A method and device for processing text

By clustering and merging fragment text blocks in image documents, the problems of high labor costs and computing resources when processing text in the prior art are solved, and the efficiency and accuracy of processing text are improved.

CN113742485BActive Publication Date: 2025-04-25BEIJING WODONG TIANJUN INFORMATION TECH CO LTD +1
View PDF 3 Cites 0 Cited by

Patent Information

Application Number
CN202111047593.3
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-09-08
Publication Date
2025-04-25
Estimated Expiration
2041-09-08

AI Technical Summary

Technical Problem

When processing text in image documents, the prior art requires labeling and training through supervised machine learning methods, resulting in high labor costs and computing resources, and the accuracy of generating continuous text is reduced when the number of samples is insufficient.

Method used

By clustering multiple to-be-processed fragment text blocks, it is determined whether there is a merge relationship between fragment text blocks, and merge text blocks based on the merge relationship to generate target text in a reasonable order.

Benefits of technology

Overcoming the high labor costs and computing resource problems of supervised machine learning methods, improving the efficiency and accuracy of text processing.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN113742485B_ABST
    Figure CN113742485B_ABST
Patent Text Reader

Abstract

The present invention discloses a method and device for processing text, and relates to the field of computer technology. A specific implementation of the method includes: clustering a plurality of fragment text blocks to be processed, determining whether there is a merging relationship between the fragment text blocks, and merging the text blocks based on the merging relationship to generate a target text with a reasonable order; the problem of high labor cost and high computing resources consumed by using supervised machine learning methods is overcome, and the efficiency and accuracy of text processing are improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of computer technology, and in particular to a method and device for processing text. Background Art

[0002] With the rapid development of image processing technology, image-based text recognition technology has been widely used. For example, OCR (Optical Character Recognition) technology is used to recognize text contained in image documents. When OCR technology is used to process image documents, multiple text segments are usually generated based on one image document. However, the multiple text segments are in a disordered state.

[0003] At present, supervised machine learning methods can be used to generate continuous text that conforms to the reading order by annotating and training each text segment. However, since this method requires obtaining sample data required for training and annotating the sample data, the manpower cost and computing resources for processing text are increased. In addition, when the number of samples is insufficient, there is a problem of reduced accuracy in generating continuous text. Summary of the invention

[0004] In view of this, an embodiment of the present invention provides a method and device for processing text, which can cluster multiple fragment text blocks to be processed, determine whether there is a merging relationship between the fragment text blocks, and merge the text blocks based on the merging relationship to generate a target text with a reasonable order; it overcomes the problems of high labor costs and computing resources consumed by supervised machine learning methods, and improves the efficiency and accuracy of text processing.

[0005] To achieve the above-mentioned purpose, according to one aspect of an embodiment of the present invention, a method for processing text is provided, characterized in that it includes: determining multiple fragment text blocks to be processed; clustering the multiple fragment text blocks; for a cluster text block indicated by the clustering result containing the multiple fragment text blocks, searching the cluster text block for multiple fragment text blocks that meet a preset merging strategy, and merging the multiple fragment text blocks that meet the preset merging strategy; and generating a target text according to the merging result.

[0006] Optionally, the method for processing text is characterized in that clustering the multiple fragment text blocks includes: expanding each of the fragment text blocks using a preset expansion coefficient; searching for multiple fragment text blocks with a connected relationship based on the expansion result of each of the fragment text blocks; and clustering the multiple fragment text blocks with a connected relationship into a clustered text block.

[0007] Optionally, the method for processing text is characterized by further comprising:

[0008] Acquire the characteristic coordinates of each of the fragment text blocks; based on the characteristic coordinates of each of the fragment text blocks, search for multiple fragment text blocks with an aligned relationship; and expand each of the fragment text blocks using a preset expansion coefficient, including: using a first expansion coefficient to expand each of the fragment text blocks with an aligned relationship; and using a second expansion coefficient to expand each of the remaining fragment text blocks.

[0009] Optionally, the method for processing text is characterized in that clustering the multiple fragment text blocks further includes: in the case where there are multiple clustered text blocks, performing an iterative operation to cluster the clustered text blocks with connectivity to generate new clustered text blocks.

[0010] Optionally, the method for processing text is characterized in that:

[0011] The method further includes: generating a clustering tree according to the clustering result; searching for multiple fragment text blocks that meet the preset merging strategy based on the clustering tree, and executing the step of merging the multiple fragment text blocks that meet the preset merging strategy.

[0012] Optionally, the method for processing text is characterized in that a clustering tree is generated based on the clustering results, including: constructing corresponding leaf nodes for each fragment text block contained in the clustered text block; constructing upper-level nodes and a root node based on the clustered text block and the leaf nodes; and associating the leaf nodes corresponding to the fragment text blocks that do not belong to any of the clustered text blocks to the root node.

[0013] Optionally, the method for processing text is characterized in that:

[0014] Based on the characteristic coordinates of each of the fragment text blocks, searching for multiple fragment text blocks having an alignment relationship includes: sorting each of the fragment text blocks based on the vertical coordinates included in the characteristic coordinates; and executing steps A1-A2 for each of the fragment text blocks:

[0015] A1: obtaining the vertical coordinates of the text block fragment and the text block adjacent to the text block fragment; calculating the distance value of the vertical coordinates of the text block fragment and the text block adjacent to the text block fragment;

