Catalog generation method, electronic device, and computer program product
By building the initial text tree and using the directory recognition model to extract features, the problem of poor genericity of PDF document directory generation in the prior art is solved, and accurate identification and directory generation of complex and deep-level title structures are achieved.
Patent Information
- Application Number
- CN202411659469.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-20
- Publication Date
- 2025-02-25
- Estimated Expiration
- 2044-11-20
AI Technical Summary
The PDF document directory generation method based on rule library matching in the prior art has poor generality and cannot effectively deal with complex and deep-level title structure.
By detecting and processing the object to be detected, the initial text tree is built and inputted into the pre-trained directory recognition model, the global and local features of the node are extracted, the prediction label is determined, and the initial text tree is corrected to generate the target text tree, thereby generating Table of contents.
Improves the accuracy of directory recognition, especially when dealing with documents with complex and deep-level title structures, enhances the recognition of long-distance title levels and improves the versatility of directory generation.
Smart Images

Figure CN119152533B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer technology, and in particular to a directory generation method, an electronic device, and a computer program product. Background Art
[0002] PDF (Portable Document Format) is a commonly used document format. In some scenarios, it is necessary to generate a PDF document directory for a PDF document to provide readers with a clear overview and structured guidance, help them quickly locate information, and improve the readability and usability of the document. Especially for long or complex documents, key information such as financial data can be efficiently extracted by generating a PDF document directory. Therefore, how to generate a PDF document directory for a PDF document is a problem that needs to be solved.
[0003] In the prior art, most of the matching is based on the directory title rule base. A directory title rule base is pre-established for documents in a specific field, and the text in the document is matched based on the directory title rule base. On this basis, different parts of the document are classified, such as first-level titles, second-level titles, text, etc., and matching is performed based on the classification results and the directory title rule base, so as to identify the title in the document and establish a PDF document directory based on the title.
[0004] However, existing methods rely on customized rules and lack universality. In addition, although the existing technology can use text and coordinate information for classification, it still relies on matching paragraph information with the rule base, and still has the problem of poor universality. Summary of the invention
[0005] The purpose of this application is to provide a directory generation method, electronic device and computer program product to address the shortcomings of the above-mentioned prior art, so as to solve the problem of poor universality of rule-based matching in the prior art.
[0006] To achieve the above objectives, the technical solutions adopted in this application are as follows:
[0007] In a first aspect, the present application provides a method for generating a directory, the method comprising:
[0008] Performing detection processing on the object to be detected to obtain multiple text blocks of the object to be detected and text block information of each of the text blocks;
[0009] Generate an initial text tree according to the multiple text blocks and the text block information of each of the text blocks, wherein the initial text tree includes multiple nodes, each of the nodes corresponds to a text block, and the initial text tree is used to represent the hierarchical relationship between the nodes;
[0010] Inputting the initial text tree into a pre-trained directory recognition model, the directory recognition model extracts global features and local features of each node, and based on the global features and local features of each node, determines a predicted label of each node, wherein the predicted label is used to characterize the hierarchical relationship between the node and its adjacent sibling nodes;
[0011] The initial text tree is modified according to the predicted labels of each node to obtain the target text tree of the object to be detected, and the directory generation result of the object to be detected is obtained according to the target text tree and the text blocks corresponding to each node in the target text tree.
[0012] In a second aspect, an embodiment of the present application further provides a directory generation device, the device comprising:
[0013] A detection module, used for performing detection processing on an object to be detected, and obtaining a plurality of text blocks of the object to be detected and text block information of each of the text blocks;
[0014] A generating module, configured to generate an initial text tree according to the plurality of text blocks and text block information of each of the text blocks, wherein the initial text tree includes a plurality of nodes, each of the nodes corresponds to a text block, and the initial text tree is used to represent the hierarchical relationship between the nodes;
[0015] A prediction module, used for inputting the initial text tree into a pre-trained directory recognition model, extracting global features and local features of each node by the directory recognition model, and determining a prediction label of each node based on the global features and local features of each node, wherein the prediction label is used to characterize the level relationship between the node and its adjacent sibling nodes;
[0016] A correction module is used to correct the initial text tree according to the predicted labels of each node to obtain a target text tree of the object to be detected, and to obtain a directory generation result of the object to be detected based on the target text tree and the text blocks corresponding to each node in the target text tree.
[0017] In a third aspect, an embodiment of the present application further provides an electronic device, comprising: a processor, a storage medium and a bus, wherein the storage medium stores machine-readable instructions executable by the processor, and when the electronic device is running, the processor communicates with the storage medium via the bus, and the processor executes the machine-readable instructions to perform the steps of the directory generation method as described in any one of the first aspects.
[0018] In a fourth aspect, an embodiment of the present application further provides a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the steps of the directory generation method as described in any one of the first aspects are implemented.
[0019] In a fifth aspect, an embodiment of the present application further provides a computer program product, wherein the computer program product comprises a computer program code. When the computer program code is executed by a computing device, the computing device executes the steps of the directory generation method as described in any one of the first aspects.
[0020] The beneficial effects of the present application are as follows: the initial text tree is constructed for the text block of the object to be detected, and the hierarchical relationship between the text blocks can be more clearly represented by the structure of the initial text tree. For documents with complex hierarchical relationships of titles, the complexity of identifying deep-level titles can be reduced. By extracting local features from each node in the initial text tree, the hierarchical relationship between the title and the adjacent title can be obtained, thereby improving the accuracy of directory recognition. In addition, the present application further proposes to extract the global features of the current node based on the initial text tree, and the overall relationship between the current title and other titles in the entire document can be represented by the global features, thereby improving the correlation between hierarchical titles across multiple pages, and improving the accuracy of recognition for long-distance title levels. In addition, the present application not only takes into account the text content of the text block itself, but also further takes into account the text block information, so that the differences between the title and the text and different title levels can be more easily captured based on the text block information, so that the directory recognition model can learn more distinguishing differentiated features, thereby improving the accuracy of recognition of the directory recognition model, and has good versatility for different documents.
[0021] In order to make the above-mentioned objects, features and advantages of the present application more obvious and easy to understand, preferred embodiments are specifically cited below and described in detail with reference to the attached drawings. BRIEF DESCRIPTION OF THE DRAWINGS
[0022] In order to more clearly illustrate the technical solutions of the embodiments of the present application, the drawings required for use in the embodiments will be briefly introduced below. It should be understood that the following drawings only show certain embodiments of the present application and therefore should not be regarded as limiting the scope. For ordinary technicians in this field, other related drawings can be obtained based on these drawings without paying creative work.
[0023] Figure 1 A flowchart of a directory generation method provided by an embodiment of the present application is shown;
[0024] Figure 2 A schematic diagram of a PDF page provided in an embodiment of the present application is shown;
[0025] Figure 3 A schematic diagram of the structure of an initial spanning tree provided in an embodiment of the present application is shown;
[0026] Figure 4A flowchart of extracting global features and local features provided by an embodiment of the present application is shown;
[0027] Figure 5 A schematic diagram of a subtree structure of a node 2 provided in an embodiment of the present application is shown;
[0028] Figure 6 A flowchart of extracting global features provided by an embodiment of the present application is shown;
[0029] Figure 7 A flowchart for obtaining a predicted label provided by an embodiment of the present application is shown;
[0030] Figure 8 A flowchart of obtaining a text block and text block information provided by an embodiment of the present application is shown;
[0031] Fig. 9 A flowchart of filtering text blocks provided by an embodiment of the present application is shown;
[0032] Fig.10 A flowchart of constructing an initial spanning tree provided by an embodiment of the present application is shown;
[0033] Fig.11 A flow chart of generating a target spanning tree provided by an embodiment of the present application is shown;
[0034] Fig.12 A schematic structural diagram of an electronic device 120 provided in an embodiment of the present application is shown. DETAILED DESCRIPTION
[0035] To make the purpose, technical scheme and advantages of the embodiments of the present application clearer, the technical scheme in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, rather than all of the embodiments. The components of the embodiments of the present application generally described and shown in the drawings here can be arranged and designed in various different configurations. Therefore, the following detailed description of the embodiments of the present application provided in the drawings is not intended to limit the scope of the application claimed for protection, but merely represents the selected embodiments of the present application. Based on the embodiments of the present application, all other embodiments obtained by those skilled in the art without making creative work belong to the scope of protection of the present application.
[0036] It should be noted that the term "comprising" will be used in the embodiments of the present application to indicate the existence of the features declared thereafter, but does not exclude the addition of other features.
[0037] Before introducing the technical solution of the embodiment of the present application, it is first necessary to explain that the directory generation method provided in the embodiment of the present application must obtain the user's consent in an explicit form before the personal information and important data collected and generated during the execution process can be applied to the solution of the embodiment of the present application. At the same time, the personal information and important data collected and generated during the execution of the directory generation method provided in the embodiment of the present application must comply with the principles of legality, legitimacy, and necessity, disclose the collection and use rules, and explicitly state the purpose, method, and scope of collecting and using information. The relevant data in the above examples do not include personal information that is not related to the relevant services provided by the above examples.
[0038] In the prior art, when the directory of a PDF document is automatically generated, matching is generally performed based on a preset directory title rule library. By matching the text content in the document with the rules in the directory title rule library, the text content that meets the font and font size indicated by the rules is identified as a title, and the document directory is generated based on the identified title.
[0039] On this basis, in order to further improve the accuracy of directory generation, the prior art also proposes to recognize the text in the document to obtain preliminary directory title information, and then further recognize the preliminary directory title information based on the directory title rule library to obtain the final directory title information.
[0040] However, matching directly based on the directory title rule base has the problem of poor universality. When identifying directory titles in the prior art, the focus is generally on extracting local features of the document, while ignoring the understanding of the overall content. Therefore, the existing solutions have poor directory recognition results for long and deep files. In particular, for documents such as financial data that have high requirements for accuracy and robustness, as well as directory generation tasks, the recognition and generation of document directories still have the problem of low accuracy.
[0041] Next, combine Figure 1 The directory generation method of the present application is described. The execution subject of the method can be an electronic device. Figure 1 , the method comprising:
[0042] S101 , performing detection processing on an object to be detected to obtain multiple text blocks of the object to be detected and text block information of each text block.
[0043] The object to be detected may be a document to be detected or a document image to be detected, such as a PDF image. The object to be detected may include multiple pages. Taking a PDF document as an example, the PDF document may be split to obtain multiple PDF images, and then each PDF image may be detected to obtain multiple text blocks in each PDF image and text block information of each text block.
[0044] Figure 2 This is a schematic diagram of an object to be detected given in this application, referring to Figure 2 The object to be detected includes multiple titles and paragraphs. After the object to be detected is detected, multiple text blocks shown in the dotted box can be obtained.
[0045] A text block can be an area consisting of text, in which the distance between the texts is less than a preset value, and each text block is distinguished by punctuation marks or line breaks. For example, a text block can be a title, text paragraph, header or footer of the object to be detected.
[0046] The text block information may include: the position of the text block, the color of the text in the text block, the font and font size of the text in the text block. The position of the text block includes the coordinates of the text block in the PDF image and the page number of the PDF image. The font of the text in the text block refers to the font type of the text in the text block, and the font size refers to the font size of the text in the text block.
[0047] S102: Generate an initial text tree according to the multiple text blocks and the text block information of each text block. The initial text tree includes multiple nodes, each node corresponds to a text block, and the initial text tree is used to represent the level relationship between the nodes.
[0048] A text block can be a header, footer, title, or ordinary text. When generating the initial text tree, the initial text tree can be generated for the text block of the title. The title can be further divided into multiple levels such as first-level titles and second-level titles, among which the second-level title can be considered as the next level of the first-level title. The initial text tree is used to characterize the hierarchical relationship between text blocks. The hierarchical relationship is used to describe the hierarchical relationship between the titles of the text blocks represented by the nodes. For example, when the text block is a first-level title and a second-level title, the first-level title can be subdivided into multiple second-level titles. According to the inclusion relationship of the title in the document, the node of the first-level title can be used as the parent node of all the second-level titles it contains.
[0049] The initial text tree can be a multi-branch tree, and each node is used to represent a text block. Among them, the nodes at a higher level in the initial text tree are used to represent titles of a higher level, and the text blocks represented by the nodes at the same level are titles of the same level. The connection relationship between each node in the initial text tree and other nodes can describe the relationship between the text block represented by the current node and the text blocks represented by other nodes in the document as a containment relationship or a peer relationship.
[0050] Figure 3 This is a schematic diagram of the structure of an initial text tree given in this application, refer to Figure 3 ,The initial text tree includes multiple nodes, where node 1 represents the first level title, for example Figure 2In the "Title 1" in the node, node 1.1 indicates the next level of title contained in node 1, for example Figure 2 In "Heading 1.1", text blocks with containment relationships are represented as parent-child node relationships in the initial text tree.
[0051] S103, inputting the initial text tree into a pre-trained directory recognition model, the directory recognition model extracts the global features and local features of each node, and determines the predicted label of each node based on the global features and local features of each node, the predicted label is used to characterize the hierarchical relationship between the node and its adjacent sibling nodes.
[0052] The connection relationship between nodes in the initial text tree is a preliminary determination of the inclusion or same-level relationship between the text blocks represented by the nodes. When performing directory recognition on an object to be detected with a relatively complex title hierarchy structure, there may be a situation where a subtitle is mistakenly recognized as a title of the same level, or a title of the same level is mistakenly recognized as a subtitle. Based on this, the application can further determine the level relationship between each node and other nodes in the initial text tree based on the directory recognition model, thereby improving the accuracy of directory generation for documents with complex title hierarchical structures.
[0053] Optionally, the directory recognition model may include multiple encoders, which are used to extract global features and local features of nodes respectively. After obtaining the global features and local features, the global features and local features may be fused, and predictions may be made based on the fused features to obtain predicted labels for each node.
[0054] In the present application, the adjacent sibling node may be the same as the parent node of the current node and the next adjacent node of the current node. The position order of the nodes in the initial text tree is the same as the position order of the text block represented by the node in the object to be detected. The predicted label is used to represent the level relationship between the node and the adjacent sibling node. The level relationship between the node and the adjacent sibling node can be: the current node is the same level title of the adjacent sibling node or the current node is the subtitle of the adjacent sibling node.
[0055] Reference Figure 3 , node 1 includes multiple child nodes, among which node 1.3 and node 1.2 have the same parent node, and node 1.2 is the previous adjacent node of node 1.3, then node 1.2 can be used as the adjacent sibling node of node 1.3, and node 1.2 and node 1.3 are titles of the same level.
[0056] Among them, the global feature can characterize the relationship between the current text block and other text blocks in the entire object to be detected, such as the relationship between the previous level text block, the next level text block and the same level text block, and can characterize the difference in text block information between the current text block and other text blocks. Local features are used to characterize the text content and text block information of the current node and adjacent sibling nodes.
[0057] S104, modifying the initial text tree according to the predicted label of each node to obtain a target text tree of the object to be detected, and obtaining a directory generation result of the object to be detected according to the target text tree and the text blocks corresponding to each node in the target text tree.
[0058] After obtaining the predicted label, the positional relationship between the current node and the adjacent sibling nodes of the current node in the initial text tree can be judged based on the predicted label. If the positional relationship between the current node and the adjacent sibling nodes in the initial text tree is the same as that indicated by the predicted label, the current node may not be corrected. If the positional relationship between the current node and the adjacent sibling nodes in the initial text tree is different from that indicated by the predicted label, the current node may be moved to the position indicated by the predicted label according to the positional relationship indicated by the predicted label to achieve correction of the current node.
[0059] Optionally, by traversing all nodes in the initial text tree and correcting each node based on the predicted label, the initial text tree can be modified to obtain the final target text tree.
[0060] The target text tree can indicate the hierarchical relationship between each text block in the object to be detected, and based on the hierarchical relationship of each node in the target text tree and the text block of each node, a directory generation result of the object to be detected can be generated. Exemplarily, after obtaining the target text tree, the target text tree can be converted into JSON format and transmitted to the back-end service, and the back-end parses the text blocks corresponding to each level of JSON and each level of nodes layer by layer, writes the title results of each level of nodes obtained by parsing into HTML, and finally parses the PDF document into an HTML result containing the title level.
[0061] The generated result of the directory of the object to be detected includes multiple title levels, and each title corresponds to a node in the target text tree. Figure 3 , "Title 1" and "Title 2" correspond to Figure 3 In the "Node 1" and "Node 2" in the title, "Title 1.1", "Title 1.2" and "Title 1.3" are the next level of "Title 1", corresponding to Figure 3 The child nodes of "Node 1" are "Node 1.1", "Node 1.2" and "Node 1.3".
[0062] In the embodiment of the present application, the initial text tree is constructed for the text block of the object to be detected, and the hierarchical relationship between the text blocks can be more clearly characterized by the structure of the initial text tree. For documents with complex hierarchical relationships of titles, the complexity of identifying deep-level titles can be reduced. By extracting local features from each node in the initial text tree, the hierarchical relationship between the title and the adjacent title can be obtained, thereby improving the accuracy of directory recognition. And the present application further proposes to extract the global features of the current node based on the initial text tree, and the overall relationship between the current title and other titles in the entire document can be characterized by the global features, thereby improving the correlation between the hierarchical titles across multiple pages, and improving the accuracy of recognition for the title hierarchy at a distance. In addition, in the present application, not only the text content of the text block itself is considered, but also the text block information is further considered, so that the difference between the title and the text and the different title levels can be more easily captured based on the text block information, so that the directory recognition model can learn more distinguishing differentiated features, thereby improving the accuracy of recognition of the directory recognition model, and has good versatility for different documents.
[0063] Optionally, the directory recognition model includes: a first encoder, a second encoder, a fusion module and a prediction module. The above process of predicting each node in the initial text tree to obtain the global features and local features of each node is as follows: Figure 4 As shown, including:
[0064] S401, performing a breadth-first search on the initial text tree to determine the adjacent sibling nodes of the current node, taking the current node and the adjacent sibling nodes of the current node as a node combination, and the current node is any node of the initial text tree.
[0065] Starting from the root node, the initial text tree takes the first child node connected to the root node as the current node, determines the adjacent sibling nodes of the current node, and takes the current node and the adjacent sibling nodes as a node combination. Then, the child nodes connected to the current node are traversed based on a breadth-first search method until the current node has no child nodes, thereby obtaining a node combination of all nodes in the initial text tree.
[0066] For each node combination, the first encoder encodes the text blocks and text block information of the two nodes contained in the node combination to obtain the local features of the current node. The local features of the current node are used to describe the text content and text block information of the current node and its adjacent sibling nodes.
[0067] S402: The first encoder encodes the text block and text block information of each node in the node combination to obtain the local features of the current node, and sends the local features to the fusion module.
[0068] The local feature of the current node may be a local feature of a node combination of the current node.
[0069] The first encoder can be composed of a pre-trained Chinese text encoder and a fully connected layer network. The Chinese text encoder is used to encode the text content of each text block in the node combination, and the text block information of each text block in the node combination is fused to obtain the encoding results of each text block. Finally, the encoding results of each text block in the node combination are spliced through the fully connected layer network to obtain the local features of the node combination.
[0070] As a possible implementation method, the process of encoding the text block and text block information of each node in the node combination can be expressed as the following formula (1), where and Expressed as and The multimodal features of the corresponding nodes, and Represents a given input tree node, It represents the pre-trained Chinese text encoder, and MLP is the fully connected layer network.
[0071] (1)
[0072] The fusion module can fuse global features and local features to obtain the node features of the current node.
[0073] S403: construct a subtree of the current node according to the initial text tree, where the subtree is used to describe the hierarchical relationship between the current node and nodes related to the current node.
[0074] The subtree of the current node may be a tree consisting of the current node and related nodes of the current node, where the related nodes of the current node include the child nodes of the current node, the parent node of the current node, and the adjacent sibling nodes of the current node in the initial text tree.
[0075] For example, Figure 3 As the current node, we can get Figure 5 The subtree shown includes node 2, the parent node "root node" of node 2, the adjacent sibling node "node 1" of node 2, and the child nodes of node 2 "node 2.1, node 2.2 and node 2.3".
[0076] S404: The second encoder determines the global feature of the current node according to the subtree of the current node, and sends the global feature to the fusion module.
[0077] As a possible implementation method, the global features of the current node can be obtained through graph learning. At this time, after constructing the subtree of the current node, the subtree can be converted into a graph G = (V, E). Before encoding the global features, first encode each node GRU encoding is performed, and the edges of parent nodes / sibling nodes can span multiple pages. In the process of converting to a graph, the text block information of the text block represented by the node can be added to the graph to obtain the relationship information of the current node, which is used to characterize the relationship between the current node and other nodes and the difference in text block information. In some complex documents, titles of the same level may be far apart. By building a subtree, the long-distance relationship information between titles of the same level can be provided.
[0078] In the embodiment of the present application, global features and local features are extracted based on the initial text tree, and the hierarchical relationship between the title and the adjacent titles can be obtained through the local features, thereby improving the accuracy of directory recognition. And compared with the prior art that only recognizes the directory through local features, the present application further proposes to build a subtree of the current node based on the initial text tree, and extract the global features of the current node based on the subtree of the current node. The global features can characterize the overall relationship between the current title and other titles in the entire document, thereby improving the correlation between hierarchical titles across multiple pages.
[0079] Further, such as Figure 6 As shown, the process of determining the global feature of the current node by the second encoder according to the subtree of the current node includes:
[0080] S601. The second encoder determines the relationship information of the current node according to the subtree of the current node, where the relationship information includes: the relationship type between each node in the subtree and the current node, and the font difference information and position difference information between each node in the subtree.
[0081] The relationship types between each node in the subtree and the current node include: adjacent sibling nodes of the current node, parent nodes of the current node, and child nodes of the current node. The font difference information between each node in the subtree can be the font difference, font size difference, text color difference, etc. between the text blocks represented by the nodes. The position difference information can be the coordinate difference of the corresponding points of the bounding box of the text block represented by the node.
[0082] It should be noted that after the current node is used as the central node, the relationship type, font difference information, and position difference information between each node in the subtree and the central node can be determined.
[0083] S602: The second encoder encodes the subtree of the current node, the text block of the current node, and the relationship information of the current node to obtain the global feature of the current node.
[0084] The second encoder can be a graph neural network structure. After obtaining the graph of the current node based on the subtree transformation, graph learning can be performed through the following formula (2) to obtain the global features of the current node.
[0085] (2)
[0086] in, represents the graph neural network structure, Represents the text block information of the current node Q given the input, Represents the relationship information of the current node, where Indicates that the current node The global features of the nodes in the subtree centered at .
[0087] After obtaining the global features and local features, the predicted label of each node can be determined based on the global features and local features of each node, such as Figure 7 As shown, the above step S103 includes:
[0088] S701: The fusion module performs splicing processing on the global features and local features of the current node based on preset learning parameters to obtain the node features of the current node, and sends the node features to the prediction module.
[0089] The learning parameters may be preset by a user or determined during the training process of the catalog recognition model.
[0090] As a possible implementation method, the process of concatenating global features and local features can be expressed as the following formula (3).
[0091] (3)
[0092] in, , and represents the learnable parameters, Represents the local features of the text pair, Represents the global features of a text pair.
[0093] S702: The prediction module predicts the node features, obtains and outputs the predicted label of the current node.
[0094] Among them, the prediction module can be composed of a feedforward network layer and a normalization layer. The feedforward network layer is composed of Activation function and After the node features are input into the prediction module, the feedforward network layer can predict the node features to obtain the prediction results, and input the prediction results into the normalization layer to obtain the prediction probabilities of each label of the node features, and take the label with the largest prediction probability as the predicted label of the current node. The following formula (4) is the prediction module predicting the node features to obtain the predicted probabilities of each label, and the following formula (5) indicates that the label with the largest probability is taken as the predicted label of the current node.
[0095] (4)
[0096] (5)
[0097] Among them, L represents all candidate labels, FFN represents the feedforward network, Q represents the current node, and C represents the adjacent sibling nodes of the current node. Represents the predicted probability of the label.
[0098] The above is an explanation of how the directory recognition model predicts each node in the initial text tree to obtain the predicted label of each node. Next, the training process of the directory recognition model is explained.
[0099] After the document is detected and processed, a text block is obtained and an initial text tree is constructed based on the text block. A label can be added to each node in the initial text tree. For example, the label can be 0, 1, or 2, where 0 indicates that the text block represented by the current node is a non-title node, 1 indicates that the current node is a subtitle of an adjacent sibling node, and 2 indicates that the current node and the adjacent sibling node are titles of the same level.
[0100] Based on the first encoder and the second encoder in the initial directory recognition model, feature extraction is performed on each node in the initial text tree respectively. After obtaining the global features and local features of each node, the global features and local features of each node can be spliced into node features of the node through the fusion module, and the node features are input into the initial prediction module to obtain the predicted labels of each node.
[0101] According to the predicted labels of each node predicted by the initial directory recognition model and the labeled labels of each node labeled in advance, the loss value is determined based on the following formula (6), and the initial directory recognition model is iteratively optimized according to the loss value to obtain the final directory recognition model.
[0102] (6)
[0103] During the model training process, the model can be optimized and trained using the stochastic gradient descent algorithm (Adaptive moment estimation, Adam) with a preset number of iterations, preset weight decay, and preset initial learning rate, and the batch size is set to 16. For pre-trained parameters, a learning rate of 1e-5 can be used. For parameters that require random initialization, a learning rate of 1e-3 can be used. For accuracy evaluation, the overall F1 score on the prediction tree node can be used to evaluate model performance. The calculation method of F1 is shown in the following formula (7).
[0104] (7)
[0105] in, Indicates the number of nodes whose predicted labels are consistent with the annotated labels, Indicates the number of actual positive samples, represents the number of prediction nodes, and To calculate the intermediate quantity, express and The ratio of express and ratio.
[0106] The following is a further description of performing the detection process on the object to be detected to obtain multiple text blocks of the object to be detected and the text block information of each text block. Figure 8 As shown, the above step S101 includes:
[0107] S801: Perform detection processing on the object to be detected to obtain at least one initial text line.
[0108] S802: parse and process each initial text line to obtain text line information of the initial text line, where the text line information includes: the position of the text line, the color of the text in the text line, and the size and font of the text in the text line.
[0109] If the object to be detected is a PDF image, the PDF image can be cut first to obtain multiple single pages. If the page is N pages, the document after cutting can be expressed as .
[0110] For each page after cutting, you can use the PDFBox parsing tool to obtain the text lines and text line information inside the region. The text position includes the coordinates of the text line in the region, the PDF page number where the text line is located, the font size of the text line can be the font size of most of the text in the text line, and the font of the text in the text line can be the font of most of the text in the text line.
[0111] S803. Cluster each initial text line to obtain at least one initial text block, and merge the text line information of each initial text line contained in each initial text block to obtain text block information of each initial text block, wherein the text block information includes: the position of the text block, the color of the text in the text block, and the font and size of the text in the text block.
[0112] By clustering the initial text lines according to their position information, at least one initial text block can be obtained. Figure 2 , text blocks can be headers, footers, paragraphs, and titles in the text.
[0113] When the text line information of the initial text line is merged, it can be implemented based on the paragraph merging model. The text content and text line information of the initial text line contained in the initial text block are merged through the paragraph merging model to obtain the text block information. The text block information can also include the number of text lines in the text block and the length of the text block.
[0114] Exemplary, single page The length of the text block in is , single page document List of text block text content information It can be expressed as: ,in express The first text block in the document. express The document The text content information of a text block, express The document The text content information of a text block.
[0115] Single Page Document text block text content list The relevant multimodal information can be expressed as: ,in, express The text block information for the first text block in the document, express The document The text block information of the text block, express The document The text block information of a text block.
[0116] S804: Filter each initial text block according to the text block information to obtain the text block of the object to be detected and the text block information of the text block.
[0117] The initial text blocks are preliminarily filtered, and the text blocks that may be titles and the text block information of the text blocks are used as the text blocks and the text block information of the text blocks of the objects to be detected.
[0118] As a possible implementation, Fig. 9 As shown, the process of filtering each initial text block according to the text block information to obtain the text block of the object to be detected and the text block information of the text block includes:
[0119] S901. Determine text font information in the object to be detected, where the text font information includes: the maximum font size and the maximum font size of non-title text in the object to be detected.
[0120] Optionally, the fonts and font sizes of the text in the object to be detected can be scanned to determine the fonts and font sizes included in the object to be detected, and the number of various fonts and font sizes can be counted to obtain the maximum font size and the maximum font size.
[0121] It should be understood that the largest proportion in a document is generally text content. Therefore, by counting the fonts and font sizes with the largest proportion, the largest proportion can be regarded as the largest proportion of font size and the largest proportion of font in non-title text.
[0122] S902. Traverse each initial text block. If the text block information of the initial text block indicates that the number of lines of the initial text block is greater than a preset line number threshold, and the font and font size in the initial text block are the same as the text font information, and the last punctuation mark of the initial text block is a preset symbol, then the initial text block is not used as a text block of the object to be detected. Otherwise, the initial text block is used as a text block of the object to be detected.
[0123] If the number of lines of the initial text block occupies multiple lines, and the font size and weight in the initial text block are the same as the font size and weight of most fonts in the document, and the initial text block ends with symbols such as a period, exclamation mark, question mark, ellipsis, etc., then it can be determined that the initial text block is a non-heading text block and the initial text block is deleted.
[0124] For the initial text block that occupies multiple lines, if its font size and weight are different from the majority of font sizes and weights in the document, it means that the current initial text block may be a long title. In this case, the initial text block can be used as a text block of the object to be detected. It should also be understood that in some cases, the font size and weight of the title may be the same as the font size and weight of most fonts in the document, but there is no preset symbol such as a period, exclamation mark, question mark, ellipsis, etc. at the end. In this case, the initial text block should also be used as a text block of the object to be detected.
[0125] It is worth noting that the length of the initial text block can also be judged. If the length of the initial text block is greater than a certain threshold and the number of lines occupies multiple lines, it can also be determined that the initial text block is a non-title content and the initial text block is deleted.
[0126] In an embodiment of the present application, by filtering the initial text blocks of non-titles that simultaneously meet the above conditions, the recognition accuracy of titles can be effectively improved when identifying documents with complex title hierarchies and long titles.
[0127] The following is a further description of generating an initial text tree based on multiple text blocks and text block information of each text block. Fig.10 As shown, the above step S102 includes:
[0128] S1001. Sort multiple text blocks according to their position sequence in the object to be detected, and use the first text block after sorting as an initial node of an initial text tree.
[0129] S1002, adding the initial node to the initial text tree.
[0130] S1003, traversing the text block information of each text block that has not been added to the initial text tree, and determining whether there is a text block to be selected that has the same font and font size as the initial node.
[0131] The font and font size are the same as those of the initial node, which may be the same font, font size, and font weight as those of the initial node, indicating that the selected text block and the initial node may be titles of the same level.
[0132] S1004: If yes, each of the to-be-selected text blocks is used as a sibling node of the initial node, and multiple new initial nodes are determined according to the positional relationship between the initial node and the sibling nodes, and the sibling nodes are used as new initial nodes.
[0133] The subheading of the text block represented by the initial node is generally located between the text block of the initial node and the text block of the next adjacent sibling node in the document. Therefore, in the first implementation method, the text blocks between the initial node and the adjacent sibling nodes in the document can be traversed to determine all the child nodes of the initial node and use the child nodes as the new initial node.
[0134] In the second implementation method, the text block after the initial node can also be traversed. After obtaining the first child node, the child node is used as the new initial node, and all text blocks after the initial node are traversed to obtain the sibling nodes of the new initial node, and the sibling nodes of the new initial node are used as the new initial node.
[0135] S1005: If not, determine a plurality of new initial nodes according to the positions corresponding to the initial nodes in the object to be detected.
[0136] If the initial node has no title of the same level in the object to be detected, the text blocks after the text block represented by the initial node in the object to be detected can be traversed, and the text block with a font size one level smaller than that of the initial node can be used as the new initial node.
[0137] S1002 - S1005 are executed cyclically until all text blocks in the object to be detected are added to the initial text tree.
[0138] After determining the sibling nodes of the initial node, the sibling nodes can be used as the initial nodes, and the child nodes of the next level can be determined for each sibling node. At the same time, the child nodes of the initial node can be determined, and the child nodes of the initial node can be used as new initial nodes, and the sibling nodes of the new initial nodes and the child nodes of each new initial node can be determined continuously until all text blocks are added as nodes to the initial text tree.
[0139] Furthermore, in the above step S1004, the process of determining a plurality of new initial nodes according to the positional relationship between the initial node and the sibling nodes includes:
[0140] According to the position order of the initial node and the sibling nodes in the object to be detected, the text blocks after the text block of the initial node and before the text block of the sibling nodes are traversed.
[0141] If the font size of the current text block traversed is one level smaller than the font size of the text block of the initial node, the current text block is used as a child node of the initial node, and the child node is used as a new initial node.
[0142] The sibling node may be the next adjacent sibling node of the initial node. The position order of the initial node and the sibling node in the object to be detected refers to the position order of the text block represented by the initial node in the object to be detected and the position order of the text block represented by the sibling node in the object to be detected.
[0143] Exemplarily, if the initial node is node 1 and the sibling node is node 2, the text block between "Title 1" and "Title 2" in the object to be detected can be traversed. If the font size of the currently traversed text block is one level smaller than the font size of the text block of "Title 1", for example, the font size of "Title 1" is size 1 and the font size of "Title 1.1" is size 1 smaller, then "Title 1.1" can be used as a subtitle of "Title 1", "Node 1.1" representing "Title 1.1" can be used as a child node of Node 1, and "Node 1.1" can be used as a new initial node.
[0144] The following is a further description of determining a plurality of new initial nodes according to the positions corresponding to the initial nodes in the object to be detected in the above step S1005, specifically including:
[0145] According to the position order of the initial node in the object to be detected, the text blocks after the text block of the initial node are traversed.
[0146] If the font size of the current text block traversed is one level smaller than the font size of the text block of the initial node, the current text block is used as a child node of the initial node, and the child node is used as a new initial node.
[0147] The position sequence of the initial nodes in the object to be detected refers to the position sequence of the text blocks represented by the initial nodes in the object to be detected.
[0148] In the embodiment of the present application, all text blocks after the text block of the initial node can be traversed, and all text blocks with a font size one level smaller than that of the text block of the initial node can be used as child nodes of the initial node. Alternatively, when the first text block with a font size one level smaller than that of the text block of the initial node is traversed, the current text block traversed can be used as a child node of the initial node, and then the text blocks after the child node are traversed to determine the text blocks with the same font size and font as the text block of the child node as the sibling nodes of the child node.
[0149] The following is a further explanation of how to modify the initial text tree according to the predicted labels of each node to obtain the target text tree of the object to be detected. Fig.11 As shown, the above step S104 includes:
[0150] S1101, traverse each node in the initial text tree and the predicted label of each node, if the predicted label indicates that the current node is non-title content, delete the current node.
[0151] The non-title content can be ordinary text content. The directory recognition model can recognize the text content in the object to be detected, obtain the non-title content, and add a prediction label. If the predicted label indicates that the text block represented by the node is non-title content, the current node in the initial text tree can be deleted.
[0152] S1102: If the predicted label indicates that the current node is a lower level title of an adjacent sibling node of the current node, the current node is modified to be a child node of the adjacent sibling node of the current node.
[0153] The predicted label indicates the hierarchical relationship between the current node and the previous adjacent sibling node of the current node. According to the structure of the initial text tree, the hierarchical relationship between the current node and the adjacent sibling node should be the same-level title. Therefore, if the predicted label indicates that the current node is the next-level title of the adjacent sibling node of the current node, it means that there is an error in the position of the current node in the initial text tree, and the current node needs to be made a child node of the adjacent sibling node.
[0154] S1103: After completing the correction of all nodes, the corrected initial text tree is used as the target text tree.
[0155] After all nodes in the initial text tree are corrected, the final initial text tree can represent the correct hierarchical relationship of all titles in the object to be detected, so the corrected initial text tree can be used as the target text tree.
[0156] Based on the same inventive concept, the embodiment of the present application also provides a directory generation device corresponding to the directory generation method. Since the principle of solving the problem by the device in the embodiment of the present application is similar to the above-mentioned directory generation method in the embodiment of the present application, the implementation of the device can refer to the implementation of the method, and the repeated parts will not be repeated. The directory generation device includes a detection module, a generation module, a prediction module and a correction module.
[0157] A detection module, used for performing detection processing on the object to be detected, and obtaining multiple text blocks of the object to be detected and text block information of each text block;
[0158] A generating module, used for generating an initial text tree according to the plurality of text blocks and the text block information of each text block, wherein the initial text tree includes a plurality of nodes, each node corresponds to a text block, and the initial text tree is used for representing the hierarchical relationship between the nodes;
[0159] A prediction module is used to input the initial text tree into a pre-trained directory recognition model, which extracts the global features and local features of each node and determines the predicted label of each node based on the global features and local features of each node. The predicted label is used to characterize the hierarchical relationship between the node and its adjacent sibling nodes.
[0160] The correction module is used to correct the initial text tree according to the predicted label of each node to obtain the target text tree of the object to be detected, and obtain the directory generation result of the object to be detected according to the target text tree and the text blocks corresponding to each node in the target text tree.
[0161] Optionally, the catalog recognition model includes: a first encoder, a second encoder, a fusion module, and a prediction module;
[0162] The detection module is specifically used for:
[0163] Perform a breadth-first search on the initial text tree to determine the adjacent sibling nodes of the current node, and use the current node and the adjacent sibling nodes of the current node as a node combination, where the current node is any node of the initial text tree;
[0164] The first encoder encodes the text block and text block information of each node in the node combination to obtain the local features of the current node, and sends the local features to the fusion module;
[0165] Construct a subtree of the current node based on the initial text tree. The subtree is used to describe the hierarchical relationship between the current node and the nodes related to the current node.
[0166] The second encoder determines the global feature of the current node according to the subtree of the current node, and sends the global feature to the fusion module.
[0167] Optionally, the subtree includes: the current node, the parent node, the sibling nodes, and the child nodes of the current node;
[0168] The prediction module is specifically used for:
[0169] The second encoder determines the relationship information of the current node according to the subtree of the current node, the relationship information including: the relationship type between each node in the subtree and the current node, the font difference information and the position difference information between each node in the subtree;
[0170] The second encoder encodes the subtree of the current node, the text block of the current node, and the relationship information of the current node to obtain the global feature of the current node.
[0171] The prediction module is specifically used for:
[0172] The fusion module performs splicing processing on the global features and local features of the current node based on the preset learning parameters to obtain the node features of the current node, and sends the node features to the prediction module;
[0173] The prediction module predicts the node features, obtains and outputs the predicted label of the current node.
[0174] The detection module is specifically used for:
[0175] Performing detection processing on the object to be detected to obtain at least one initial text line;
[0176] Parsing each initial text line to obtain text line information of the initial text line, the text line information including: the position of the text line, the color of the text in the text line, the font size and font of the text in the text line;
[0177] Performing clustering processing on each initial text line to obtain at least one initial text block, and merging text line information of each initial text line contained in each initial text block to obtain text block information of each initial text block, wherein the text block information includes: a position of the text block, a color of text in the text block, and a font and font size of text in the text block;
[0178] Each initial text block is filtered according to the text block information to obtain the text block of the object to be detected and the text block information of the text block.
[0179] The detection module is specifically used for:
[0180] Determine the text font information in the object to be detected, the text font information including: the maximum font size and the maximum font size of the non-title text in the object to be detected;
[0181] Traverse each initial text block. If the text block information of the initial text block indicates that the number of lines of the initial text block is greater than the preset line number threshold, and the font and font size in the initial text block are the same as the text font information, and the last punctuation mark of the initial text block is a preset symbol, then the initial text block is not used as a text block of the object to be detected. Otherwise, the initial text block is used as a text block of the object to be detected.
[0182] The generation module is specifically used for:
[0183] A. Sort the multiple text blocks according to their position order in the object to be detected, and use the first text block after sorting as the initial node of the initial text tree;
[0184] B. Add the initial node to the initial text tree;
[0185] C. Traverse the text block information of each text block that has not been added to the initial text tree to determine whether there is a text block to be selected that has the same font and font size as the initial node;
[0186] D. If yes, then each of the to-be-selected text blocks is used as a sibling node of the initial node, and multiple new initial nodes are determined according to the positional relationship between the initial node and the sibling nodes, and the sibling nodes are used as new initial nodes;
[0187] E. If not, determine multiple new initial nodes according to the corresponding positions of the initial nodes in the object to be detected;
[0188] BE is executed repeatedly until all text blocks in the object to be detected are added to the initial text tree.
[0189] The generation module is specifically used for:
[0190] According to the position order of the initial node and the sibling nodes in the object to be detected, traverse the text blocks after the text block of the initial node and before the text block of the sibling nodes;
[0191] If the font size of the current text block traversed is one level smaller than the font size of the text block of the initial node, the current text block is used as a child node of the initial node, and the child node is used as a new initial node.
[0192] The generation module is specifically used for:
[0193] According to the position order of the initial node in the object to be detected, traverse the text blocks after the text block of the initial node;
[0194] If the font size of the current text block traversed is one level smaller than the font size of the text block of the initial node, the current text block is used as a child node of the initial node, and the child node is used as a new initial node.
[0195] The correction module is specifically used for:
[0196] Traverse each node in the initial text tree and the predicted label of each node. If the predicted label indicates that the current node is non-title content, delete the current node;
[0197] If the predicted label indicates that the current node is the next level title of the adjacent sibling node of the current node, the current node is modified to be a child node of the adjacent sibling node of the current node;
[0198] After completing the correction of all nodes, the corrected initial text tree is used as the target text tree.
[0199] The embodiment of the present application builds an initial text tree for the text block of the object to be detected, and the hierarchical relationship between the text blocks can be more clearly characterized by the structure of the initial text tree. For documents with complex hierarchical relationships of titles, the complexity of identifying deep-level titles can be reduced. By extracting local features from each node in the initial text tree, the hierarchical relationship between the title and the adjacent title can be obtained, thereby improving the accuracy of directory recognition. And the application further proposes to extract the global features of the current node based on the initial text tree, and the overall relationship between the current title in the entire document and other titles can be characterized by the global features, thereby improving the correlation between the hierarchical titles across multiple pages, and improving the accuracy of recognition for the title hierarchy at a distance. In addition, in the present application, not only the text content of the text block itself is considered, but also the text block information is further considered, so that the difference between the title and the text and the different title levels can be more easily captured based on the text block information, so that the directory recognition model can learn the differentiated features with more distinguishing degree, and then improve the accuracy of recognition of the directory recognition model.
[0200] Fig.12A schematic diagram of the structure of an electronic device 120 provided in an embodiment of the present application is shown, comprising: a processor 1201, a storage medium 1202 and a bus 1203, wherein the storage medium 1202 stores machine-readable instructions executable by the processor 1201, and when the electronic device runs the directory generation method in the embodiment, the processor 1201 communicates with the storage medium 1202 via the bus 1203, and the processor 1201 executes the machine-readable instructions, and the processor 1201 executes the preamble of the method item to execute the steps in the directory generation method.
[0201] An embodiment of the present application further provides a computer-readable storage medium, on which a computer program is stored. The computer program is executed when a processor is running, and the processor executes the steps in the directory generation method.
[0202] In the embodiment of the present application, the computer program can also execute other machine-readable instructions when run by the processor to execute other methods described in the embodiment. For the specific execution method steps and principles, please refer to the description of the embodiment, which will not be repeated here.
[0203] An embodiment of the present application also provides a computer program product, which includes computer program code. When the computer program code is executed by a computing device, the computing device executes the steps in the directory generation method.
[0204] In the embodiments provided in the present application, it should be understood that the disclosed devices and methods can be implemented in other ways. The device embodiments described above are merely schematic. For example, the division of the units is only a logical function division. There may be other division methods in actual implementation. For example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some communication interfaces, and the indirect coupling or communication connection of the devices or units can be electrical, mechanical or other forms.
[0205] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0206] In addition, each functional unit in the embodiments provided in the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit.
[0207] If the functions are implemented in the form of software functional units and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present application, or the part that contributes to the prior art or the part of the technical solution, can be embodied in the form of a software product. The computer software product is stored in a storage medium, including several instructions to enable a computer device (which can be a personal computer, server, or network device, etc.) to execute all or part of the steps of the method described in each embodiment of the present application. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), disk or optical disk, and other media that can store program codes.
[0208] It should be noted that similar numbers and letters represent similar items in the following figures. Therefore, once an item is defined in one figure, it does not need to be further defined and explained in subsequent figures. In addition, the terms "first", "second", "third", etc. are only used to distinguish the description and are not to be understood as indicating or implying relative importance.
[0209] Finally, it should be noted that the above-described embodiments are only specific implementation methods of the present application, which are used to illustrate the technical solutions of the present application, rather than to limit them. The protection scope of the present application is not limited thereto. Although the present application is described in detail with reference to the above-mentioned embodiments, ordinary technicians in the field should understand that any technician familiar with the technical field can still modify the technical solutions recorded in the above-mentioned embodiments within the technical scope disclosed in the present application, or can easily think of changes, or make equivalent replacements for some of the technical features therein; and these modifications, changes or replacements do not make the essence of the corresponding technical solutions deviate from the spirit and scope of the technical solutions of the embodiments of the present application. They should all be included in the protection scope of the present application. Therefore, the protection scope of the present application shall be based on the protection scope of the claims.
Claims
1. A method for generating a directory, characterized in that: include: Performing detection processing on the object to be detected to obtain multiple text blocks of the object to be detected and text block information of each of the text blocks; Generate an initial text tree according to the multiple text blocks and the text block information of each of the text blocks, wherein the initial text tree includes multiple nodes, each of the nodes corresponds to a text block, and the initial text tree is used to represent the hierarchical relationship between the nodes; Inputting the initial text tree into a pre-trained directory recognition model, the directory recognition model extracts global features and local features of each node, and based on the global features and local features of each node, determines a predicted label of each node, wherein the predicted label is used to characterize the hierarchical relationship between the node and its adjacent sibling nodes; The initial text tree is modified according to the predicted labels of each node to obtain the target text tree of the object to be detected, and the directory generation result of the object to be detected is obtained according to the target text tree and the text blocks corresponding to each node in the target text tree.
2. The method according to claim 1, characterized in that: The catalog recognition model includes: a first encoder, a second encoder, a fusion module and a prediction module; The step of predicting each node in the initial text tree to obtain global features and local features of each node includes: Performing a breadth-first search on the initial text tree to determine adjacent sibling nodes of a current node, and taking the current node and the adjacent sibling nodes of the current node as a node combination, wherein the current node is any node of the initial text tree; The first encoder encodes the text block and text block information of each node in the node combination to obtain the local feature of the current node, and sends the local feature to the fusion module; Constructing a subtree of the current node according to the initial text tree, wherein the subtree is used to describe the hierarchical relationship between the current node and nodes related to the current node; The second encoder determines the global feature of the current node according to the subtree of the current node, and sends the global feature to the fusion module.
3. The method according to claim 2, characterized in that The subtree includes: the current node, the parent node, the brother node and the child node of the current node; The determining, by the second encoder, the global feature of the current node according to the subtree of the current node includes: The second encoder determines the relationship information of the current node according to the subtree of the current node, wherein the relationship information includes: the relationship type between each node in the subtree and the current node, and the font difference information and position difference information between each node in the subtree; The second encoder encodes the subtree of the current node, the text block of the current node, and the relationship information of the current node to obtain the global features of the current node.
4. The method according to claim 2, characterized in that: The step of determining the predicted label of each node based on the global features and the local features of each node includes: The fusion module performs splicing processing on the global features and local features of the current node based on preset learning parameters to obtain the node features of the current node, and sends the node features to the prediction module; The prediction module predicts the node features to obtain and output a predicted label of the current node.
5. The method according to claim 1, characterized in that The detecting process of the object to be detected is performed to obtain a plurality of text blocks of the object to be detected and text block information of each of the text blocks, including: Performing detection processing on the object to be detected to obtain at least one initial text line; Parsing each of the initial text lines to obtain text line information of the initial text line, the text line information including: the position of the text line, the color of the text in the text line, the size and font of the text in the text line; Performing clustering processing on each of the initial text lines to obtain at least one initial text block, and merging text line information of each initial text line contained in each initial text block to obtain text block information of each initial text block, wherein the text block information includes: the position of the text block, the color of the text in the text block, and the font and font size of the text in the text block; The initial text blocks are filtered according to the text block information to obtain the text block of the object to be detected and the text block information of the text block.
6. The method according to claim 5, characterized in that The filtering process of each of the initial text blocks according to the text block information to obtain the text block of the object to be detected and the text block information of the text block includes: Determine the text font information in the object to be detected, the text font information including: the maximum font size and the maximum font size of the non-title text in the object to be detected; Traverse each of the initial text blocks, if the text block information of the initial text block indicates that the number of lines of the initial text block is greater than a preset line number threshold, and the font and font size in the initial text block are the same as the text font information, and the last punctuation mark of the initial text block is a preset symbol, then the initial text block is not used as the text block of the object to be detected, otherwise, the initial text block is used as a text block of the object to be detected.
7. The method according to claim 1, characterized in that The step of generating an initial text tree according to the plurality of text blocks and the text block information of each of the text blocks comprises: A. sorting the multiple text blocks according to the position order of the multiple text blocks in the object to be detected, and taking the first text block after sorting as the initial node of the initial text tree; B. adding the initial node to the initial text tree; C. traversing the text block information of each text block that is not added to the initial text tree, and determining whether there is a text block to be selected that has the same font and font size as the initial node; D. If yes, each of the to-be-selected text blocks is used as a sibling node of the initial node, and multiple new initial nodes are determined according to the positional relationship between the initial node and the sibling nodes, and the sibling nodes are used as new initial nodes; E. If not, determining a plurality of new initial nodes according to the positions corresponding to the initial nodes in the object to be detected; BE is executed cyclically until all text blocks in the object to be detected are added to the initial text tree.
8. The method according to claim 7, characterized in that The determining of a plurality of new initial nodes according to the positional relationship between the initial node and the brother nodes comprises: According to the position order of the initial node and the sibling node in the object to be detected, traverse the text blocks after the text block of the initial node and before the text block of the sibling node; If the font size of the current text block traversed is one level smaller than the font size of the text block of the initial node, the current text block is used as a child node of the initial node, and the child node is used as a new initial node.
9. The method according to claim 7, characterized in that: The step of determining a plurality of new initial nodes according to the positions corresponding to the initial nodes in the object to be detected includes: According to the position order of the initial node in the object to be detected, traverse the text blocks after the text block of the initial node; If the font size of the current text block traversed is one level smaller than the font size of the text block of the initial node, the current text block is used as a child node of the initial node, and the child node is used as a new initial node.
10. The method according to claim 1, characterized in that The step of modifying the initial text tree according to the predicted labels of each node to obtain the target text tree of the object to be detected includes: Traversing each node in the initial text tree and the predicted label of each node, if the predicted label indicates that the current node is non-title content, deleting the current node; If the predicted tag indicates that the current node is a lower level title of an adjacent sibling node of the current node, modifying the current node to be a child node of the adjacent sibling node of the current node; After completing the modification of all nodes, the modified initial text tree is used as the target text tree.
11. An electronic device, characterized in that: include: A processor, a storage medium and a bus, wherein the storage medium stores machine-readable instructions executable by the processor, and when the electronic device is running, the processor and the storage medium communicate via the bus, and the processor executes the machine-readable instructions to perform the steps of the directory generation method as described in any one of claims 1 to 10.
12. A computer program product, characterized in that The computer program product comprises a computer program code. When the computer program code is executed by a computing device, the computing device performs the catalog generation method according to any one of claims 1 to 10.
Citation Information
Patent Citations
Financial certificate information input processing method, device, equipment, medium and product
CN116863486A
Document processing method and device, storage medium, terminal and computer program product
CN118313352A