Methods, devices, storage media and products for text retrieval in document image files
By merging text blocks that meet preset conditions in document image files, the problem of being unable to search across text blocks after OCR recognition is solved, achieving efficient and accurate text retrieval and improving review efficiency and accuracy.
Patent Information
- Application Number
- CN202311194903.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-09-15
- Publication Date
- 2026-01-06
- Estimated Expiration
- 2043-09-15
AI Technical Summary
In existing technologies, document image files contain continuous meaningless number strings and long company names, which makes it impossible for OCR to search across text blocks after recognition. This prevents the reviewing personnel from correctly and quickly searching for text composed of multiple text blocks.
By selecting the same segmented words as the text to be retrieved from the text block set of the document image file, an inverted index is established, and text blocks that meet the preset coverage and reading direction are merged to determine the precise text with consistent start and end words, thereby improving retrieval accuracy.
It enables text content retrieval across text blocks and lines, improving the accuracy and efficiency of retrieval of document image files and accurately locating the text to be retrieved.
Smart Images

Figure CN117235201B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of natural language processing, and in particular to methods, apparatus, storage media, and products for text retrieval in document image files. Background Technology
[0002] In international trade letters of credit, the letter of credit specifies requirements regarding the preparation time, issuer, and printed content of various related documents. Therefore, if the submitted documents (scanned copies) and their content do not meet the requirements of the letter of credit, the seller may face both financial and cargo losses.
[0003] When processing such transactions, the document center's reviewers strictly adhere to the letter of credit's requirements for documents, verifying the existence of the information presented in the letter of credit and corresponding documents, and rigorously comparing the consistency of values for the same elements across various documents. However, during these existence and consistency checks, uncommon types of number strings, company names and addresses, and printed certification statements often appear. These typically require the reviewers to meticulously compare each character, which is extremely time-consuming and accounts for a significant portion of the document review time.
[0004] In existing technologies, the processing efficiency of document image files by reviewers can be greatly improved by using Optical Character Recognition (OCR) technology and some retrieval or recognition technologies. This includes enabling reviewers to quickly retrieve specific text in document image files for comparison and review.
[0005] However, document image files often contain continuous meaningless strings of numbers, long company names, etc., which usually occupy multiple lines. When OCR recognizes this type of text, it usually recognizes it as multiple text blocks. After retrieving the text recognized by OCR, it is impossible to search across text blocks, which makes it impossible for the reviewing officer to correctly and quickly retrieve the text composed of multiple text blocks.
[0006] Therefore, improving the accuracy and efficiency of text retrieval in document images by the reviewing personnel has become an urgent technical problem to be solved. Summary of the Invention
[0007] This invention provides a method, apparatus, storage medium, and product for text retrieval in document image files, in order to solve the technical problem in the prior art that the reviewing officer cannot correctly and quickly retrieve text composed of multiple text blocks.
[0008] Firstly, to solve the above-mentioned technical problems, the technical solution of a method for text retrieval in a single document image file provided by the embodiments of the present invention is as follows:
[0009] From the set of text blocks corresponding to the document image file, select the segmentation words that are the same as the search segmentation words in the text to be searched to obtain a candidate text block set; wherein, the search segmentation words are obtained by segmenting the text to be searched according to the preset segmentation rules, the segmentation words are obtained by segmenting each text block corresponding to the document image file according to the preset segmentation rules, and the segmentation words are associated with the index number of the text block from which the segmentation words originate;
[0010] At least one group of text blocks is selected from the candidate text block set, and the overall coverage of the searched words in the text to be searched is greater than the preset coverage, and the text blocks are arranged in ascending order in the reading direction of the text to be searched. These groups of text blocks are then merged to obtain at least one merged text block. The index numbers contained in different groups of text blocks are not exactly the same.
[0011] From the at least one merged text block, determine the precise text that matches the start and end words of the text to be retrieved, and obtain a precise text set;
[0012] The search results are the precise texts in the precise text set whose character similarity to the text to be searched is greater than a preset value.
[0013] One possible implementation, before selecting the segmentation word that is the same as the search segmentation word in the text to be searched from the set of text blocks corresponding to the document image file, further includes:
[0014] For a set of document image files corresponding to a letter of credit transaction, optical character recognition is performed on each document image to obtain a set of original text blocks for each document image file; wherein, each original text block in the set of original text blocks has a unique index number;
[0015] Replace the lowercase Western letters in each original text block in the original text block set with uppercase Western letters, and replace the interference characters in the original text block with spaces to obtain the corresponding text block; wherein, the index number of the text block is the index number of the corresponding original text block;
[0016] Each text block corresponding to the original text block set is segmented according to the preset word segmentation rules to obtain multiple segmented words corresponding to the original text block set;
[0017] Based on the index number of each text block from which each segment word originates, an inverted index is established for the corresponding segment word; wherein, the segment word is associated with the text block from which it originates through the index number in the inverted index;
[0018] All the segmented words corresponding to the original text block set are used to construct the text block set of the document image file.
[0019] One possible implementation involves performing optical character recognition on each document image file within a set of document image files corresponding to a letter of credit transaction, to obtain a set of original text blocks for each document image file, including:
[0020] Optical character recognition is performed on each document image file to obtain multiple initial text blocks;
[0021] The multiple initial text blocks are corrected so that two adjacent initial text blocks with actual line spacing less than normal line spacing are aligned in the same row, resulting in multiple original text blocks.
[0022] According to the reading order of the document image file, the corrected original text blocks are numbered sequentially to obtain the index number of each original text block;
[0023] The original text blocks with index numbers corresponding to the document image files are constructed into the original text block set.
[0024] One possible implementation involves segmenting each text block corresponding to the original text block set according to the preset word segmentation rules to obtain multiple segmented words corresponding to the original text block set, including:
[0025] Based on the spaces in each text block, the non-Chinese characters in each text block are segmented to obtain the non-Chinese words contained in each text block;
[0026] The Chinese characters in each text block are segmented into individual characters to obtain the Chinese word segments contained in each text block;
[0027] All non-Chinese word segments and all Chinese word segments are deduplicated to obtain multiple segmented words corresponding to the original text block.
[0028] One possible implementation involves selecting segmentation words from the set of text blocks corresponding to the document image file that are identical to the search segmentation words in the text to be searched, thus obtaining a candidate text block set, including:
[0029] Set the search words in the text to be searched that are consistent with the preset high-frequency words as stop words; and remove duplicate search words corresponding to the text to be searched.
[0030] Each non-stop word after deduplication is used as a valid search word segment;
[0031] Each valid search word segment is compared one by one with the segmented words in the text block set;
[0032] All successfully matched segmented words are used to construct the candidate text block set.
[0033] One possible implementation involves selecting at least one group of text blocks from the candidate text block set that have an overall word segmentation coverage greater than a preset coverage in the text to be retrieved and are arranged in ascending order in the reading direction of the text to be retrieved, and merging them to obtain at least one merged text block, including:
[0034] The index number associated with each segmentation word in the candidate text block set is associated with the search segmentation word in the text to be searched that matches the corresponding segmentation word to obtain the initial text sequence to be searched;
[0035] In the reading direction of the text to be retrieved, the index numbers that meet the preset conditions located in the tail region of the initial text sequence to be retrieved are removed to obtain the text sequence to be retrieved; wherein, the preset condition is that the index number is less than the index number associated with the previous retrieval word segmentation;
[0036] In the reading direction of the text to be retrieved, obtain all combinations of index numbers arranged in descending order from the sequence of text to be retrieved;
[0037] The overall coverage of the text to be retrieved by the corresponding combination is determined based on the total number of search terms contained in each combination.
[0038] Select the text blocks corresponding to the combinations whose overall coverage is greater than the preset coverage, and merge them in ascending order of the index numbers in the corresponding combinations to obtain the merged text blocks of the corresponding combinations.
[0039] One possible implementation involves determining precise text from the at least one merged text block that matches the start and end words of the text to be retrieved, resulting in a precise text set, including:
[0040] From the at least one merged text block, select merged text blocks with consecutive text block positions as consecutive text blocks to obtain at least one consecutive text block;
[0041] From the at least one continuous text block, select continuous text blocks whose total length is less than a preset length as intermediate text blocks; wherein, the preset length is a preset multiple of the length of the text to be retrieved, and the preset multiple is greater than 1;
[0042] The precise text set is obtained by identifying the exact text from the intermediate text block that matches the start and end words of the text to be retrieved.
[0043] One possible implementation involves selecting merged text blocks with consecutive text block positions from the at least one merged text block to obtain at least one consecutive text block, including:
[0044] If two adjacent text blocks in the merged text block are in the same row, determine whether the spacing between the two adjacent text blocks is less than or equal to the width of a Western letter. If so, determine that the two adjacent text blocks are consecutive adjacent text blocks.
[0045] If two adjacent text blocks are not aligned, determine whether the line spacing between the two adjacent text blocks is less than the height of a Western letter, and whether the overlap of the two adjacent text blocks in the column direction is greater than a preset percentage. If both are true, determine that the two adjacent text blocks are consecutive adjacent text blocks.
[0046] When all adjacent text blocks in the merged text block are consecutive adjacent text blocks, the merged text block is determined to be a consecutive text block.
[0047] One possible implementation involves determining precise text from the intermediate text block that matches the start and end words of the text to be retrieved, thus obtaining a precise text set, including:
[0048] Select the first and last word segments from the text to be retrieved;
[0049] The first word segment and the last word segment are compared with the word segment corresponding to the middle text block. The two word segments in the middle text block that are successfully compared with the first word segment and the last word segment, as well as the part between the two word segments, are determined as the corresponding precise text.
[0050] The precise text set is composed of the precise text corresponding to all intermediate texts.
[0051] One possible implementation involves using precise texts from the precise text set whose character similarity to the text to be retrieved is greater than a preset value as search results, including:
[0052] Count the total number of identical word segments in each exact text and the text to be retrieved;
[0053] The ratio of the total number to the total number of search terms contained in the text to be searched is determined as the character similarity of the corresponding precise text;
[0054] The exact text with a character similarity greater than the preset value is used as the search result of the text to be searched in the document image file.
[0055] Secondly, embodiments of the present invention provide a device for text retrieval in document image files, comprising:
[0056] The selection unit is used to select the segmentation words that are the same as the search segmentation words in the text to be searched from the set of text blocks corresponding to the document image file, so as to obtain a candidate text block set; wherein, the search segmentation words are obtained by segmenting the text to be searched according to the preset segmentation rules, the segmentation words are obtained by segmenting each text block corresponding to the document image file according to the preset segmentation rules, and the segmentation words are associated with the index number of the text block from which the segmentation words originate;
[0057] The merging unit is used to select at least one group of text blocks from the candidate text block set that have an overall coverage of the searched words in the text to be retrieved that is greater than a preset coverage and are arranged in ascending order in the reading direction of the text to be retrieved, and merge them to obtain at least one merged text block; wherein, the index numbers contained in different groups of text blocks are not completely the same;
[0058] The processing unit is configured to determine, from the at least one merged text block, the precise text that matches the start and end words of the text to be retrieved, and obtain a precise text set; and to take the precise text in the precise text set whose character similarity to the text to be retrieved is greater than a preset value as the retrieval result.
[0059] In one possible implementation, the apparatus further includes a building unit, the building unit being further configured to:
[0060] Before selecting the segmentation word that is the same as the search segmentation word in the text to be searched from the set of text blocks corresponding to the document image file, optical character recognition is performed on each document image in a set of document image files corresponding to the letter of credit business to obtain the original text block set of each document image file; wherein, each original text block in the original text block set has a unique index number;
[0061] Replace the lowercase Western letters in each original text block in the original text block set with uppercase Western letters, and replace the interference characters in the original text block with spaces to obtain the corresponding text block; wherein, the index number of the text block is the index number of the corresponding original text block;
[0062] Each text block corresponding to the original text block set is segmented according to the preset word segmentation rules to obtain multiple segmented words corresponding to the original text block set;
[0063] Based on the index number of each text block from which each segment word originates, an inverted index is established for the corresponding segment word; wherein, the segment word is associated with the text block from which it originates through the index number in the inverted index;
[0064] All the segmented words corresponding to the original text block set are used to construct the text block set of the document image file.
[0065] In one possible implementation, the building unit is further configured to:
[0066] Optical character recognition is performed on each document image file to obtain multiple initial text blocks;
[0067] The multiple initial text blocks are corrected so that two adjacent initial text blocks with actual line spacing less than normal line spacing are aligned in the same row, resulting in multiple original text blocks.
[0068] According to the reading order of the document image file, the corrected original text blocks are numbered sequentially to obtain the index number of each original text block;
[0069] The original text blocks with index numbers corresponding to the document image files are constructed into the original text block set.
[0070] In one possible implementation, the building unit is further configured to:
[0071] Based on the spaces in each text block, the non-Chinese characters in each text block are segmented to obtain the non-Chinese words contained in each text block;
[0072] The Chinese characters in each text block are segmented into individual characters to obtain the Chinese word segments contained in each text block;
[0073] All non-Chinese word segments and all Chinese word segments are deduplicated to obtain multiple segmented words corresponding to the original text block.
[0074] In one possible implementation, the selection unit is further configured to:
[0075] Set the search words in the text to be searched that are consistent with the preset high-frequency words as stop words; and remove duplicate search words corresponding to the text to be searched.
[0076] Each non-stop word after deduplication is used as a valid search word segment;
[0077] Each valid search word segment is compared one by one with the segmented words in the text block set;
[0078] All successfully matched segmented words are used to construct the candidate text block set.
[0079] In one possible implementation, the merging unit is further configured to:
[0080] The index number associated with each segmentation word in the candidate text block set is associated with the search segmentation word in the text to be searched that matches the corresponding segmentation word to obtain the initial text sequence to be searched;
[0081] In the reading direction of the text to be retrieved, the index numbers that meet the preset conditions located in the tail region of the initial text sequence to be retrieved are removed to obtain the text sequence to be retrieved; wherein, the preset condition is that the index number is less than the index number associated with the previous retrieval word segmentation;
[0082] In the reading direction of the text to be retrieved, obtain all combinations of index numbers arranged in descending order from the sequence of text to be retrieved;
[0083] The overall coverage of the text to be retrieved by the corresponding combination is determined based on the total number of search terms contained in each combination.
[0084] Select the text blocks corresponding to the combinations whose overall coverage is greater than the preset coverage, and merge them in ascending order of the index numbers in the corresponding combinations to obtain the merged text blocks of the corresponding combinations.
[0085] In one possible implementation, the processing unit is further configured to:
[0086] From the at least one merged text block, select merged text blocks with consecutive text block positions as consecutive text blocks to obtain at least one consecutive text block;
[0087] From the at least one continuous text block, select continuous text blocks whose total length is less than a preset length as intermediate text blocks; wherein, the preset length is a preset multiple of the length of the text to be retrieved, and the preset multiple is greater than 1;
[0088] The precise text set is obtained by identifying the exact text from the intermediate text block that matches the start and end words of the text to be retrieved.
[0089] In one possible implementation, the processing unit is further configured to:
[0090] If two adjacent text blocks in the merged text block are in the same row, determine whether the spacing between the two adjacent text blocks is less than or equal to the width of a Western letter. If so, determine that the two adjacent text blocks are consecutive adjacent text blocks.
[0091] If two adjacent text blocks are not aligned, determine whether the line spacing between the two adjacent text blocks is less than the height of a Western letter, and whether the overlap of the two adjacent text blocks in the column direction is greater than a preset percentage. If both are true, determine that the two adjacent text blocks are consecutive adjacent text blocks.
[0092] When all adjacent text blocks in the merged text block are consecutive adjacent text blocks, the merged text block is determined to be a consecutive text block.
[0093] In one possible implementation, the processing unit is further configured to:
[0094] Select the first and last word segments from the text to be retrieved;
[0095] The first word segment and the last word segment are compared with the word segment corresponding to the middle text block. The two word segments in the middle text block that are successfully compared with the first word segment and the last word segment, as well as the part between the two word segments, are determined as the corresponding precise text.
[0096] The precise text set is composed of the precise text corresponding to all intermediate texts.
[0097] In one possible implementation, the processing unit is further configured to:
[0098] Count the total number of identical word segments in each exact text and the text to be retrieved;
[0099] The ratio of the total number to the total number of search terms contained in the text to be searched is determined as the character similarity of the corresponding precise text;
[0100] The exact text with a character similarity greater than the preset value is used as the search result of the text to be searched in the document image file.
[0101] Thirdly, embodiments of the present invention also provide a device for text retrieval in document image files, comprising:
[0102] At least one processor, and
[0103] Memory connected to the at least one processor;
[0104] The memory stores instructions that can be executed by the at least one processor, which executes the instructions stored in the memory to perform the method described in the first aspect above.
[0105] Fourthly, embodiments of the present invention also provide a readable storage medium, comprising:
[0106] memory,
[0107] The memory is used to store instructions that, when executed by a processor, cause the apparatus including the readable storage medium to perform the method described in the first aspect above.
[0108] Fifthly, embodiments of the present invention also provide a computer program product, including program code, wherein when a computer runs the computer program, the program code executes the method described in the first aspect.
[0109] Through the technical solutions in one or more of the above embodiments of the present invention, the embodiments of the present invention have at least the following technical effects:
[0110] In the embodiments provided by this invention, by selecting the same segmentation words as the search words in the text to be retrieved from the text block set corresponding to the document image file, a candidate text block set is obtained; then, at least one group of text blocks with an overall coverage of the search words in the text to be retrieved that is greater than a preset coverage and are arranged in ascending order in the reading direction of the text to be retrieved are selected from the candidate text block set and merged to obtain at least one merged text block; this not only reduces the retrieval volume of the text to be retrieved in the text blocks corresponding to the document image file, but also enables cross-text block and cross-line retrieval of the text content after OCR recognition of the document image file; and by determining the precise text with the same start and end words as the text to be retrieved from at least one merged text block, a precise text set is obtained; and then, the precise text with a character similarity greater than a preset value to the text to be retrieved in the precise text set is used as the retrieval result, which can improve the retrieval accuracy, accuracy and retrieval efficiency of the text to be retrieved, and accurately locate the position of the text to be retrieved in the unit image file. Attached Figure Description
[0111] Figure 1 A flowchart of a text retrieval method for document image files is provided in an embodiment of the present invention;
[0112] Figure 2 This is a schematic diagram illustrating the position of text blocks obtained after OCR recognition of a document image file, provided by an embodiment of the present invention.
[0113] Figure 3 A method provided by an embodiment of the present invention Figure 2 A diagram of the corresponding text block;
[0114] Figure 4 This is a flowchart illustrating the formation of the original text block set in an embodiment of the present invention;
[0115] Figure 5 A schematic diagram of a merged text block of text to be retrieved, provided as an embodiment of the present invention;
[0116] Figure 6 This is a schematic diagram illustrating how to obtain precise text according to an embodiment of the present invention;
[0117] Figure 7 This is a schematic diagram of the apparatus for a text retrieval method in a document image file provided in an embodiment of the present invention. Detailed Implementation
[0118] This invention provides a method, apparatus, storage medium, and product for text retrieval in document image files, addressing the technical problem in the prior art where reviewers cannot correctly and quickly retrieve text composed of multiple text blocks. The acquisition, storage, use, and processing of data in this application all comply with relevant national laws and regulations.
[0119] To better understand the above technical solutions, the technical solutions of the present invention will be described in detail below with reference to the accompanying drawings and specific embodiments. It should be understood that the embodiments of the present invention and the specific features in the embodiments are detailed descriptions of the technical solutions of the present invention, rather than limitations on the technical solutions of the present invention. In the absence of conflict, the embodiments of the present invention and the technical features in the embodiments can be combined with each other.
[0120] Please refer to Figure 1 This invention provides a method for text retrieval in document image files, and the processing procedure of this method is as follows.
[0121] Step 101: Select the segmentation words that are the same as the search segmentation words in the text to be searched from the set of text blocks corresponding to the document image file, and obtain the candidate text block set; wherein, the search segmentation words are obtained by segmenting the text to be searched according to the preset segmentation rules, the segmentation words are obtained by segmenting each text block corresponding to the document image file according to the preset segmentation rules, and the segmentation words are associated with the index number of the text block from which the segmentation words originate;
[0122] A set of document image files corresponding to a letter of credit transaction includes image files of the letter of credit, drafts, invoices, packing lists, Generalized System of Preferences (GSP) certificates of origin, a complete set of insurance policies, and transport documents. In this invention, the document image file can be any image file from the set of document image files corresponding to a letter of credit transaction.
[0123] The aforementioned set of alternative text blocks can be provided by entities other than the execution entity of this scheme, or it can be provided by the execution entity of this scheme. For example, the execution entity of this scheme can be processor 1, and other execution entities can be processor 2; or, for example, the execution entity of this scheme can be model 1, and other execution entities can be model 2, etc.
[0124] When the candidate text block set is provided by the entity executing this solution, before selecting the segmentation word that is the same as the search segmentation word in the text to be searched from the text block set corresponding to the document image file, the entity executing this solution can obtain the text block set in the following way:
[0125] For a set of document image files corresponding to a letter of credit transaction, optical character recognition (OCR) is performed on each document image to obtain a set of original text blocks for each document image file; each original text block in the set of original text blocks has a unique index number;
[0126] Document image files can be obtained by scanning paper documents (such as letters of credit, drafts, invoices, etc.) using a scanning device. Because the paper documents may not be properly positioned when placed in the scanning device, the text in the resulting scan may not be parallel or perpendicular to the edges of the document, reducing the accuracy of OCR recognition. To improve OCR accuracy, the scanned document can be corrected before OCR recognition to obtain the corresponding document image file.
[0127] Please see Figure 2 This is a schematic diagram illustrating the position of text blocks obtained after OCR recognition of a document image file, as provided in an embodiment of the present invention. Figure 2 Each box represents a block of original text, and the number in the upper right corner of the box is the index number of the corresponding original text block.
[0128] It is necessary to understand that Figure 2 This is a Chinese translation of a portion of the invoice corresponding to a foreign letter of credit, and does not represent the actual invoice.
[0129] Replace lowercase Western letters in each original text block in the original text block set with uppercase Western letters, and replace interfering characters in the original text blocks with spaces to obtain the corresponding text blocks; where the index number of the text block is the index number of the corresponding original text block; Western letters include English letters, German letters, French letters, etc., without specific restrictions. For example, replacing with spaces Figure 2 The diagram after the scrambler is as follows: Figure 3 As shown, Figure 3 A method provided by an embodiment of the present invention Figure 2 A diagram of the corresponding text block.
[0130] Letters of credit include domestic and foreign letters of credit. Domestic letters of credit are usually mostly in Chinese with a small number of English characters on a single page, while foreign letters of credit are mostly in English. To facilitate retrieval, lowercase Western letters in the original text block can be replaced with uppercase Western letters. In addition, interference characters in the original text block, such as punctuation marks and connectors, can be replaced with spaces to avoid OCR misidentifying interference characters and interfering with the retrieval.
[0131] It is important to understand that if the OCR recognition accuracy is relatively high, interference characters can be retained, and in this case, the original text block is the text block.
[0132] Each text block in the original text block set is segmented according to a preset word segmentation rule, resulting in multiple segmented words corresponding to the original text block set; among them, the segmented words are associated with the original text blocks through their index numbers in the inverted index; for example, according to the preset word segmentation rule... Figure 3 Segmenting the text block with index number 36 yields the following segmentation terms: documentary credit number, BBCDAK123456, date, and 2010128. Similarly, other segmentation terms can be obtained.
[0133] Based on the index number of each text block from which each segmented word originates, an inverted index is built for the corresponding segmented word; for example... Figure 3 The segmentation word "date" in the text is obtained from index numbers 32, 34, and 36 (i.e., "date" originates from index numbers 32, 34, and 36 of the original text block). Therefore, the inverted index of "date" is (32, 34, 36). Similarly, the inverted indices of other segmentation words can be obtained.
[0134] All the segmented words corresponding to the original text block set are used to construct a text block set for the certificate image file.
[0135] like Figure 3 The segmentation words “date”, “2021”, “year”, “6”, “month”, “21”, and “day” in the text block set of the document image file are represented as {date(32,34,36), 2021(32,34), year(32,34), 6(32,34), month(32,34), 21(32,34), day(32,34)}.
[0136] The search terms for the text to be searched, “June 21, 2021”, are “2021”, “year”, “6”, “month”, “21”, and “day”. Each of these search terms is compared with the segmented terms in the text block set. The segmented terms that are successfully matched are used to construct a set of candidate text blocks in the document image file for the text block to be searched: {2021(32,34), year(32,34), 6(32,34), month(32,34), 21(32,34), day(32,34)}.
[0137] In some embodiments, slight vibrations of the scanning device or paper documents during scanning may cause positional deviations in the column direction of the actual text in the same row of the image file. Therefore, to address this issue, the present invention provides another solution for forming the original text block set, as follows: For a set of document image files corresponding to a letter of credit transaction, optical character recognition is performed on each document image to obtain the original text block set for each document image file. This can be achieved in the following way:
[0138] Optical character recognition is performed on each document image file to obtain multiple initial text blocks;
[0139] Multiple initial text blocks are corrected so that two adjacent initial text blocks with actual line spacing less than normal line spacing are aligned in the same row, resulting in multiple original text blocks.
[0140] Following the reading order of the document image files, the corrected original text blocks are numbered sequentially to obtain the index number of each original text block;
[0141] Construct a set of original text blocks with index numbers corresponding to the document image files.
[0142] Please see Figure 4 This is a flowchart illustrating the formation of an original text block set according to an embodiment of the present invention. Assume... Figure 2 The last two files with index number 39 in the index are offset from the original line by their "numbers". Figure 4 Only shown in Figure 2 This corresponds to a small portion of the information in the invoice.
[0143] S10: OCR recognition.
[0144] right Figure 4 The document image file shown is subjected to OCR recognition to obtain multiple corresponding initial text blocks.
[0145] S11: Correct the initial text block.
[0146] Calculate the column spacing between two adjacent initial text blocks. If the spacing is less than the normal line spacing between two adjacent lines, adjust the two adjacent initial text blocks to the same line. Specifically, as follows: Figure 4 The initial text block “BBB Bank DCNO.0000123456789, Letter of Credit Authorization Number.345678. Customs Goods” and “Number” have a smaller actual line spacing than normal. It can be determined that the initial text block “Number” has been offset. Adjust them to be on the same line.
[0147] Of course, it may also be necessary to check the spacing between the initial text block that shifted and its left and right adjacent text blocks, and whether it overlaps with the adjacent text block in the column direction. If there is overlap, it cannot be adjusted to the same line. Figure 2In the text block with index number 31, the character "21" is offset upwards. Since the actual line spacing of "21" and the initial text blocks corresponding to index numbers 29 and 31 is less than the normal line spacing, it is necessary to further determine whether "21" overlaps with the initial text blocks corresponding to index numbers 29 and 31 in the column direction. It is determined that the initial text block "21" overlaps with the initial text block corresponding to index number 29, so they cannot be adjusted to the same line. However, the initial text "21" does not overlap with the initial text block corresponding to index number 31, so they can be adjusted to the same line. At this point, they can be directly treated as two original text blocks. Alternatively, it can be further determined whether the spacing between the initial text "21" and the initial text block corresponding to index number 31 in the line direction is less than or equal to one normal character spacing. If so, these two initial text blocks can be merged into one original text block.
[0148] For initial text blocks that do not require adjustment, use them directly as the original text blocks.
[0149] S12: Numbered original text block.
[0150] The original text blocks corresponding to the document image files are numbered according to the reading order of the document image files to obtain the index number of each original text block, forming a set of original text blocks.
[0151] In the embodiments provided by the present invention, after performing OCR recognition on the document image file, the resulting multiple initial text blocks are corrected so that two adjacent initial text blocks with actual line spacing smaller than normal line spacing are aligned in the same row, which can improve the accuracy of text retrieval.
[0152] In some embodiments, each text block corresponding to the original text block set is segmented according to a preset word segmentation rule to obtain multiple segmented words corresponding to the original text block set. This can be achieved in the following ways:
[0153] Based on the spaces in each text block, the non-Chinese characters in each text block are segmented to obtain the non-Chinese words contained in each text block; non-Chinese characters include Western characters, numbers, etc.
[0154] Each Chinese character in a text block is segmented into individual characters to obtain the Chinese word segments contained in each text block;
[0155] Deduplication is performed on all non-Chinese word segments and all Chinese word segments to obtain multiple segmented words corresponding to the original text block.
[0156] For example, for the text block "Documentary Credit Number BBCDAK123456 Date 2010128", according to the preset word segmentation rule that non-Chinese characters are split by spaces, the non-Chinese word segments that can be segmented from this text block are: BBCDAK123456, 2010128; according to the preset word segmentation rule that Chinese characters are split by character, the Chinese word segments that can be segmented from the above text block are: follow, single, letter, use, certificate, number, date. The index numbers of the text blocks corresponding to these segmented words are all 36. Among them, the segmented words include Chinese word segments and non-Chinese word segments.
[0157] Another example is the text block "Number 1234 12 00 Postal Code 4400012345 By Export Contract". After segmenting this text block according to the above preset word segmentation rule, the segmented words obtained are: number, 1234, 12, 00, postal, code, 4400012345, by, export, contract, and the corresponding index numbers are all 36. Since the segmented word "number" appears twice in this text block, only one segmented word "number" needs to be retained in the obtained segmented words.
[0158] According to the above preset word segmentation rule, other text blocks in the document image file can be segmented to obtain the remaining segmented words. According to the index numbers corresponding to the same segmented word, the inverted index of the segmented word can be obtained. For example Figure 3 The index numbers of the text blocks from which the Chinese segmented word "number" is derived include 05, 13, 17, 28, 35, 36, 39, 40. Therefore, the inverted index (05, 13, 17, 28, 35, 36, 39, 40) of the segmented word "number" can be formed. After obtaining the inverted indexes of all segmented words in the document image file, they can be constructed into a set of text blocks of the document image file.
[0159] Furthermore, according to each retrieval word segment of the retrieval text to be retrieved currently, the segmented words that match the retrieval word segments in the retrieval text are selected from the set of text blocks of the document image file to form a set of alternative text blocks corresponding to the retrieval text. Among them, the retrieval text is also segmented using the preset word segmentation rule.
[0160] In some embodiments, selecting the segmented words that are the same as the retrieval word segments in the retrieval text from the set of text blocks corresponding to the document image file to obtain the set of alternative text blocks can also be achieved through the following methods:
[0161] Set the retrieval word segments in the retrieval text that are the same as the preset high-frequency words as stop words; and remove duplicates from the retrieval word segments corresponding to the retrieval text; use each non-stop word after duplicate removal as an effective retrieval word segment; compare each effective retrieval word segment with the segmented words in the set of text blocks one by one; construct all the segmented words that match successfully into a set of alternative text blocks.
[0162] In the image files of documents corresponding to letter of credit transactions, there are usually some frequently used words, which can be called high-frequency words, such as "NO". High-frequency words appearing in the text to be searched can be stopped, that is, high-frequency words are not included in the comparison. High-frequency words can be pre-set by the reviewing officer based on experience, or they can be screened after statistical analysis of the segmented words of image files corresponding to historical document transactions. There are no specific restrictions.
[0163] For example, if the text to be searched is “DC NO.0000285921060226,LCA NO.374953,HS CODENO.5208.52.00,PO NO 4400054348”, the corresponding search terms are DC, NO, 0000285921060226, LCA, NO, 374953, H, S, CODE, NO, 5208, 52, 00, P, O, NO, 4400054348, a total of 16 search terms.
[0164] NO is a preset high-frequency word. NO is set as a stop word. The 16 search terms are deduplicated, resulting in the following valid search terms: DC, 0000285921060226, LCA, 374953, H, S, CODE, 5208, 52, 00, P, O, 4400054348. These valid search terms are compared one by one with the segmentation words in the candidate text block set. Assuming that when performing OCR recognition on a document image file, all "O"s in the file are recognized as "0", the successfully matched segmentation words are: DC, 0000285921060226, LCA, 374953, H, S, 5208, 52, 00, P, 4400054348. These successfully matched segmentation words are used to construct the candidate text block set for the text to be retrieved.
[0165] In the embodiments provided by this invention, by setting preset high-frequency words for the text to be retrieved, stopping the search segments in the text block that are the same as the preset high-frequency words, and deduplicating the search segments in the search text, each non-stop word after deduplication is taken as a valid search segment. The valid search segments are compared one by one with the segmented words in the text block set, which can effectively reduce the number of search segment comparisons, thereby improving comparison efficiency and quickly obtaining a set of candidate text blocks. Furthermore, since the above process is based on the search segments in the text to be retrieved, searching for segmented words that are the same as the search segments from the text block combination corresponding to the document image file, rather than starting from multiple segmented words or the entire text block, the fuzziness of the final search results for the text to be retrieved is greater, the recall effect of the search results is better, and the omission of search results is avoided.
[0166] After selecting the same segmented words as the search segmented words in the text to be searched from the text block set, and obtaining the candidate text block set, step 102 can be executed.
[0167] Step 102: Select at least one group of text blocks from the candidate text block set whose overall coverage of the searched words in the text to be searched is greater than the preset coverage and whose text blocks are arranged in ascending order in the reading direction of the text to be searched, and merge them to obtain at least one merged text block; wherein, the index numbers contained in different groups of text blocks are not completely the same;
[0168] From the candidate text block set, at least one group of text blocks that have an overall coverage of the searched words in the text to be searched that is greater than a preset coverage and are arranged in ascending order in the reading direction of the text to be searched are selected and merged to obtain at least one merged text block. This can be achieved in the following way:
[0169] The index number associated with each segmentation word in the candidate text block set is associated with the search segmentation word in the text to be searched, resulting in an initial text sequence to be searched. In the reading direction of the text to be searched, index numbers that meet preset conditions located at the end of the initial text sequence to be searched are removed, resulting in another text sequence to be searched. The preset condition is that the index number is less than the index number associated with the previous search segmentation word. In the reading direction of the text to be searched, all combinations of index numbers arranged in descending order are obtained from the text sequence to be searched. Based on the total number of search segmentation words contained in each combination, the overall coverage of the corresponding combination in the text to be searched is determined. Text blocks corresponding to combinations with an overall coverage greater than the preset coverage are selected and merged according to the ascending order of the index numbers in the corresponding combination, resulting in merged text blocks for the corresponding combination.
[0170] Please see Figure 5 This is a schematic diagram of a merged text block of text to be retrieved, provided as an embodiment of the present invention.
[0171] Suppose the text to be retrieved is “DC NO.0000285921060226,LCA NO.374953,HS CODENO.5208.52.00,PO NO 4400054348”. During OCR recognition, the “O” in the document image file is recognized as “0”. Therefore, the set of candidate text blocks corresponding to the text to be retrieved is {DC(42), 0000285921060226(42), LCA(42), 374953(42), H(42), S(42, 36, 49), 5208(43), 52(43, 50), 00(43), P(14, 43), 4400054348(43)}. To facilitate program processing, each search term in the text to be searched can be numbered. For example, the search terms can be numbered sequentially from the first search term to the last search term. If the first search term is numbered 0, the above set of candidate text blocks can also be recorded as {0(42), 2(42), 3(42), 5(42), 6(42), 7(42, 36, 49), 10(43), 11(43, 50), 12(43), 13(14, 43), 16(43)}.
[0172] S20. Form the text sequence to be retrieved;
[0173] If the segment "DC" in the candidate text block set is the same as the first search segment "DC" in the text to be retrieved, the index number "42" associated with the segment "DC" will be associated with the first search segment "DC"; if the segment "S" is the same as the seventh search segment "S", the index numbers "42", "36", and "49" associated with the segment "DC" will be associated with the seventh search segment "S"; if the search segment "NO" does not match any segment in the candidate text block set, the index number associated with the search segment "NO" will be set to a specific identifier (such as "None"). Similar processing can be applied to other search segments, which will not be elaborated here. Through the above processing, the sequence of text to be retrieved (such as...) can be obtained. Figure 5 (As shown in the Chinese frame), for easier viewing... Figure 5 The left side of the retrieved text sequence shows the search term corresponding to the number of each search term.
[0174] S21. Select the combination with index numbers arranged in descending order;
[0175] In the reading direction of the text to be retrieved, the combinations arranged in descending order from the text sequence are: combination 1 = [42,43], combination 2 = [42,50], combination 3 = [42,49], combination 4 = [42,43,50], combination 5 = [42,49,50], combination 6 = [36,43], combination 7 = [36,43,50], combination 8 = [49,50].
[0176] S22. Count the total number of search terms included in each combination and calculate the corresponding overall coverage;
[0177] S23. Select a combination whose overall coverage is greater than the preset coverage (8, 50%).
[0178] The total number of search terms included in each combination is as follows: Combination 1 contains 17 search terms, Combination 2 contains 12 search terms, Combination 3 contains 8 search terms, Combination 4 contains 12 search terms, Combination 5 contains 12 search terms, Combination 6 contains 10 search terms, Combination 7 contains 5 search terms, and Combination 8 contains 5 search terms.
[0179] If overall coverage is represented by the total number of search terms included in the combination, then the preset coverage can be set according to a certain proportion of the total number of search terms contained in the text to be searched. For example, the preset coverage is half of the total number of search terms contained in the text to be searched. Figure 5 The total number of search terms contained in the text to be searched is 17, half of which is 8.5, which is rounded down to 8. Therefore, the preset coverage can be set to 8.
[0180] If overall coverage is represented by the proportion of search terms included in the combination within the text to be searched, then the percentage corresponding to the ratio of the total number of search terms included in each combination to the total number of search terms included in the text to be searched is taken as the overall coverage of the corresponding combination. Based on this, the overall coverage of combination 1 is determined to be 100%, combination 2 to be 70.6%, combination 3 to be 47.1%, combination 4 to be 70.6%, combination 5 to be 70.6%, combination 6 to be 58.8%, combination 7 to be 29.4%, and combination 8 to be 29.4%. The preset coverage can be set to 50%.
[0181] By selecting combinations with an overall coverage greater than the preset coverage, the following combinations can be obtained: Combination 2 = [42, 50], Combination 4 = [42, 43, 50], Combination 5 = [42, 49, 50], Combination 6 = [36, 43], Combination 8 = [49, 50].
[0182] The text blocks corresponding to the index numbers contained in each combination are merged to obtain the merged text block for each combination.
[0183] In addition, if the overall coverage of the text to be retrieved by a certain index number is greater than the preset coverage, this single text block can also be treated as a separate merged text block.
[0184] After obtaining the merged text block corresponding to each combination, step 103 can be executed.
[0185] Step 103: Determine the exact text that matches the start and end words of the text to be retrieved from at least one merged text block to obtain an exact text set;
[0186] For example, regarding the above Figure 5 Each merged text block can be searched for segments that match the start and end words of the text to be retrieved (the first search segment "DC" and the last search segment "4400054348"). The two segments that successfully match the start and end words in the reading direction of the document image file and the text between them are selected as the precise text of the corresponding merged text block.
[0187] It should be noted that: if a segmentation word that successfully matches the first segmentation word of the text to be retrieved is located at the beginning of the exact text, and if a segmentation word that successfully matches the last segmentation word of the text to be retrieved is located at the end of the exact text.
[0188] In some embodiments, determining the precise text that matches the start and end words of the text to be retrieved from at least one merged text block to obtain a precise text set can also be achieved in the following ways:
[0189] From at least one merged text block, select merged text blocks with consecutive text block positions as continuous text blocks to obtain at least one continuous text block; from at least one continuous text block, filter continuous text blocks whose total length is less than a preset length as intermediate text blocks; wherein, the preset length is a preset multiple of the length of the text to be retrieved, and the preset multiple is greater than 1; from the intermediate text blocks, determine the precise text that matches the start and end words of the text to be retrieved to obtain a precise text set.
[0190] Text block positional continuity means that it is continuous in at least one of the row or column directions.
[0191] For example, a merged text block includes text block 1 and text block 2. In the text block corresponding to the document image file, text block 1 and text block 2 are adjacent in the row direction in the document image file. It can be considered that text block 1 and text block 2 are in continuous position. The merged text block composed of text block 1 and text block 2 can be determined as a continuous text block. If text block 2 is in the next row of text block 1, it can be considered that they are in continuous position in the column direction. The merged text block composed of text block 1 and text block 2 can be determined as a continuous text block.
[0192] For example, a merged text block includes text block 1 to text block 3. In the text block corresponding to the document image file, text block 1 and text block 2 are adjacent in the line direction, and text block 3 is on the next line after text block 1. It can be considered that text block 1 to text block 3 are adjacent in position, and the merged text block consisting of text block 1 to text block 3 can be determined as a continuous text block.
[0193] The sum of the lengths of each text block contained within a continuous text block is used as the length of the corresponding continuous text block. For example, if the preset multiple is 1.3 and the length of the text to be retrieved is L, then the preset length is 1.3L. Assume the length of continuous text block 1 is 1.1L, the length of continuous text block 2 is 1.5L, the length of continuous text block 3 is 1.2L, and the length of continuous text block 5 is 1.2L. Continuous text blocks with a length less than the preset length of 1.3L include continuous text block 1, continuous text block 3 through continuous text block 5, and these are all considered intermediate text blocks. In the reading direction of the document image file, the start and end words of the text to be retrieved successfully match the segmentation words in continuous text block 1, resulting in the corresponding precise text 1. The start and end words of the text to be retrieved successfully match the segmentation words in continuous text block 3, but the segmentation word matching the last segmentation word of the text to be retrieved appears first in the reading direction, while the segmentation word matching the first segmentation word appears last. Furthermore, no other segmentation words in the continuous text block successfully match any of the start and end words, therefore no precise text is obtained from continuous text block 3. Only one segmentation word in the start and end words of the text to be retrieved successfully matches the segmentation words in continuous text block 4, therefore no precise text is obtained from continuous text block 4 either. In the reading direction of the document image file, the start and end words of the text to be retrieved successfully match the segmentation words in continuous text block 5, resulting in the corresponding precise text 5. Precise text 1 and precise text 5 are then constructed as a precise text set.
[0194] In the embodiments provided by this invention, at least one continuous text block is obtained by selecting consecutively positioned merged text blocks from at least one merged text block; from the at least one continuous text block, consecutive text blocks with a total length less than a preset length are selected as intermediate text blocks; wherein, the preset length is a preset multiple of the length of the text to be retrieved, and the preset multiple is greater than 1; precise texts with the same start and end words as the text to be retrieved are determined from the intermediate text blocks, resulting in a set of precise texts. Since the process of comparing the start and end words of the text to be retrieved with the segmented words in the merged text block is first performed based on the positional continuity of the text blocks in the merged text block and the length relationship between the merged text block and the text to be retrieved before obtaining precise texts from the merged text block, the retrieval efficiency is improved.
[0195] In some embodiments, selecting merged text blocks with consecutive text block positions from at least one merged text block to obtain at least one consecutive text block can also be achieved in the following ways:
[0196] If two adjacent text blocks in the merged text block are on the same line, determine whether the spacing between the two adjacent text blocks is less than or equal to the width of a Western letter. If yes, the two adjacent text blocks are determined to be consecutive adjacent text blocks. If two adjacent text blocks are on different lines, determine whether the line spacing between the two adjacent text blocks is less than the height of a Western letter, and whether the overlap of the two adjacent text blocks in the column direction is greater than a preset percentage. If both are yes, the two adjacent text blocks are determined to be consecutive adjacent text blocks. When all adjacent text blocks in the merged text block are consecutive adjacent text blocks, the merged text block is determined to be a consecutive text block.
[0197] In some embodiments, determining the precise text that matches the start and end words of the text to be retrieved from the intermediate text block to obtain a precise text set can also be achieved in the following ways:
[0198] Select the first and last word segments from the text to be retrieved; compare the first and last word segments with the word segments corresponding to the middle text block; determine the two word segments in the middle text block that successfully match the first and last word segments and the part between the two word segments as the corresponding precise text; and form a precise text set by combining all the precise texts corresponding to the middle text.
[0199] Please see Figure 6 This is a schematic diagram illustrating an embodiment of the present invention for obtaining precise text. The text to be retrieved is... Figure 5 Take the text to be searched in the example. Figure 6The image file only shows a portion of the document containing the text to be retrieved: “BANGLADESH BANK DC NO.0000285921060226, LCA NO.374953, HS CODENO.5208.52.00, PO NO 4400054348, AGAINST EXPORT CONTRACT”.
[0200] Because the OCR recognition of the document image file mistakenly identified "O" as "0", the recognized content was "BANGLADESH BANK DC N0.0000285921060226,LCA N0.374953,HS C0DE N0.5208.52.00,P.0N0 4400054348,AGAINST EXP0RT C0NTRACT" (which was recognized as 3 text blocks, text block 1 to text block 3, as shown in the image). Figure 6 (as shown); before obtaining the merged text block, the interfering characters in it have been replaced with spaces, so the obtained merged text block is "BANGLADESH BANK DC N0 0000285921060226LCA N0 374953H S C0DE N0 520852 00P 0N04400054348AGAINST EXP0RT C0NTRACT".
[0201] Calculate whether the spacing between two adjacent text blocks 1 and 2 in the same row is less than or equal to the width of one English letter. If the result is yes, text blocks 1 and 2 are determined to be consecutive adjacent text blocks. Since text block 3 is on a different line than text blocks 1 and 2, the line spacing between text block 3 and the line containing text block 1 needs to be calculated. If the line spacing is less than the height of one English letter, it means that text block 3 is adjacent to either text block 1 or text block 2 in the column direction, i.e., the entire line containing text block 3 and either text block 1 or text block 2 is consecutive adjacent text blocks.
[0202] In the embodiments provided by the present invention, by determining whether the spacing between two adjacent text blocks in the same row is less than or equal to the width of a Western letter, it is possible to quickly determine whether two adjacent text blocks are consecutive in the row direction; and by determining whether the line spacing between two adjacent text blocks in different rows is less than or equal to the height of a Western letter, it is possible to quickly determine whether two adjacent text blocks in the column direction are consecutive in the column direction, and thus it is possible to determine whether a merged text block composed of multiple lines of text is consecutive in the reading direction of the document image file.
[0203] Since text block 1 and text block 2 are consecutive adjacent text blocks in the line direction, and text block 3 is consecutive adjacent to the entire line containing text block 1 or text block 2, the merged text block can be determined to be a continuous text block. The length of the continuous text block containing text blocks 1 to 3 is calculated, and it is determined that the length of this continuous text block is less than 1.3 times the length of the text to be retrieved. Therefore, this continuous text block is considered an intermediate text block.
[0204] Then, from the text to be searched, “DC NO.0000285921060226,LCA NO.374953,HS CODENO.5208.52.00,PO NO 4400054348”, the first word segment “DC” and the last word segment “4400054348” are selected as the start and end words. The precise text obtained from the above intermediate text block is “DC N00000285921060226LCA N0374953HS CODE N0 5208 52 00P 0N04400054348”.
[0205] Similarly, other precise texts of the text to be retrieved can be identified. All precise texts are then grouped into a precise text set.
[0206] Once the exact text set is obtained, step 104 can be executed.
[0207] Step 104: Select the precise texts in the precise text set whose character similarity to the text to be retrieved is greater than a preset value as the search results.
[0208] For example, the similarity between each exact text and the text to be retrieved can be calculated using existing character similarity calculation methods, which will not be elaborated here. Assuming a preset value of 80%, the exact text with a character similarity greater than 80% can be used as the retrieval result for the text to be retrieved.
[0209] In some embodiments, using precise texts from the precise text set whose character similarity to the text to be retrieved is greater than a preset value as search results can also be achieved in the following ways:
[0210] The total number of identical word segments in each precise text and the text to be retrieved is counted; the ratio of the total number to the total number of search words contained in the text to be retrieved is determined as the character similarity of the corresponding precise text; precise texts with character similarity greater than a preset value are used as the search results of the text to be retrieved in the document image file.
[0211] For example, with Figure 6Taking the search text “DC NO.0000285921060226,LCA NO.374953,H.SCODE NO.5208.52.00,PO NO 4400054348” and the exact text “DC N00000285921060226LCA N0374953H S C0DE N0 5208 52 00P 0N04400054348” as an example, statistics show that the total number of segmented words in the exact text that are the same as those in the search text is 12, and the total number of segmented words in the search text is 17. Therefore, the character similarity between the exact text and the search text is 12 / 17×100%=70.58%. If the preset value is 70%, this exact text can be used as the search result for the search text.
[0212] In some retrieval scenarios, a single document may contain multiple search results, each with different line break patterns, potentially leading to interference from redundant text. The solution provided by this invention can accurately retrieve the start and end points of these multi-line texts while allowing for a certain degree of character ambiguity, thus achieving fuzzy retrieval.
[0213] In the embodiments provided by this invention, by selecting the same segmentation words as the search words in the text to be retrieved from the text block set corresponding to the document image file, a candidate text block set is obtained; then, at least one group of text blocks with an overall coverage of the search words in the text to be retrieved that is greater than a preset coverage and are arranged in ascending order in the reading direction of the text to be retrieved are selected from the candidate text block set and merged to obtain at least one merged text block; this not only reduces the retrieval volume of the text to be retrieved in the text blocks corresponding to the document image file, but also enables cross-text block and cross-line retrieval of the text content after OCR recognition of the document image file; and by determining the precise text with the same start and end words as the text to be retrieved from at least one merged text block, a precise text set is obtained; and then, the precise text with a character similarity greater than a preset value to the text to be retrieved in the precise text set is used as the retrieval result, which can improve the retrieval accuracy, accuracy and retrieval efficiency of the text to be retrieved, and accurately locate the position of the text to be retrieved in the unit image file.
[0214] Furthermore, since the above solution does not require the use of a pre-trained model to retrieve the text to be retrieved as in existing technologies, there is no need for sample labeling, organizing a thesaurus, or training a model. This reduces the amount of work required for training and iterating the model, thereby improving work efficiency.
[0215] Based on the same inventive concept, one embodiment of the present invention provides a device for text retrieval in document image files. Specific implementation methods for text retrieval in document image files using this device can be found in the description of the method embodiments section; repeated details will not be repeated here. Figure 7 The device includes:
[0216] The selection unit 701 is used to select the segmentation words that are the same as the search segmentation words in the text to be searched from the set of text blocks corresponding to the document image file, so as to obtain a candidate text block set; wherein, the search segmentation words are obtained by segmenting the text to be searched according to the preset segmentation rules, the segmentation words are obtained by segmenting each text block corresponding to the document image file according to the preset segmentation rules, and the segmentation words are associated with the index number of the text block from which the segmentation words originate;
[0217] The merging unit 702 is used to select at least one group of text blocks from the candidate text block set that have an overall coverage of the searched word segmentation in the text to be searched that is greater than a preset coverage and are arranged in ascending order in the reading direction of the text to be searched, and merge them to obtain at least one merged text block; wherein, the index numbers contained in different groups of text blocks are not completely the same.
[0218] The processing unit 703 is configured to determine, from the at least one merged text block, the precise text that matches the start and end words of the text to be retrieved, and obtain a precise text set; and to take the precise text in the precise text set whose character similarity to the text to be retrieved is greater than a preset value as the retrieval result.
[0219] In one possible implementation, the apparatus further includes a construction unit 704, which is further configured to:
[0220] Before selecting the segmentation word that is the same as the search segmentation word in the text to be searched from the set of text blocks corresponding to the document image file, optical character recognition is performed on each document image in a set of document image files corresponding to the letter of credit business to obtain the original text block set of each document image file; wherein, each original text block in the original text block set has a unique index number;
[0221] Replace the lowercase Western letters in each original text block in the original text block set with uppercase Western letters, and replace the interference characters in the original text block with spaces to obtain the corresponding text block; wherein, the index number of the text block is the index number of the corresponding original text block;
[0222] Each text block corresponding to the original text block set is segmented according to the preset word segmentation rules to obtain multiple segmented words corresponding to the original text block set;
[0223] Based on the index number of each text block from which each segment word originates, an inverted index is established for the corresponding segment word; wherein, the segment word is associated with the text block from which it originates through the index number in the inverted index;
[0224] All the segmented words corresponding to the original text block set are used to construct the text block set of the document image file.
[0225] In one possible implementation, the building unit 704 is further configured to:
[0226] Optical character recognition is performed on each document image file to obtain multiple initial text blocks;
[0227] The multiple initial text blocks are corrected so that two adjacent initial text blocks with actual line spacing less than normal line spacing are aligned in the same row, resulting in multiple original text blocks.
[0228] According to the reading order of the document image file, the corrected original text blocks are numbered sequentially to obtain the index number of each original text block;
[0229] The original text blocks with index numbers corresponding to the document image files are constructed into the original text block set.
[0230] In one possible implementation, the building unit 704 is further configured to:
[0231] Based on the spaces in each text block, the non-Chinese characters in each text block are segmented to obtain the non-Chinese words contained in each text block;
[0232] The Chinese characters in each text block are segmented into individual characters to obtain the Chinese word segments contained in each text block;
[0233] All non-Chinese word segments and all Chinese word segments are deduplicated to obtain multiple segmented words corresponding to the original text block.
[0234] In one possible implementation, the selection unit 701 is further configured to:
[0235] Set the search words in the text to be searched that are consistent with the preset high-frequency words as stop words; and remove duplicate search words corresponding to the text to be searched.
[0236] Each non-stop word after deduplication is used as a valid search word segment;
[0237] Each valid search word segment is compared one by one with the segmented words in the text block set;
[0238] All successfully matched segmented words are used to construct the candidate text block set.
[0239] In one possible implementation, the merging unit 702 is further configured to:
[0240] The index number associated with each segmentation word in the candidate text block set is associated with the search segmentation word in the text to be searched that matches the corresponding segmentation word to obtain the initial text sequence to be searched;
[0241] In the reading direction of the text to be retrieved, the index numbers that meet the preset conditions located in the tail region of the initial text sequence to be retrieved are removed to obtain the text sequence to be retrieved; wherein, the preset condition is that the index number is less than the index number associated with the previous retrieval word segmentation;
[0242] In the reading direction of the text to be retrieved, obtain all combinations of index numbers arranged in descending order from the sequence of text to be retrieved;
[0243] The overall coverage of the text to be retrieved by the corresponding combination is determined based on the total number of search terms contained in each combination.
[0244] Select the text blocks corresponding to the combinations whose overall coverage is greater than the preset coverage, and merge them in ascending order of the index numbers in the corresponding combinations to obtain the merged text blocks of the corresponding combinations.
[0245] In one possible implementation, the processing unit 703 is further configured to:
[0246] From the at least one merged text block, select merged text blocks with consecutive text block positions as consecutive text blocks to obtain at least one consecutive text block;
[0247] From the at least one continuous text block, select continuous text blocks whose total length is less than a preset length as intermediate text blocks; wherein, the preset length is a preset multiple of the length of the text to be retrieved, and the preset multiple is greater than 1;
[0248] The precise text set is obtained by identifying the exact text from the intermediate text block that matches the start and end words of the text to be retrieved.
[0249] In one possible implementation, the processing unit 703 is further configured to:
[0250] If two adjacent text blocks in the merged text block are in the same row, determine whether the spacing between the two adjacent text blocks is less than or equal to the width of a Western letter. If so, determine that the two adjacent text blocks are consecutive adjacent text blocks.
[0251] If two adjacent text blocks are not aligned, determine whether the line spacing between the two adjacent text blocks is less than the height of a Western letter, and whether the overlap of the two adjacent text blocks in the column direction is greater than a preset percentage. If both are true, determine that the two adjacent text blocks are consecutive adjacent text blocks.
[0252] When all adjacent text blocks in the merged text block are consecutive adjacent text blocks, the merged text block is determined to be a consecutive text block.
[0253] In one possible implementation, the processing unit 703 is further configured to:
[0254] Select the first and last word segments from the text to be retrieved;
[0255] The first word segment and the last word segment are compared with the word segment corresponding to the middle text block. The two word segments in the middle text block that are successfully compared with the first word segment and the last word segment, as well as the part between the two word segments, are determined as the corresponding precise text.
[0256] The precise text set is composed of the precise text corresponding to all intermediate texts.
[0257] In one possible implementation, the processing unit 703 is further configured to:
[0258] Count the total number of identical word segments in each exact text and the text to be retrieved;
[0259] The ratio of the total number to the total number of search terms contained in the text to be searched is determined as the character similarity of the corresponding precise text;
[0260] The exact text with a character similarity greater than the preset value is used as the search result of the text to be searched in the document image file.
[0261] It should be noted that the division of units in the embodiments of this application is illustrative and only represents one logical functional division. In actual implementation, other division methods may be used. Furthermore, the functional units in the various embodiments of this application can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated units described above can be implemented in hardware or as software functional units.
[0262] If the integrated unit is implemented as a software functional unit and sold or used as an independent product, it can be stored in a processor-readable storage medium. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, or all or part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) or processor to execute all or part of the steps of the methods described in the various embodiments of this application. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.
[0263] It should be noted that the apparatus provided in this embodiment of the invention can implement all the method steps implemented in the above method embodiment and can achieve the same technical effect. Therefore, the parts and beneficial effects that are the same as those in the method embodiment will not be described in detail here.
[0264] Based on the same inventive concept, this invention provides an apparatus for text retrieval in document image files, comprising: at least one processor, and
[0265] Memory connected to the at least one processor;
[0266] The memory stores instructions that can be executed by the at least one processor, which executes the instructions stored in the memory to perform the text retrieval method in the document image file as described above.
[0267] Based on the same inventive concept, embodiments of the present invention also provide a readable storage medium, comprising:
[0268] memory,
[0269] The memory is used to store instructions that, when executed by a processor, cause the apparatus including the readable storage medium to perform the method of text retrieval in a document image file as described above.
[0270] The readable storage medium can be any available medium or data storage device accessible to the processor, including volatile memory or non-volatile memory, or both. By way of example, and not limitation, non-volatile memory can include read-only memory (ROM), programmable read-only memory (PROM), electrically programmable read-only memory (EPROM), electrically erasable programmable read-only memory (EEPROM), flash memory, solid-state disk (SSD), magnetic storage (e.g., floppy disk, hard disk, magnetic tape, magneto-optical disc (MO), etc.), and optical storage (e.g., CD, DVD, BD, HVD, etc.). Volatile memory can include random access memory (RAM), which can act as an external cache memory. By way of example and not limitation, RAM can be obtained in various forms, such as Dynamic Random Access Memory (DRAM), Synchronous Dynamic Random-Access Memory (SDRAM), Double Data Rate SDRAM (DDR SDRAM), Enhanced Synchronous DRAM (ESDRAM), and Sync Link DRAM (SLDRAM). The storage devices disclosed herein are intended to include, but are not limited to, these and other suitable types of memory.
[0271] Based on the same inventive concept, this invention also provides a computer program product, including program code, which, when a computer runs the computer program, executes the text retrieval method in the document image file as described above.
[0272] Those skilled in the art will understand that embodiments of the present invention can be provided as methods, systems, or program products. Therefore, embodiments of the present invention can take the form of entirely hardware embodiments, entirely software embodiments, or embodiments combining software and hardware aspects. Furthermore, embodiments of the present invention can take the form of machine program products implemented on one or more readable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer / processor-usable program code.
[0273] Embodiments of the present invention are described with reference to flowchart illustrations and / or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of the invention. It will be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These program instructions can be provided to a processor of a general-purpose computer, special-purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, generate instructions for implementing the flowchart illustrations. Figure 1 One or more processes and / or boxes Figure 1 A device that provides the functions specified in one or more boxes.
[0274] These program instructions may also be stored in a readable storage medium that can direct a computer or other programmable data processing device to operate in a particular manner, such that the instructions stored in the readable storage medium produce an article of manufacture including instruction means, which are implemented in a process Figure 1 One or more processes and / or boxes Figure 1 The function specified in one or more boxes.
[0275] These program instructions may also be loaded onto a computer or other programmable data processing apparatus to cause a series of operational steps to be performed on the computer or other programmable apparatus to produce a process implemented by the computer / processor, thereby providing instructions that execute on the computer / processor or other programmable apparatus for implementing the process. Figure 1 One or more processes and / or boxes Figure 1 The steps of the function specified in one or more boxes.
[0276] Obviously, those skilled in the art can make various modifications and variations to this invention without departing from its spirit and scope. Therefore, if these modifications and variations fall within the scope of the claims of this invention and their equivalents, this invention also intends to include these modifications and variations.
Claims
1. A method for searching text in a document image file, characterized by, The method comprises the following steps: From the text block set corresponding to the single certificate image file, select the same cut word as the search word in the text to be searched to obtain a candidate text block set; wherein, the search word is obtained by cutting the text to be searched according to a preset word segmentation rule, and the cut word is obtained by cutting each text block corresponding to the single certificate image file according to the preset word segmentation rule; the cut word is associated with the index number of the text block from which the cut word originates; From the candidate text block set, select at least one group of text blocks that have an overall coverage of the search word in the text to be searched greater than a preset coverage and are arranged in ascending order in the reading direction of the text to be searched, and merge the text blocks to obtain at least one merged text block; wherein, different groups of text blocks contain different index numbers; From the at least one merged text block, determine the accurate text consistent with the start and end words of the text to be searched to obtain an accurate text set; The accurate text set with a character similarity greater than a preset value to the text to be searched is taken as a search result; Wherein, from the candidate text block set, select at least one group of text blocks that have an overall coverage of the search word in the text to be searched greater than a preset coverage and are arranged in ascending order in the reading direction of the text to be searched, and merge the text blocks to obtain at least one merged text block, comprising: Associate the index number of each cut word in the candidate text block set with the search word consistent with the corresponding cut word in the text to be searched to obtain an initial text to be searched sequence; In the reading direction of the text to be searched, remove the index numbers located in the tail area of the initial text to be searched sequence that meet a preset condition to obtain a text to be searched sequence; wherein, the preset condition is that the index number is less than the index number associated with the previous search word; In the reading direction of the text to be searched, obtain all combinations of index numbers arranged in descending order from the text to be searched sequence; Determine the overall coverage of the corresponding combination to the text to be searched according to the total number of search words contained in each combination; Select the text blocks corresponding to the combination with the overall coverage greater than the preset coverage, and merge the text blocks in the ascending order of the index numbers in the corresponding combination to obtain the merged text blocks of the corresponding combination; From the at least one merged text block, determine the accurate text consistent with the start and end words of the text to be searched to obtain an accurate text set, comprising: From the at least one merged text block, select the merged text blocks with continuous positions as continuous text blocks to obtain at least one continuous text block; From the at least one continuous text block, select the continuous text blocks with a total length less than a preset length as intermediate text blocks; wherein, the preset length is a preset multiple of the length of the text to be searched, and the preset multiple is greater than 1; From the intermediate text blocks, determine the accurate text consistent with the start and end words of the text to be searched to obtain an accurate text set.
2. The method of claim 1, wherein, Before selecting the same cut word as the search word in the text to be searched from the text block set corresponding to the single certificate image file, the method further comprises the following steps: In a set of image files of documents corresponding to the letter of credit business, optical character recognition is performed on each image of the documents to obtain a set of original text blocks of each image file of the documents; wherein each original text block in the set of original text blocks has a unique index number; The lower-case English letters in each original text block in the set of original text blocks are replaced with upper-case English letters, and the interference symbols in the original text block are replaced with spaces to obtain a corresponding text block; wherein the index number of the text block is the index number of the corresponding original text block; Each text block corresponding to the set of original text blocks is segmented according to the preset word segmentation rule to obtain a plurality of segmented words corresponding to the set of original text blocks; According to the index number of each text block from which each segmented word originates, an inverted order index of the corresponding segmented word is established; wherein the segmented word is associated with the text block originating from the index number in the inverted order index; All segmented words corresponding to the set of original text blocks are constructed into a set of text blocks of the image file of the documents.
3. The method of claim 2, wherein, In a set of image files of documents corresponding to the letter of credit business, optical character recognition is performed on each image of the documents to obtain a set of original text blocks of each image file of the documents, including: Optical character recognition is performed on each image file of the documents to obtain a plurality of initial text blocks; Correction is performed on the plurality of initial text blocks so that two adjacent initial text blocks with an actual line spacing smaller than a normal line spacing are in the same line to obtain a plurality of original text blocks; The plurality of original text blocks after the correction are sequentially numbered according to a reading order of the image file of the documents to obtain an index number of each original text block; The original text blocks with the index number corresponding to the image file of the documents are constructed into the set of original text blocks.
4. The method of claim 2, wherein, Each text block corresponding to the set of original text blocks is segmented according to the preset word segmentation rule to obtain a plurality of segmented words corresponding to the set of original text blocks, including: Non-Chinese characters in each text block are segmented according to spaces in the text block to obtain non-Chinese segmented words contained in the text block; Chinese characters in the text block are segmented into single characters to obtain Chinese segmented words contained in the text block; All non-Chinese segmented words and all Chinese segmented words are de-duplicated to obtain a plurality of segmented words corresponding to the original text blocks.
5. The method according to any one of claims 2 to 4, wherein, From a set of text blocks corresponding to the image file of the documents, a set of candidate text blocks is obtained by selecting segmented words identical to search segmented words in a text to be searched, including: Search segmented words identical to preset high-frequency words in the text to be searched are set as stop words; and search segmented words corresponding to the text to be searched are de-duplicated; Each non-stop word after the de-duplication is used as an effective search segmented word; Each effective search segmented word is compared with segmented words in the set of text blocks one by one; All successfully compared segmented words are constructed into the set of candidate text blocks.
6. The method of claim 5, wherein, From the at least one merged text block, a merged text block with continuous text block positions is selected as a continuous text block to obtain at least one continuous text block, including: If the two adjacent text blocks in the merged text block are in the same line, it is determined whether the interval between the two adjacent text blocks is less than or equal to the width of a western letter, and if yes, the two adjacent text blocks are determined to be the continuously adjacent text blocks; If the two adjacent text blocks are in different lines, it is determined whether the line interval between the two adjacent text blocks is less than the height of a western letter, and whether the overlapping degree of the two adjacent text blocks in the column direction is greater than a preset percentage, and if both are yes, the two adjacent text blocks are determined to be the continuously adjacent text blocks; When all the adjacent text blocks in the merged text block are the continuously adjacent text blocks, the merged text block is determined to be the continuous text block.
7. The method of claim 5, wherein, From the intermediate text blocks, accurate texts consistent with the start and end words of the text to be searched are determined to obtain an accurate text set, including: selecting a first segmented word and a last segmented word from the text to be searched; comparing the first segmented word and the last segmented word with the segmented words corresponding to the intermediate text blocks, respectively, determining two segmented words and the part between the two segmented words in the intermediate text blocks as corresponding accurate texts, which are successfully compared with the first segmented word and the last segmented word; all the accurate texts corresponding to the intermediate texts are combined to form the accurate text set.
8. The method of claim 5, wherein, The accurate texts with a character similarity greater than a preset value to the text to be searched in the accurate text set are taken as the search result, including: counting the total number of the same segmented words of each accurate text in the text to be searched; determining the ratio of the total number to the total number of search segmented words contained in the text to be searched as the character similarity of the corresponding accurate text; the accurate texts with the character similarity greater than the preset value are taken as the search result of the text to be searched in the image file of the single document.
9. A device for text retrieval in a document image file, characterized in that, including: a selection unit configured to select segmented words identical to search segmented words in a text to be searched from a text block set corresponding to an image file of a single document to obtain a candidate text block set; the search segmented words are segmented from the text to be searched according to a preset segmentation rule, the segmented words are segmented from each text block corresponding to the image file of the single document according to the preset segmentation rule, and the segmented words are associated with the index number of the text block from which the segmented words are derived; a merging unit configured to select at least one group of text blocks from the candidate text block set, which has a whole coverage greater than a preset coverage to the search segmented words in the text to be searched and is arranged in ascending order in a reading direction of the text to be searched, and merge the text blocks to obtain at least one merged text block; different groups of text blocks contain different index numbers; a processing unit configured to determine accurate texts consistent with the start and end words of the text to be searched from the at least one merged text block to obtain an accurate text set, and take accurate texts with a character similarity greater than a preset value to the text to be searched in the accurate text set as a search result. The merging unit is further configured to associate, with each segmented word in the candidate text block set, an index number with a search segmented word in the text to be searched that is consistent with the corresponding segmented word, to obtain an initial text sequence to be searched; remove, in a reading direction of the text to be searched, an index number in a tail region of the initial text sequence to be searched that meets a preset condition, to obtain a text sequence to be searched; wherein the preset condition is that the index number is less than an index number associated with a previous search segmented word; obtain, in the reading direction of the text to be searched, all combinations of index numbers arranged in descending order from the text sequence to be searched; determine, according to a total number of search segmented words included in each combination, an overall coverage of the text to be searched by the corresponding combination; select a text block corresponding to a combination whose overall coverage is greater than the preset coverage; and merge the text block in an ascending order of index numbers in the corresponding combination, to obtain a merged text block of the corresponding combination; the processing unit is further configured to select, from the at least one merged text block, a merged text block whose positions are continuous as a continuous text block, to obtain at least one continuous text block; filter, from the at least one continuous text block, a continuous text block whose total length is less than a preset length as an intermediate text block; wherein the preset length is a preset multiple of the length of the text to be searched, and the preset multiple is greater than 1; determine, from the intermediate text block, an accurate text that is consistent with a start word and an end word of the text to be searched, to obtain an accurate text set.
10. An apparatus for searching a text in a document image file, characterized by comprising: comprise: at least one processor, and a memory connected to the at least one processor; wherein the memory stores instructions that can be executed by the at least one processor, and the at least one processor executes the method according to any one of claims 1-8 by executing the instructions stored in the memory.
11. A readable storage medium, characterized by, comprise a memory, the memory is configured to store instructions, and when the instructions are executed by a processor, the apparatus comprising the readable storage medium completes the method according to any one of claims 1-8.
12. A computer program product, characterised in that, comprise program code, and when a computer runs the computer program, the program code executes the method according to any one of claims 1-8.
Citation Information
Patent Citations
Bill automatic identification and processing system based on OCR
CN105528604A
Electronic contract signing method and device, terminal and storage medium
CN112561746A