[0016] A2: Determine whether the distance value is less than a first preset value, and if so, determine that a text block adjacent to the text block segment and the text block segment have a horizontal alignment relationship.

[0017] Optionally, the method for processing text is characterized in that:

[0018] Based on the characteristic coordinates of each of the fragment text blocks, searching for multiple fragment text blocks having an alignment relationship includes: sorting each of the fragment text blocks based on the horizontal coordinates included in the characteristic coordinates; and executing steps B1-B2 for each of the fragment text blocks:

[0019] B1: Acquire the fragment text block and the horizontal coordinates of the text block adjacent to the fragment text block; calculate the distance value between the fragment text block and the horizontal coordinates of the text block adjacent to the fragment text block;

[0020] B2: Determine whether the distance value is less than a second preset value, and if so, determine that the text block adjacent to the text block segment and the text block segment have a vertical alignment relationship.

[0021] Optionally, the method for processing text is characterized in that: the preset merging strategy includes: when the leaf nodes corresponding to any two of the fragment text blocks have the same parent node corresponding to the cluster text block, the any two of the fragment text blocks satisfy the two text blocks to be merged according to the merging strategy;

[0022] Alternatively, when the leaf nodes corresponding to any two of the fragment text blocks have the same parent node corresponding to the cluster text block, the character sizes corresponding to the texts contained in the any two fragment text blocks are obtained respectively; and the similarity values ​​between the character sizes corresponding to the any two fragment text blocks are calculated;

[0023] In the case where the similarity value is not greater than the set similarity threshold, the arbitrary two fragment text blocks are two text blocks to be merged that meet the merging strategy.

[0024] Optionally, the method for processing text is characterized in that:

[0025] The searching for multiple fragment text blocks satisfying a preset merging strategy in the clustered text blocks and merging the multiple fragment text blocks satisfying the preset merging strategy includes:

[0026] Based on the order of the leaf nodes included in the clustering tree, the fragment text blocks corresponding to the leaf nodes are obtained; and steps C1-C4 are executed in a loop until all the fragment text blocks have been matched, and then the loop ends:

[0027] C1: Select the current text block from each of the fragment text blocks;

[0028] C2: Determine whether the current text block and the adjacent text block meet the preset merging strategy; if they match, execute step C3; otherwise, execute step C4;

[0029] C3: Merge the current text block and the adjacent text block to obtain a merged text block; use the merged text block as the current text block and execute step C2;

[0030] C4: Take the adjacent text block as the current text block and execute the steps of C2.

[0031] To achieve the above object, according to a second aspect of an embodiment of the present invention, a device for processing text is provided, characterized in that it comprises: a text clustering module and a text merging module; wherein:

[0032] The text clustering module is used to determine a plurality of text fragments to be processed; and cluster the plurality of text fragments;

[0033] The text merging module is used to search for multiple fragment text blocks that meet a preset merging strategy in a clustered text block indicated by a clustering result and contain multiple fragment text blocks, and merge the multiple fragment text blocks that meet the preset merging strategy; and generate a target text based on the merging result.

[0034] To achieve the above-mentioned purpose, according to the third aspect of an embodiment of the present invention, there is provided an electronic device for processing text, characterized in that it includes: one or more processors; a storage device for storing one or more programs, when the one or more programs are executed by the one or more processors, the one or more processors implement any of the methods described in the above-mentioned methods for processing text.

[0035] To achieve the above-mentioned purpose, according to a fourth aspect of an embodiment of the present invention, a computer-readable medium is provided, on which a computer program is stored, characterized in that when the program is executed by a processor, any method as described in the above-mentioned method for processing text is implemented.

[0036] An embodiment of the above invention has the following advantages or beneficial effects: it can cluster multiple fragment text blocks to be processed, determine whether there is a merging relationship between the fragment text blocks, and merge the text blocks based on the merging relationship to generate a target text with a reasonable order; it overcomes the problems of high labor costs and computing resources consumed by using supervised machine learning methods, and improves the efficiency and accuracy of text processing.

[0037] The further effects of the above-mentioned non-conventional optional manner will be described below in conjunction with the specific implementation manner. BRIEF DESCRIPTION OF THE DRAWINGS

[0038] The accompanying drawings are used to better understand the present invention and do not constitute an improper limitation of the present invention.

[0039] Figure 1is a flowchart of a method for processing text provided by an embodiment of the present invention;

[0040] Figure 2 It is a schematic diagram of a process of clustering text blocks provided by an embodiment of the present invention;

[0041] Figure 3 It is a schematic diagram of a process of merging text blocks provided by an embodiment of the present invention;

[0042] Figure 4 is a schematic diagram of the structure of a device for processing text provided by an embodiment of the present invention;

[0043] Figure 5 is an exemplary system architecture diagram to which embodiments of the present invention may be applied;

[0044] Figure 6 It is a schematic diagram of the structure of a computer system of a terminal device or a server suitable for implementing an embodiment of the present invention. DETAILED DESCRIPTION

[0045] The following is a description of exemplary embodiments of the present invention in conjunction with the accompanying drawings, including various details of the embodiments of the present invention to facilitate understanding, which should be considered as merely exemplary. Therefore, it should be recognized by those of ordinary skill in the art that various changes and modifications may be made to the embodiments described herein without departing from the scope and spirit of the present invention. Similarly, for clarity and conciseness, the description of well-known functions and structures is omitted in the following description.

[0046] like Figure 1 As shown, an embodiment of the present invention provides a method for processing text, which may include the following steps:

[0047] Step S101: Determine a plurality of text fragment blocks to be processed.

[0048] Specifically, the fragment text block of the present invention takes the OCR (Optical Character Recognition) text block as an example. In text recognition, the image document containing the text is usually binarized, and then the text is extracted from the image document (for example, the product details image document). An OCR-based tool can be used, that is, an image document can be used to obtain multiple fragment text blocks using the OCR tool. Since there is a situation where a continuous text corresponds to multiple OCR text blocks, the list of text blocks obtained by the OCR tool cannot ensure the coherence of the text, and the text blocks are disordered, that is, inconsistent with the reading order of people. Therefore, the present invention processes the OCR text block to obtain a target text with coherence and consistent with the reading order through multiple text blocks. Among them, before processing the text, the text segments with low relevance to the text can be screened and removed by setting features, such as table text segments, picture text segments, etc.

[0049] Step S102: clustering the plurality of text fragment blocks.

[0050] Specifically, a clustering operation is performed on the multiple fragment text blocks to be processed to determine information such as the correlation and sequence between the multiple fragment text blocks.

[0051] Preferably, the clustering method includes using image processing tools (e.g. OpenCV) to determine whether there is a connectivity relationship between the fragment text blocks, and after iterative operations, clustering the text blocks with connectivity relationship into clustered text blocks, that is, the fragment text blocks contained in the clustered text blocks have a connectivity relationship.

[0052] Furthermore, before determining whether there is a connectivity relationship between the fragment text blocks, an expansion operation is performed for each fragment text block (expansion is a method of processing an image, by adding pixel values ​​to the edge of the image, so that the overall pixel value is expanded, thereby achieving an image expansion effect). The expansion operation can improve the accuracy of the image processing tool in determining connectivity and performing clustering. That is, clustering the plurality of fragment text blocks includes: using a preset expansion coefficient to expand each of the fragment text blocks; according to the expansion result of each of the fragment text blocks, searching for a plurality of fragment text blocks with connectivity; clustering the plurality of fragment text blocks with connectivity into a clustered text block, preferably, generating a clustering tree according to the clustering result.

[0053] Furthermore, before performing the expansion operation for each text block segment, it is necessary to determine an expansion coefficient for each text block segment, so as to determine the expansion range by the expansion coefficient; the specific description of clustering is consistent with the description of step S201 to step S206, and will not be repeated here.

[0054] By clustering, the association relationship between text blocks is obtained, which improves the efficiency of determining the order of text blocks. It is an unsupervised method. Compared with the supervised machine learning model, it reduces the computational difficulty and complexity, saves manpower and computing costs, and improves the efficiency of text processing.

[0055] Step S103: for a clustered text block indicated by the clustering result that contains multiple fragment text blocks, search for multiple fragment text blocks that meet the preset merging strategy in the clustered text block, and merge the multiple fragment text blocks that meet the preset merging strategy; generate the target text according to the merging result.

[0056] Specifically, according to the clustering result described in step S102, a merging operation is performed on each fragment text block to obtain a coherent target text that conforms to the reading order. The specific description of searching for multiple fragment text blocks that meet the preset merging strategy in the clustered text blocks and merging the multiple fragment text blocks that meet the preset merging strategy is consistent with the description of steps S301 to S307, and will not be repeated here.

[0057] By merging texts after clustering, the efficiency of generating target texts is improved. Compared with supervised machine learning models, the computational difficulty and complexity are reduced, manpower and computing costs are saved, and the efficiency of text processing is improved.

[0058] like Figure 2 As shown, an embodiment of the present invention provides a schematic diagram of a process of clustering text blocks; the process may include the following steps:

[0059] Step S201: Obtain the feature coordinates of each text block.

[0060] Specifically, the text block obtained by the OCR tool is taken as an example. The feature coordinates of the text block indicate the position and range of the text block. Each text block contains the data of the invisible rectangular box and the corresponding text. The feature coordinates can be the upper left corner coordinates and the lower right corner coordinates of the invisible rectangular box to determine the position and range. i Indicates that its characteristic coordinates are: (x1 i ,y1 i ), (x2 i , y2 i ), where (x1 i ,y1 i ) corresponds to S i The upper left corner coordinates, (x2 i , y2 i ) corresponds to S i The lower right corner coordinates; the font size of the text it contains is expressed as f i .

[0061] Step S202: based on the feature coordinates of each text segment block, searching for multiple text segment blocks having an alignment relationship.

[0062] Specifically, searching for a plurality of fragment text blocks having an alignment relationship includes: searching for a plurality of fragment text blocks having a horizontal alignment relationship and a fragment text block having a vertical alignment relationship.

[0063] Specifically:

[0064] 1) The method for finding multiple fragment text blocks with horizontal alignment relationship is:

[0065] Sort the text fragments based on the vertical coordinates included in the feature coordinates; and for each text fragment, perform steps A1-A2:

[0066] A1: Obtain the vertical coordinates of the text block fragment and the text block adjacent to the text block fragment; calculate the distance value of the vertical coordinates of the text block fragment and the text block adjacent to the text block fragment;

[0067] A2: Determine whether the distance value is less than a first preset value, and if so, determine that a text block adjacent to the text block segment and the text block segment have a horizontal alignment relationship.

[0068] Among them, the vertical coordinate y1 of each fragment text block can be i Sorting; looping to calculate the distance value hdist of the vertical coordinates of the text block fragment and the text blocks adjacent to the text block fragment. For example, the formula for calculating the distance value hdist of the vertical coordinate is as follows, wherein min represents taking the minimum value among the calculation results of the respective values ​​corresponding to the vertical coordinates contained therein:

[0069] hdist(S i ,S i+1 )=min(|y1 i -y1 i+1 |,|y2 i -y2 i+1 |,|(y1 i +y2 i ) / 2-(y1 i+1 +y2 i+1 ) / 2|)

[0070] Among them, S i , S i+1 represents two adjacent fragment text blocks, further, it is determined whether hdist is less than a first preset value (w v f i), if so, it is determined that the text blocks adjacent to the fragment text block and the fragment text block have a horizontal alignment relationship, and this method is used to determine whether each fragment text block has a text block that has a horizontal alignment relationship with it.

[0071] 2) The method for finding multiple fragment text blocks with vertical alignment relationship is:

[0072] Sort the text blocks based on the horizontal coordinates included in the feature coordinates; and for each text block, perform steps B1-B2:

[0073] B1: Acquire the fragment text block and the horizontal coordinates of the text block adjacent to the fragment text block; calculate the distance value between the fragment text block and the horizontal coordinates of the text block adjacent to the fragment text block;

[0074] B2: Determine whether the distance value is less than a second preset value, and if so, determine that the text block adjacent to the text block segment and the text block segment have a vertical alignment relationship.

[0075] Among them, the horizontal coordinate x1 of each fragment text block can be i Sorting; calculating the distance value vdist of the horizontal coordinates of the text block fragment and the text block adjacent to the text block fragment. For example, the formula for calculating the distance value vdist of the horizontal coordinate is as follows, wherein min represents taking the minimum value among the calculation results of the respective numerical values ​​corresponding to the horizontal coordinate contained therein:

[0076] vdist(Si,Si+1)=min(|x1 i -x1 i+1 |,|x2 i -x2 i+1 |,|(x1 i +x2 i ) / 2-(x1 i+1 +x2 i+1 ) / 2|)

[0077] Determine whether vdist is less than the second preset value (w h f i ), if so, it is determined that the text blocks adjacent to the fragment text block and the fragment text block have a vertical alignment relationship, and this method is used to determine whether each fragment text block has a text block that has a vertical alignment relationship with it.

[0078] Among them, f i For the fragment text block S i The font size of the contained text, w h 、w v It can be set to 0.3. The default value can be set according to the size and format of the image document.

[0079] Step S203: using the first expansion coefficient, expand each text block segment having an alignment relationship; using the second expansion coefficient, expand each remaining text block segment.

[0080] Specifically, according to the description of step S202, the alignment relationship (any one or more of the horizontal alignment relationship and the vertical alignment relationship) of each text block segment is determined.

[0081] Further, each of the text blocks is expanded according to a preset expansion coefficient; if the text blocks have a horizontal alignment relationship, a first expansion coefficient (for example, e ah f i ) for expansion; if the fragment text blocks have a vertical alignment relationship, the first expansion coefficient (for example: e av f i ) for expansion; if the fragment text blocks do not have an alignment relationship, the second expansion coefficient (for example: ef i ) is expanded (i.e., the remaining fragment text blocks that do not have an alignment relationship are expanded using the second expansion coefficient), where e ah 、e av Both can be set to 0.6. The value is set according to the size and format of the image file. ah 、e av They can be set to the same value or different values; e can be set to 0.2. i It is the font size of the text contained in the fragment text block; it can be understood that the expansion coefficient is different from that related to the expanded image (i.e., the fragment text block). By setting different expansion coefficients, the accuracy of clustering the fragment text blocks based on the expansion processing is improved. The present invention does not limit the numerical value of each preset expansion coefficient.

[0082] The description of step S201 to step S203 is: obtaining the characteristic coordinates of each of the fragment text blocks; searching for multiple fragment text blocks with an aligned relationship based on the characteristic coordinates of each of the fragment text blocks; using a preset expansion coefficient to expand each of the fragment text blocks, including: using a first expansion coefficient to expand each of the fragment text blocks with an aligned relationship; using a second expansion coefficient to expand each of the remaining fragment text blocks. It can be understood that the expansion process can expand each text block in the horizontal and vertical directions based on the expansion coefficient, that is, expand the range of the invisible rectangle of each fragment text block, and the expanded invisible rectangle range is the obtained expansion result. The expansion operation increases the probability and accuracy of determining that multiple fragment text blocks have a connected relationship.

[0083] Step S204: searching for multiple fragment text blocks having a connected relationship; clustering the multiple fragment text blocks having a connected relationship into a clustered text block.

[0084] Specifically, based on each fragment text block after expansion, multiple fragment text blocks with a connected relationship are searched; preferably, an image processing tool (such as: OpenCV) is used to scan the binary image after expansion, and the multiple fragment text blocks with a connected relationship are clustered into clustered text blocks; it can be understood that the fragment text blocks contained in the clustered text blocks have a high probability of being consistent with the text in the original image document in terms of coherence and arrangement order.

[0085] Further, optionally, the clustering operation is continued for the clustered text blocks to generate new clustered text blocks, that is, the clustering of the multiple fragment text blocks further includes: when there are multiple clustered text blocks, an iterative operation is performed to cluster the clustered text blocks with connectivity to generate new clustered text blocks.

[0086] That is, each of the fragment text blocks is expanded using a preset expansion coefficient; multiple fragment text blocks with a connected relationship are searched based on the expansion result of each fragment text block; and the multiple fragment text blocks with a connected relationship are clustered into a clustered text block.

[0087] Step S205: Determine whether the condition for ending clustering is met. If yes, execute step S206; otherwise, execute step S202.

[0088] Specifically, the conditions for clustering to end include: the number of unclustered clustered text blocks is 1, the number of unclustered segment text blocks is 1, and a set clustering iteration threshold is reached (for example, the clustering iteration threshold is set to 3); if any of the clustering end conditions is met, the clustering operation ends. Otherwise, step S202 is executed.

[0089] Step S206: Generate a clustering tree according to the clustering results.

[0090] Specifically, a clustering tree is generated based on the fragment text blocks and the corresponding cluster text blocks to save the association relationship between the fragment text blocks and the corresponding one or more layers of cluster text blocks, wherein the clustering tree is generated based on the clustering results, including: constructing corresponding leaf nodes for each fragment text block contained in the cluster text block; constructing upper nodes and root nodes based on the cluster text blocks and the leaf nodes; and associating the leaf nodes corresponding to the fragment text blocks that do not belong to any of the cluster text blocks to the root node.

[0091] Furthermore, the process of generating a clustering tree can be synchronized with the clustering process. For example, when a clustering text block is generated based on multiple fragment text blocks, a corresponding leaf node is constructed for each fragment text block contained in the clustering text block, and an upper-level node is constructed for the clustering text block until a root node is constructed. The unclustered fragment text blocks (i.e., the fragment text blocks that do not belong to any of the clustering text blocks) are directly associated with the root node to form a clustering tree.

[0092] like Figure 3 As shown, an embodiment of the present invention provides a method for merging text blocks, which may include the following steps:

[0093] Step S301: Obtain each fragment text block corresponding to the leaf node.

[0094] Specifically, a clustering tree is generated according to the clustering result; the clustering tree is traversed (for example, the clustering tree is traversed in a depth-first order) to obtain each leaf node, the leaf node corresponds to a fragment text block, that is, based on the order of the leaf nodes included in the clustering tree, each of the fragment text blocks corresponding to the leaf node is obtained. Further, a merging operation is performed according to the obtained fragment text blocks, that is, based on the clustering tree, multiple fragment text blocks that meet the preset merging strategy are searched, and the step of merging the multiple fragment text blocks that meet the preset merging strategy is performed.

[0095] Furthermore, the preset merge strategy includes: when the leaf nodes corresponding to any two of the fragment text blocks have the same parent node corresponding to the cluster text block, the any two fragment text blocks are two text blocks to be merged that meet the merge strategy; or, when the leaf nodes corresponding to any two of the fragment text blocks have the same parent node corresponding to the cluster text block, respectively obtaining the character sizes corresponding to the texts contained in any two fragment text blocks; calculating the similarity value between the character sizes corresponding to the any two fragment text blocks; when the similarity value is not greater than the set similarity threshold, the any two fragment text blocks are two text blocks to be merged that meet the merge strategy.

[0096] Among them, the parent node of the leaf node is obtained through the clustering tree, that is, the cluster block corresponding to the fragment text block corresponding to the leaf node can be obtained, so as to determine whether two fragment text blocks have a common cluster block, that is, the leaf nodes corresponding to any two fragment text blocks have the same parent node corresponding to the cluster text block, which is used as the condition of the preset merging strategy;

[0097] Further, when the parent nodes corresponding to the leaf nodes of any two of the segment text blocks are the same, calculate the similarity degree between the character sizes corresponding to any two segment text blocks as a preset merging strategy; wherein, the method for calculating the similarity value between character sizes is: if there is no alignment relationship between two segment text blocks, use the formula |f i -f i+1 | / f i <m to determine whether it satisfies that the similarity value is not greater than a set similarity threshold (for example, set m to 0.06), wherein, f i and f i+1 respectively represent the text font sizes of segment text block S i and segment text block S i+1 . When it is not greater than the set similarity threshold, determine that the two segment text blocks are two to-be-merged text blocks that meet the merging strategy; if there is an alignment relationship between two segment text blocks, use |f i -f i+1 | / f i <m a formula to determine whether it satisfies that the similarity value is not greater than a set similarity threshold (for example, m a is set to 0.3). When it is not greater than the set similarity threshold, determine that the two segment text blocks are two to-be-merged text blocks that meet the preset merging strategy. Among them, the two to-be-merged text blocks are selected from the segment text blocks, and the format and content of the to-be-merged text blocks are the same as the corresponding segment text blocks.

[0098] The description and steps for merging based on the preset merging strategy are the same as those in step S302 - step S307, and will not be elaborated here.

[0099] Step S302: Determine whether all segment text blocks have been matched. If so, execute step S303; otherwise, execute step S304.

[0100] Specifically, determining whether all segment text blocks have been matched is to determine the condition for the end of the loop, that is, to determine whether each segment text block has been matched.

[0101] Step S303: End the merging.

[0102] Step S304: Select the current text block from each of the segment text blocks.

[0103] Specifically, the segment text blocks can be selected in sequence according to the order of the segment text blocks obtained from the clustering tree. For example: select the first segment text block in the segment text block list as the current text block, as the starting point of the merging loop operation.

[0104] Step S305: Determine whether the current text block and the adjacent text block meet the preset merging strategy. If yes, execute step S306; otherwise, execute step S307.

[0105] Specifically, the description of the preset merging strategy is consistent with the description of step S301 and will not be repeated here.

[0106] Step S306: merge the current text block and the adjacent text block to obtain a merged text block. Specifically, after obtaining the merged text block, the adjacent text block can be deleted to form a new text block list, and step S305 is continued to be executed for loop judgment. Further, when the merged text block is used as the current text block, the vertex coordinates of the feature coordinates of the merged text block can be calculated using the following method: i is min(x1 i ,x1 i+1 ), that is, x1 i ,x1 i+1 The minimum value in i is max(y1 i ,y1 i+1 ) result; x2 i is min(x2 i ,x2 i+1 ) result; y2 i is max(y2 i ,y2 i+1 ) result. By recalculating the feature coordinates of the merged text block, the merge operation is performed in a loop. The loop ends until all the fragment text blocks have been matched. That is, the loop ends after each fragment text block in the list is traversed in order, and the target text is generated based on the merged one or more text blocks.

[0107] Step S307: Use the adjacent text block as the current text block. Execute step S305.

[0108] For example: fragment text block 1 and fragment text block 2 are adjacent fragment text blocks; determine whether fragment text block 1 and fragment text block 2 satisfy the preset merge strategy, if so, merge fragment text block 1 and fragment text block 2 into fragment text block A (i.e., merged text block), take fragment text block A as the current text block, and continue to execute the step of determining whether the preset merge strategy is satisfied with the adjacent text blocks; if fragment text block 1 and fragment text block 2 do not satisfy the preset merge strategy, take fragment text block 2 (i.e., the adjacent text block) as the current text block, and continue to execute the step of determining whether the preset merge strategy is satisfied with the adjacent text blocks.

[0109] The description of step S302 to step S307 is: searching for multiple fragment text blocks that meet the preset merging strategy in the clustered text blocks, and merging the multiple fragment text blocks that meet the preset merging strategy, including:

[0110] Based on the order of the leaf nodes included in the clustering tree, the fragment text blocks corresponding to the leaf nodes are obtained; and steps C1-C4 are executed in a loop until all the fragment text blocks have been matched, and then the loop ends:

[0111] C1: Select the current text block from each of the fragment text blocks;

[0112] C2: Determine whether the current text block and the adjacent text block meet the preset merging strategy; if they match, execute step C3; otherwise, execute step C4;

[0113] C3: Merge the current text block and the adjacent text block to obtain a merged text block; use the merged text block as the current text block and execute step C2;

[0114] C4: Take the adjacent text block as the current text block and execute the steps of C2.

[0115] like Figure 4 As shown, the embodiment of the present invention provides a device 400 for processing text, including: a text clustering module 401 and a text merging module 402; wherein,

[0116] The text clustering module 401 is used to determine a plurality of text fragments to be processed; and cluster the plurality of text fragments;

[0117] The text merging module 402 is used to search for multiple fragment text blocks that meet a preset merging strategy in a clustered text block containing multiple fragment text blocks indicated by the clustering result, and merge the multiple fragment text blocks that meet the preset merging strategy; generate a target text based on the merging result.

[0118] An embodiment of the present invention also provides an electronic device for processing text, comprising: one or more processors; a storage device for storing one or more programs, when the one or more programs are executed by the one or more processors, the one or more processors implement the method provided in any of the above embodiments.

[0119] An embodiment of the present invention further provides a computer-readable medium on which a computer program is stored. When the program is executed by a processor, the method provided in any of the above embodiments is implemented.

[0120] Figure 5An exemplary system architecture 500 is shown to which the method for processing text or the apparatus for processing text according to the embodiments of the present invention can be applied.

[0121] like Figure 5 As shown, system architecture 500 may include terminal devices 501, 502, 503, a network 504 and a server 505. Network 504 is used to provide a medium for communication links between terminal devices 501, 502, 503 and server 505. Network 504 may include various connection types, such as wired, wireless communication links or optical fiber cables, etc.

[0122] Users can use terminal devices 501, 502, 503 to interact with server 505 through network 504 to receive or send messages, etc. Various client applications can be installed on terminal devices 501, 502, 503, such as e-commerce client applications, web browser applications, search applications, instant messaging tools, and email clients.

[0123] The terminal devices 501 , 502 , and 503 may be various electronic devices having a display screen and supporting various client applications, including but not limited to smart phones, tablet computers, laptop computers, desktop computers, and the like.

[0124] The server 505 may be a server providing various services, such as a background management server providing support for client applications used by users using the terminal devices 501, 502, 503. The background management server may process the received request for processing text and send the target text to the terminal device.

[0125] It should be noted that the method for processing text provided in the embodiment of the present invention is generally executed by the server 505 , and accordingly, the device for processing text is generally set in the server 505 .

[0126] It should be understood that Figure 5 The number of terminal devices, networks and servers in the embodiment is only for illustration. Any number of terminal devices, networks and servers may be provided according to implementation requirements.

[0127] Reference below Figure 6 , which shows a schematic diagram of the structure of a computer system 600 of a terminal device suitable for implementing an embodiment of the present invention. Figure 6 The terminal device shown is only an example and should not bring any limitation to the functions and scope of use of the embodiments of the present invention.

[0128] like Figure 6As shown, the computer system 600 includes a central processing unit (CPU) 601, which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 602 or a program loaded from a storage part 608 into a random access memory (RAM) 603. In the RAM 603, various programs and data required for the operation of the system 600 are also stored. The CPU 601, the ROM 602, and the RAM 603 are connected to each other via a bus 604. An input / output (I / O) interface 605 is also connected to the bus 604.

[0129] The following components are connected to the I / O interface 605: an input section 606 including a keyboard, a mouse, etc.; an output section 607 including a cathode ray tube (CRT), a liquid crystal display (LCD), etc., and a speaker, etc.; a storage section 608 including a hard disk, etc.; and a communication section 609 including a network interface card such as a LAN card, a modem, etc. The communication section 609 performs communication processing via a network such as the Internet. A drive 610 is also connected to the I / O interface 605 as needed. A removable medium 611, such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, etc., is installed on the drive 610 as needed, so that a computer program read therefrom is installed into the storage section 608 as needed.

[0130] In particular, according to the embodiments disclosed in the present invention, the process described above with reference to the flowchart can be implemented as a computer software program. For example, the embodiments disclosed in the present invention include a computer program product, which includes a computer program carried on a computer-readable medium, and the computer program includes a program code for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from the network through the communication part 609, and / or installed from the removable medium 611. When the computer program is executed by the central processing unit (CPU) 601, the above-mentioned functions defined in the system of the present invention are executed.

[0131] It should be noted that the computer-readable medium shown in the present invention may be a computer-readable signal medium or a computer-readable storage medium or any combination of the above two. The computer-readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, or any combination of the above. More specific examples of computer-readable storage media may include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In the present invention, a computer-readable storage medium may be any tangible medium containing or storing a program that can be used by or in combination with an instruction execution system, device or device. In the present invention, a computer-readable signal medium may include a data signal propagated in a baseband or as part of a carrier wave, which carries a computer-readable program code. This propagated data signal may take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. Computer-readable signal media may also be any computer-readable medium other than computer-readable storage media, which may send, propagate or transmit a program for use by or in conjunction with an instruction execution system, apparatus or device. The program code contained on the computer-readable medium may be transmitted using any appropriate medium, including but not limited to: wireless, wire, optical cable, RF, etc., or any suitable combination of the above.

[0132] The flow chart and block diagram in the accompanying drawings illustrate the possible architecture, function and operation of the system, method and computer program product according to various embodiments of the present invention. In this regard, each box in the flow chart or block diagram can represent a module, a program segment, or a part of a code, and the above-mentioned module, program segment, or a part of a code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the box can also occur in a different order from the order marked in the accompanying drawings. For example, two boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram or flow chart, and the combination of the boxes in the block diagram or flow chart can be implemented with a dedicated hardware-based system that performs a specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.

[0133] The modules and / or units involved in the embodiments of the present invention may be implemented in software or hardware. The modules and / or units described may also be arranged in a processor. For example, they may be described as: a processor includes a text clustering module and a text merging module. The names of these modules do not constitute limitations on the modules themselves in certain cases. For example, the text clustering module may also be described as "a module for determining a plurality of fragment text blocks to be processed; a module for clustering the plurality of said fragment text blocks".

[0134] As another aspect, the present invention also provides a computer-readable medium, which may be included in the device described in the above embodiment; or may exist independently without being assembled into the device. The above computer-readable medium carries one or more programs, and when the above one or more programs are executed by a device, the device includes: determining multiple fragment text blocks to be processed; clustering multiple fragment text blocks; for a cluster text block containing multiple fragment text blocks indicated by the clustering result, searching the cluster text block for multiple fragment text blocks that meet the preset merging strategy, and merging the multiple fragment text blocks that meet the preset merging strategy; generating the target text according to the merging result.

[0135] The embodiments of the present invention utilize clustering of multiple fragment text blocks to be processed to determine whether there is a merging relationship between the fragment text blocks, and merge the text blocks based on the merging relationship to generate a target text with a reasonable order; it overcomes the problems of high labor costs and computing resources consumed by using supervised machine learning methods, and improves the efficiency and accuracy of text processing.

[0136] The above specific implementations do not constitute a limitation on the protection scope of the present invention. It should be understood by those skilled in the art that various modifications, combinations, sub-combinations and substitutions may occur depending on design requirements and other factors. Any modification, equivalent substitution and improvement made within the spirit and principle of the present invention shall be included in the protection scope of the present invention.

Claims

1. A method for processing text, characterized in that: include: Determine multiple fragment text blocks to be processed; Clustering a plurality of the fragment text blocks; For a clustered text block including a plurality of the fragment text blocks indicated by the clustering result, searching for a plurality of fragment text blocks satisfying a preset merging strategy in the clustered text block, and merging the plurality of fragment text blocks satisfying the preset merging strategy; Generate a clustering tree based on the clustering results; Constructing corresponding leaf nodes for each fragment text block contained in the clustered text block; The preset merging strategy includes: when the leaf nodes corresponding to any two of the fragment text blocks have the same parent node corresponding to the cluster text block, respectively obtaining the character sizes corresponding to the texts contained in the any two fragment text blocks; calculating the similarity value between the character sizes corresponding to the any two fragment text blocks; when the similarity value is not greater than the set similarity threshold, the any two fragment text blocks are two text blocks to be merged that meet the merging strategy; Generate the target text based on the merged results.

2. The method according to claim 1, characterized in that The clustering of the plurality of fragment text blocks comprises: Using a preset expansion coefficient, each of the fragment text blocks is expanded; According to the expansion result of each of the fragment text blocks, searching for multiple fragment text blocks having a connected relationship; Clustering a plurality of the fragment text blocks having a connected relationship into a clustered text block.

3. The method according to claim 2, characterized in that Further including: Obtaining feature coordinates of each of the fragment text blocks; Based on the feature coordinates of each of the fragment text blocks, searching for multiple fragment text blocks having an alignment relationship; The step of expanding each of the text blocks using a preset expansion coefficient includes: Using the first expansion coefficient, each segment text block having an alignment relationship is expanded; Each of the remaining text blocks is expanded using the second expansion coefficient.

4. The method according to claim 2, characterized in that: The clustering of the plurality of text fragment blocks further comprises: In the case where there are multiple clustered text blocks, an iterative operation is performed to cluster the clustered text blocks having a connected relationship to generate new clustered text blocks.

5. The method according to claim 4, characterized in that Further including: Based on the clustering tree, multiple fragment text blocks that meet the preset merging strategy are searched, and the step of merging the multiple fragment text blocks that meet the preset merging strategy is performed.

6. The method according to claim 5, characterized in that Generate a clustering tree based on the clustering results, including: Based on the clustered text blocks and the leaf nodes, constructing upper-level nodes and root nodes; The leaf nodes corresponding to the fragment text blocks that do not belong to any of the clustered text blocks are associated with the root node.

7. The method according to claim 3, characterized in that Based on the feature coordinates of each of the fragment text blocks, searching for multiple fragment text blocks having an alignment relationship includes: Sort each of the fragment text blocks based on the vertical coordinates included in the feature coordinates; For each of the fragment text blocks, perform steps A1-A2: A1: Obtain the vertical coordinates of the text block fragment and the text block adjacent to the text block fragment; calculate the distance value of the vertical coordinates of the text block fragment and the text block adjacent to the text block fragment; A2: Determine whether the distance value is less than a first preset value, and if so, determine that a text block adjacent to the text block segment and the text block segment have a horizontal alignment relationship.

8. The method according to claim 3, characterized in that Based on the characteristic coordinates of each of the fragment text blocks, searching for multiple fragment text blocks having an alignment relationship includes: sorting the fragment text blocks based on the horizontal coordinates included in the characteristic coordinates; For each of the text blocks, perform steps B1-B2: B1: Obtain the fragment text block and the horizontal coordinates of the text block adjacent to the fragment text block; calculate the distance value between the fragment text block and the horizontal coordinates of the text block adjacent to the fragment text block; B2: Determine whether the distance value is less than a second preset value, and if so, determine that the text block adjacent to the text block segment and the text block segment have a vertical alignment relationship.

9. The method according to claim 5, characterized in that The searching for multiple fragment text blocks satisfying a preset merging strategy in the clustered text blocks and merging the multiple fragment text blocks satisfying the preset merging strategy includes: Based on the order of the leaf nodes included in the clustering tree, the fragment text blocks corresponding to the leaf nodes are obtained; and steps C1-C4 are executed in a loop until all the fragment text blocks have been matched, and then the loop ends: C1: Select the current text block from each of the fragment text blocks; C2: Determine whether the current text block and the adjacent text block meet the preset merging strategy; if they match, execute step C3; otherwise, execute step C4; C3: Merge the current text block and the adjacent text block to obtain a merged text block; use the merged text block as the current text block and execute step C2; C4: Take the adjacent text block as the current text block and execute the steps of C2.

10. A device for processing text, characterized in that: include: Text clustering module and text merging module; among them, The text clustering module is used to determine a plurality of text fragments to be processed; and cluster the plurality of text fragments; The text merging module is used to search for multiple fragment text blocks that meet a preset merging strategy in a clustered text block indicated by a clustering result and contain multiple fragment text blocks, and merge the multiple fragment text blocks that meet the preset merging strategy; generate a clustering tree according to the clustering result; construct corresponding leaf nodes for each fragment text block contained in the clustered text block; wherein the preset merging strategy includes: when the leaf nodes corresponding to any two of the fragment text blocks have the same parent node corresponding to the clustered text block, respectively obtain the character sizes corresponding to the texts contained in any two fragment text blocks; calculate the similarity value between the character sizes corresponding to the any two fragment text blocks; when the similarity value is not greater than the set similarity threshold, the any two fragment text blocks are two text blocks to be merged that meet the merging strategy; and generate the target text according to the merging result.

11. An electronic device, characterized in that: include: one or more processors; a storage device for storing one or more programs, When the one or more programs are executed by the one or more processors, the one or more processors implement the method according to any one of claims 1 to 9.

12. A computer readable medium having a computer program stored thereon, characterized in that: When the program is executed by a processor, the method according to any one of claims 1 to 9 is implemented.

Citation Information

Patent Citations

  • Method and device for extracting text line in file

    CN105574530A

  • Electronic menu generation method, device and apparatus

    CN111192346A

  • Document information extraction method and device and electronic equipment

    CN111680491A