Method and device for determining title level
By obtaining known and unknown title sets, creating and updating title feature templates, and calculating the matching degree to determine the title level, the problem of confusing title levels in documents is solved, and accurate and rapid identification of document structure is achieved.
Patent Information
- Application Number
- CN202410342735.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-03-25
- Publication Date
- 2025-09-26
AI Technical Summary
Many documents have confusing heading levels, making it difficult to determine the structure of the document's content.
By obtaining the known title set and unknown title set of the target document, multiple title feature templates are created, the templates are updated according to the features of the known titles, and the matching degree between the unknown title and the template is calculated to determine the level of the unknown title.
Accurately and quickly identify the title hierarchy of each title in the document, improving the accuracy and reliability of document structuring.
Smart Images

Figure CN120706390A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of document processing, and in particular to a method and device for determining title levels. Background Art
[0002] Whether it's a flow document or a layout document, its structure includes the concept of a title. However, many documents are not created according to a standard structure, resulting in a chaotic level of title, making it difficult to determine the structure of the document content. Therefore, an effective solution is urgently needed to solve this problem. Summary of the Invention
[0003] In view of the problems existing in the prior art, embodiments of the present invention provide a method and apparatus for determining a title level.
[0004] The present invention provides a method for determining a title level, comprising:
[0005] Acquire a known title set and an unknown title set of a target document, and create a plurality of title feature templates, wherein the known title set includes at least one known title of a known title level, and the unknown title set includes at least one unknown title of a title level to be identified, and each of the title feature templates corresponds to a title level;
[0006] updating each of the title feature templates according to the title feature of each of the known titles in the known title set;
[0007] For each unknown title in the unknown title set, the matching degree between the title feature of the unknown title and each updated title feature template is calculated, and the title level of the unknown title is determined according to each matching degree.
[0008] According to a method for determining a title level provided by the present invention, before updating each title feature template based on the title features of each known title in the known title set, the method further includes:
[0009] The following steps are performed for each designated title, where the designated title is the known title or the unknown title:
[0010] The average font size, alignment, and indent value of the designated title are obtained, and the average font size, alignment, and indent value are determined as title features of the designated title.
[0011] According to a method for determining a title level provided by the present invention, obtaining the average font size, alignment, and indentation value of the specified title includes:
[0012] Get the font size of each element in the specified title;
[0013] Determining an average font size of the designated title based on the font sizes;
[0014] Obtain a first bounding rectangular frame of the designated title and a second bounding rectangular frame of the text area where the designated title is located;
[0015] An alignment mode and an indentation value of the designated title are determined according to the first circumscribed rectangular frame and the second circumscribed rectangular frame.
[0016] According to a method for determining a title level provided by the present invention, determining the alignment and indentation value of the designated title based on the first circumscribed rectangular frame and the second circumscribed rectangular frame includes:
[0017] Calculating a left distance between a left border of the first circumscribed rectangular frame and a left border of the second circumscribed rectangular frame, and calculating a right distance between a right border of the first circumscribed rectangular frame and a right border of the second circumscribed rectangular frame;
[0018] Determine the larger and smaller distances between the left and right distances, and obtain the width and height of the first circumscribed rectangular frame;
[0019] If the first condition is met, determining that the alignment of the designated title is justified, and determining that the indent value of the designated title is left spacing, the first condition is that the larger spacing is less than a first product, and the first product is the product of the height and the first value;
[0020] If the second condition is met, determining that the alignment of the designated title is centered, and determining that the indent value of the designated title is left spacing, the second condition is that the larger spacing is smaller than the second product, and the smaller spacing is larger than a third product, the second product is the product of the smaller spacing and a second value, the third product is the product of the height and a third value, the third value is larger than the second value, and the second value is larger than the first value;
[0021] If a third condition is met, determining that the alignment of the designated title is right-aligned, and determining that the indentation value of the designated title is right spacing, the third condition being that the left spacing is greater than the right spacing, and the left spacing is greater than a fourth product, the fourth product being the product of the height and a fourth value, and the fourth value being greater than the second value;
[0022] If the first condition, the second condition, and the third condition are all not satisfied, the alignment of the designated title is determined to be left alignment, and the indent value of the designated title is determined to be left spacing.
[0023] According to a method for determining a title level provided by the present invention, updating each title feature template according to the title features of each known title in the known title set includes:
[0024] Starting from the first known title in the known title set, the features in the set feature template are updated to the average font size, alignment and indentation value of the known titles, and the set feature template is the title feature template corresponding to the title level of the known titles, until the last known title.
[0025] According to a method for determining a title level provided by the present invention, the method further includes:
[0026] For the designated feature template that has not been updated, searching for a first feature template and a second feature template from each of the updated title feature templates, wherein the first title level of the first feature template is higher than the designated title level, and the second title level of the second feature template is lower than the designated title level, and the designated title level is the title level of the designated feature template;
[0027] performing linear interpolation calculation based on the average font size in the first feature template, the average font size in the second feature template, and the level interval to obtain the average font size corresponding to the specified heading level, wherein the level interval is the difference between the second heading level and the first heading level;
[0028] The features in the specified feature template are updated to the average font size corresponding to the specified heading level.
[0029] According to a method for determining a title level provided by the present invention, before updating the features in the specified feature template to the average font size corresponding to the specified title level, the method further includes:
[0030] If the first feature template is not found and the second feature template is found, performing linear interpolation calculation based on the first set font size, the average font size in the second feature template, and the second heading level to obtain the average font size corresponding to the specified heading level;
[0031] If the second feature template is not found and the first feature template is found, performing linear interpolation calculation based on the average font size in the second feature template, the second set font size, and the specified heading level to obtain the average font size corresponding to the specified heading level, wherein the first set font size is larger than the second set font size;
[0032] In the case where the first characteristic template and the second characteristic template are not searched, a linear interpolation calculation is performed according to the first set font size, the second set font size and a preset number to obtain an average font size corresponding to the specified title level.
[0033] According to a method for determining a heading level provided by the present invention, the heading features include average font size, alignment, and indentation value;
[0034] The calculating the matching degree between the title features of the unknown title and each of the updated title feature templates includes:
[0035] For each of the said title feature templates that have been updated, do the following:
[0036] If the features in the title feature template include average font size, alignment, and indentation value, determining a font size score based on the average font size of the unknown title and the average font size in the title feature template; determining a format score based on the alignment and indentation value of the unknown title and the alignment and indentation value in the title feature template;
[0037] If the feature in the title feature template only includes the average font size, determining a font size score based on the average font size of the unknown title and the average font size in the title feature template; and determining the first set score as the format score;
[0038] The degree of matching between the title feature of the unknown title and the title feature template is determined according to the font size score and the format score.
[0039] According to a method for determining a title level provided by the present invention, determining a font size score based on the average font size of the unknown title and the average font size in the title feature template includes:
[0040] Calculating a first absolute value of a difference between a first average font size and a second average font size, wherein the first average font size is the average font size of the unknown title and the second average font size is the average font size in the title feature template;
[0041] The first absolute value is input into a formula for setting a font size score to obtain a font size score.
[0042] According to a method for determining a title level provided by the present invention, determining a format score based on the alignment and indentation value of the unknown title and the alignment and indentation value in the title feature template includes:
[0043] If a fourth condition is satisfied, determining the second set score as the format score, the second set score is greater than the first set score, and the fourth condition is that the alignment of the unknown title is justified or centered, and the alignment in the title feature template is justified or centered;
[0044] If a fifth condition is satisfied, determining the third set score as the format score, the third set score is less than the first set score, and the fifth condition is that the alignment of the unknown title is different from the alignment in the title feature template, and both the alignment of the unknown title and the alignment in the title feature template are not justified;
[0045] If the fourth condition is not met and the fifth condition is not met, calculate the second absolute value of the difference between the first indent value and the second indent value, the first indent value is the indent value of the unknown title, and the second indent value is the indent value in the title feature template; input the second absolute value into the set format score formula to obtain the format score.
[0046] According to a method for determining a title level provided by the present invention, determining the title level of the unknown title according to each matching degree includes:
[0047] The title level of the target feature template is determined to be the title level of the unknown title, and the target feature template is the title feature template corresponding to the highest matching degree among the matching degrees.
[0048] According to a method for determining a title level provided by the present invention, after determining the title level of the unknown title according to each matching degree, the method further includes:
[0049] updating the target feature template according to the title feature of the unknown title;
[0050] Deleting the unknown title from the unknown title set;
[0051] Continue to determine the title level of the next unknown title in the unknown title set.
[0052] The present invention also provides a device for determining a title level, comprising:
[0053] A first acquisition module is configured to acquire a known title set and an unknown title set of a target document and create a plurality of title feature templates, wherein the known title set includes at least one known title of a known title level, and the unknown title set includes at least one unknown title of a title level to be identified, and each of the title feature templates corresponds to a title level;
[0054] A first updating module is configured to update each of the title feature templates according to the title feature of each of the known titles in the known title set;
[0055] The calculation module is configured to calculate the matching degree between the title features of each unknown title in the unknown title set and the updated title feature templates, and determine the title level of the unknown title based on each matching degree.
[0056] The present invention also provides an electronic device comprising a memory, a processor and a computer program stored in the memory and executable on the processor, wherein when the processor executes the program, the method for determining the title level as described above is implemented.
[0057] The present invention also provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements any of the above methods for determining title levels.
[0058] The present invention also provides a computer program product, comprising a computer program, which implements any of the above methods for determining title levels when executed by a processor.
[0059] The method and device for determining title levels provided by the present invention obtain a known title set and an unknown title set of a target document and create multiple title feature templates, wherein the known title set includes at least one known title of a known title level, and the unknown title set contains at least one unknown title of a title level to be identified, and each of the title feature templates corresponds to a title level; each of the title feature templates is updated according to the title features of each of the known titles in the known title set; for each of the unknown titles in the unknown title set, the matching degree between the title features of the unknown title and each of the updated title feature templates is calculated, and the title level of the unknown title is determined according to each matching degree, so that the title level of each title in the document can be accurately and quickly identified. BRIEF DESCRIPTION OF THE DRAWINGS
[0060] In order to more clearly illustrate the technical solutions in the present invention or the prior art, a brief introduction will be given below to the drawings required for use in the embodiments or the description of the prior art. Obviously, the drawings described below are some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.
[0061] Figure 1 It is a flowchart of the method for determining the title level provided by the present invention;
[0062] Figure 2 It is a structural diagram of the device for determining title level provided by the present invention;
[0063] Figure 3 It is a structural schematic diagram of the electronic device provided by the present invention. DETAILED DESCRIPTION
[0064] To make the objectives, technical solutions, and advantages of the present invention more clear, the technical solutions of the present invention will be clearly and completely described below in conjunction with the accompanying drawings. Obviously, the embodiments described are only some of the embodiments of the present invention, not all of them. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without making creative efforts shall fall within the scope of protection of the present invention.
[0065] In order to facilitate a clearer understanding of the embodiments of the present invention, some relevant knowledge is first introduced as follows.
[0066] A title is a short phrase that summarizes your content and grabs your reader's attention.
[0067] Structuring: This refers to organizing and categorizing the headings in a document to make it more hierarchical and readable. This structuring can be achieved by using different levels of headings, subheadings, and tags to create clear sections and chapters in the document. This helps readers more easily navigate and understand the content of the document.
[0068] Unicode is a character encoding standard used to represent characters, symbols, and punctuation marks in various languages. It provides consistent encoding for all texts worldwide to resolve confusion and compatibility issues caused by different character sets and encoding schemes.
[0069] A font is the visual representation of a set of characters, including their appearance, style, and arrangement. There are many font properties that can be adjusted and configured, including but not limited to: font family, font style, font size, and font weight.
[0070] A font family is a category or classification of fonts, such as Songti, Arial, and Times New Roman. Font styles include Regular, Italic, and Bold. Font size determines the display size of characters. Font weight specifies the thickness of characters.
[0071] TextObject is a basic element in a document and belongs to the text type element. It contains information such as Unicode (Unicode), CharCode (character code), Font, and BBox (bounding rectangle).
[0072] In the prior art, the title level or title hierarchy is usually determined based on numerical symbols in the title text content, and the title level cannot be identified for titles without numerical symbols.
[0073] The following combination Figure 1-Figure 3 The method and apparatus for determining title levels of the present invention are described.
[0074] Figure 1 This is a flow chart of the method for determining the title level provided by the present invention, see Figure 1 As shown, it includes steps 101 to 103, wherein:
[0075] Step 101: Obtain a known title set and an unknown title set of a target document, and create multiple title feature templates, wherein the known title set includes at least one known title of a known title level, and the unknown title set includes at least one unknown title of a title level to be identified, and each of the title feature templates corresponds to a title level.
[0076] First, it should be noted that the present invention can be implemented by any electronic device capable of determining heading levels, such as a smartphone, smartwatch, desktop computer, laptop, or the like. Furthermore, the heading level determination method provided by the present invention can be used in scenarios such as document conversion, document reformatting, document content retrieval, document structure tree generation, document directory generation, and document bookmark generation.
[0077] Specifically, the target document refers to the document whose title needs to be identified. It can be a layout document, such as a PDF document, an OFD (Open Fixed-layout Document) document, a streaming document, such as a Word document, a TXT document, a presentation document, such as a slide document, or a picture document. The present invention does not impose any restrictions on this.
[0078] A heading level refers to the rank of a heading, such as a first-level heading (e.g., 1. Courses), a second-level heading (e.g., 1.2 Chinese), or a third-level heading (e.g., 1.2.3 Classical Poetry). A first-level heading is higher than a second-level heading, which is higher than a third-level heading, and so on. A known heading is one with a known heading level, i.e., one included in the target document's title information. An unknown heading is one with an uncertain or unknown heading level.
[0079] In practical applications, before determining the area to be identified in the target document, the target document must be acquired first. There are many methods for acquiring the target document, which are not limited in the present invention.
[0080] Exemplarily, a user uploads a target document through a document upload page, and accordingly, the execution entity obtains the target document.
[0081] Exemplarily, the execution subject receives a document acquisition instruction or a title identification instruction, and accordingly, the execution subject acquires the target document from the storage area pointed to by the document acquisition instruction or the title identification instruction.
[0082] On the basis of obtaining the target document, further, the known title set and unknown title set of the target document are obtained: the target document itself has title information, the known titles in the title information are taken out and stored in the title set HeadingGTSet, that is, the known title set; and the titles other than the known titles in the target document are identified, that is, the unknown titles at the title level to be identified, and the unknown titles are stored in the title set HeadingDetSet, that is, the unknown title set.
[0083] For example, when it is necessary to expand the title: if there is title information in the document itself, the known titles in the title information are taken out and stored in the known title set, and the unknown titles in the document are identified and stored in the unknown title set; if there is no title information in the document, the known title set is empty, and all the titles in the identified document are regarded as unknown titles and stored in the unknown title set.
[0084] For example, when it is necessary to automatically determine and repair the hierarchical structure relationship of the original titles in the document: all titles in the document that can be directly identified as unknown titles are stored in the unknown title set, and the known title set is empty at this time; if there is title information in the document itself, the known titles in the title information are taken out and stored in the known title set, and all titles in the document are identified as unknown titles, and all titles in the known title set are stored in the unknown title set, and the known title set is cleared.
[0085] Title information refers to the information in the target document that has been marked with a title. For example, in a Word document, if an outline is set, the corresponding text is the title; in a PDF document, if the text content has the tag Heading, the corresponding content is the title.
[0086] In addition, it is also necessary to create multiple title feature templates, such as creating a preset number of title feature templates, each title feature template corresponding to a title level. For example, the preset number is 6, and title feature templates are created for the first to sixth level titles respectively.
[0087] For example, the maximum number of heading levels is set to MaxLevel = 6, i.e., the preset number is 6, and a heading feature template Template is created. Template[i] represents the feature when the heading level is i; MaxLevel = 6, i.e., the current document is allowed to have 6 different heading levels, i.e., Heading1 to Heading6.
[0088] The preset number can be specified. If you only want to have a maximum of 3 levels of titles, then MaxLevel = 3. In addition, the features in the created title feature template can be empty.
[0089] Step 102: Update each of the title feature templates according to the title feature of each of the known titles in the known title set.
[0090] Specifically, the title feature includes at least one of an average font size, font, alignment, indentation value, and sequence number of a known title.
[0091] In practical applications, the title levels of known titles in the target document are fixed, and the title feature templates corresponding to those title levels can be updated based on the title features corresponding to the known titles. Specifically, if there are known titles in the known title set, for each known title, the title feature template corresponding to its title level is updated based on the title features of the known title.
[0092] In addition, when there is no known title in the known title set, linear interpolation calculation can be performed based on the first set font size, the second set font size and the preset number to update each of the title feature templates.
[0093] Step 103: For each unknown title in the unknown title set, calculate the matching degree between the title features of the unknown title and each updated title feature template, and determine the title level of the unknown title based on each matching degree.
[0094] In practical applications, for each unknown title in the unknown title set, the title features of the unknown title can be matched with the updated title feature templates according to the set matching rules, so as to obtain the matching degree between the title features and the title feature templates.
[0095] For each unknown title in the unknown title set, on the basis of obtaining the matching degrees corresponding to the unknown title, further, the highest matching degree is determined from the matching degrees, and then the title feature template corresponding to the highest matching degree is determined as the target feature template, and the title level of the target feature template is determined as the title level of the unknown title.
[0096] In addition, after the title levels of all unknown titles are determined, the unknown titles become known titles, and the title structure tree, directory, bookmarks, etc. of the target document can be constructed based on all known titles.
[0097] The method for determining title levels provided by the present invention obtains a known title set and an unknown title set of a target document and creates multiple title feature templates, wherein the known title set includes at least one known title of a known title level, and the unknown title set includes at least one unknown title of a title level to be identified, and each of the title feature templates corresponds to a title level; according to the title features of each known title in the known title set, each of the title feature templates is updated; for each unknown title in the unknown title set, the matching degree between the title features of the unknown title and each of the updated title feature templates is calculated, and the title level of the unknown title is determined based on each matching degree, so that the title level of each title in the document can be accurately and quickly identified.
[0098] In one or more optional embodiments of the present invention, before updating each of the title feature templates based on the title feature of each of the known titles in the known title set, the method further includes:
[0099] The following steps are performed for each designated title, where the designated title is the known title or the unknown title:
[0100] The average font size, alignment, and indent value of the designated title are obtained, and the average font size, alignment, and indent value are determined as title features of the designated title.
[0101] In practical applications, each title in the known title set and the unknown title set is traversed, that is, each specified title is traversed, and the average font size, alignment and indentation value of each specified title, that is, the title features, are obtained.
[0102] In this way, using the average font size, alignment, and indent value as title features can ensure the accuracy and reliability of title features and further improve the accuracy of title level determination.
[0103] In one or more optional embodiments of the present invention, the obtaining of the average font size, alignment, and indent value of the designated title may be specifically implemented as follows:
[0104] Get the font size of each element in the specified title;
[0105] Determining an average font size of the designated title based on the font sizes;
[0106] Obtain a first bounding rectangular frame of the designated title and a second bounding rectangular frame of the text area where the designated title is located;
[0107] An alignment mode and an indentation value of the designated title are determined according to the first circumscribed rectangular frame and the second circumscribed rectangular frame.
[0108] In practical applications, when determining the average font size, you can specify each text element in the title content, obtain the font size of each text element, and average it to obtain the average font size, which is recorded as FontSize. This can improve the accuracy of the average font size.
[0109] If the target document is a layout document, all TextObjects in the title are traversed to obtain the number of Unicode characters and the corresponding font size in each TextObject, and calculate the average font size.
[0110] When determining the alignment and indent values, the bounding rectangle of the specified title (i.e., the first bounding rectangle, denoted as HeadingBBox) is obtained, and the bounding rectangle of the text area containing the specified title (i.e., the second bounding rectangle, denoted as SectBBox) is obtained. Then, based on the first and second bounding rectangles, the alignment type (alignType) and indent value (ident) of the specified title are determined according to the determination rules. This improves the accuracy of the alignment and indent values.
[0111] In one or more optional embodiments of the present invention, the alignment and indentation value of the designated title are determined based on the first circumscribed rectangular frame and the second circumscribed rectangular frame. The specific implementation process may be as follows:
[0112] Calculating a left distance between a left border of the first circumscribed rectangular frame and a left border of the second circumscribed rectangular frame, and calculating a right distance between a right border of the first circumscribed rectangular frame and a right border of the second circumscribed rectangular frame;
[0113] Determine the larger and smaller distances between the left and right distances, and obtain the width and height of the first circumscribed rectangular frame;
[0114] If the first condition is met, determining that the alignment of the designated title is justified, and determining that the indent value of the designated title is left spacing, the first condition is that the larger spacing is less than a first product, and the first product is the product of the height and the first value;
[0115] If the second condition is met, determining that the alignment of the designated title is centered, and determining that the indent value of the designated title is left spacing, the second condition is that the larger spacing is smaller than the second product, and the smaller spacing is larger than a third product, the second product is the product of the smaller spacing and a second value, the third product is the product of the height and a third value, the third value is larger than the second value, and the second value is larger than the first value;
[0116] If a third condition is met, determining that the alignment of the designated title is right-aligned, and determining that the indentation value of the designated title is right spacing, the third condition being that the left spacing is greater than the right spacing, and the left spacing is greater than a fourth product, the fourth product being the product of the height and a fourth value, and the fourth value being greater than the second value;
[0117] If the first condition, the second condition, and the third condition are all not satisfied, the alignment of the designated title is determined to be left alignment, and the indent value of the designated title is determined to be left spacing.
[0118] In practical applications, the left boundary of the second circumscribed rectangular box, SectBBox.left, is subtracted from the left boundary of the first circumscribed rectangular box, HeadingBBox.left, to obtain the left distance leftDiff, that is, leftDiff = HeadingBBox.left - SectBBox.left.
[0119] Subtract the right boundary of the first circumscribed rectangular box, HeadingBBox.right, from the right boundary of the second circumscribed rectangular box, SectBBox.right, to obtain the right distance rightDiff, that is, rightDiff = SectBBox.right - HeadingBBox.right.
[0120] Then, the larger distance maxDiff and the smaller distance minDiff of the left distance leftDiff and the right distance rightDiff are determined, that is, maxDiff=Max(leftDiff, rightDiff), minDiff=Min(leftDiff, rightDiff).
[0121] Subtract the left boundary of the first circumscribed rectangular box, HeadingBBox.left, from the right boundary of the first circumscribed rectangular box, HeadingBBox.right, to obtain the width of the first circumscribed rectangular box, that is, width = HeadingBBox.right - HeadingBBox.left; and subtract the upper boundary of the first circumscribed rectangular box, HeadingBBox.top, from the lower boundary of the first circumscribed rectangular box, HeadingBBox.bottom, to obtain the height of the first circumscribed rectangular box, that is, height = HeadingBBox.bottom - HeadingBBox.top.
[0122] Each boundary is determined based on an image coordinate system with the upper left corner of the current page as the origin.
[0123] If maxDiff < height * the first value (e.g., 0.5), then alignType = 1 (aligned at both ends), ident = leftDiff, where the first value is a floating-point value greater than 0.
[0124] If maxDiff < minDiff * the second value (e.g., 1.5) and minDiff > height * the third value (e.g., 2), or maxDiff < minDiff * the second value (e.g., 1) and minDiff > height * the third value (e.g., 4), then the left and right spacing differences are not large, so alignType = 4 (centered alignment), ident = leftDiff.
[0125] Preferably, the third value is greater than 2, that is, when the left and right spacing differences are not large and at least it is considered that the left and right spacing differences are greater than 2 spaces or more, the alignment method is determined to be centered alignment and the indent value is the left spacing.
[0126] If leftDiff > rightDiff and leftDiff > height * the fourth value (e.g., 2.5), then alignType = 2 (right alignment), ident = rightDiff.
[0127] In the remaining cases, alignType = 3 (left alignment), ident = leftDiff.
[0128] In this way, the accuracy and reliability of the alignment method and the indent value can be ensured, and the reliability of the title level determination can be further improved.
[0129] In one or more alternative embodiments of the present invention, updating each of the title feature templates according to the title features of each of the known titles in the known title set may be specifically implemented as follows:
[0130] For the known titles in the known title set, update the features in the set feature template to the average font size, alignment method, and indent value of the known titles, where the set feature template is the title feature template corresponding to the title level of the known titles.
[0131] In practical applications, for the known titles in the known title set, the set feature template corresponding to the known title can be determined according to the title level of the known title. Further, update the features in the set feature template to the average font size, alignment method, and indent value of the known title. In this way, the update of the title feature template can be simply and quickly realized, which is beneficial to improving the efficiency of title level determination.
[0132] In an optional embodiment of the present invention, for the known titles in the known title set, the features in the set feature template are updated to the average font size, alignment, and indentation value of the known titles. The specific implementation process may be as follows:
[0133] Starting from the first known title in the known title set, the features in the set feature template are updated to the average font size, alignment and indentation value of the known titles until the last known title.
[0134] In practice, the title features (average font size, alignment, and indentation) of all known titles in the HeadingGTSet (if any) are traversed in order of appearance. Based on the target document's given heading level i, the average font size, alignment, and indentation values of each title are stored in Template[i]. If the average font size, alignment, and indentation values already exist in Template[i], they are overwritten. For example, if there are two headings in a document, the later one will overwrite the earlier one.
[0135] It should be noted that the first known title here refers to the first known title that appears from the start to the end of the target document, and the last known title refers to the last known title that appears from the start to the end of the target document. The order in which the known titles are traversed here refers to the order in which the known titles appear in the target document.
[0136] In this way, the accuracy and reliability of the title feature template can be guaranteed.
[0137] In another optional embodiment of the present invention, for the known titles in the known title set, the features in the set feature template are updated to the average font size, alignment, and indentation value of the known titles. The specific implementation process may be as follows:
[0138] copying the known title set to obtain a backup title set;
[0139] filtering the known titles with the same title level in the standby title set to obtain a filtered standby title set;
[0140] According to each of the known titles in the filtered set of candidate titles, the features in the set feature template are updated to the average font size, alignment and indentation value of the known titles.
[0141] In actual applications, there may be multiple known titles with the same title level in a known title set. To reduce the number of updates to the title feature template and thus the amount of data processing, the known title set can be copied to obtain a backup title set, and then the known titles with the same title level in the backup title set can be filtered to obtain a filtered backup title set.
[0142] Each known title in the filtered set of alternative titles has a different title level. For each known title in the filtered set of alternative titles, a corresponding set feature template can be determined based on the title level of the known title. Furthermore, the features in the set feature template are updated to include the average font size, alignment, and indentation value of the known title.
[0143] In one or more optional embodiments of the present invention, the method further includes:
[0144] For the designated feature template that has not been updated, searching for a first feature template and a second feature template from each of the updated title feature templates, wherein the first title level of the first feature template is higher than the designated title level, and the second title level of the second feature template is lower than the designated title level, and the designated title level is the title level of the designated feature template;
[0145] performing linear interpolation calculation based on the average font size in the first feature template, the average font size in the second feature template, and the level interval to obtain the average font size corresponding to the specified heading level, wherein the level interval is the difference between the second heading level and the first heading level;
[0146] The features in the specified feature template are updated to the average font size corresponding to the specified heading level.
[0147] In practical applications, first traverse i from 1 to MaxLevel. If the average font size, alignment, and indentation value exist in Template[i], then Template[i] is the updated title feature template; continue to traverse the next Template[i]. If the average font size, alignment, and indentation value do not exist in Template[i], that is, it is a specified feature template, then first search from j<i to the left in sequence. If Template[j] (the first feature template) can be found, then record leftFontSize=Template[j], that is, record the left boundary font size as the average font size in the first feature template; similarly, search from k>i to the right. If Template[k] (the second feature template) can be found, then record rightFontSize=Template[k], that is, record the right boundary font size as the average font size in the second feature template.
[0148] Furthermore, a linear interpolation algorithm is used to determine the average font size corresponding to the specified title level based on leftFontSize and rightFontSize, as well as kj (level interval): based on leftFontSize, rightFontSize and kj, the font size interval M is first determined, that is, M = |leftFontSize-rightFontSize| / (kj), and then the average font size Template[i].fontSize of the specified feature template is determined based on leftFontSize and M, that is, Template[i].fontSize = leftFontSize-M*(ij), or the average font size Template[i].fontSize of the specified feature template is determined based on rightFontSize and M, that is, Template[i].fontSize = rightFontSize+M*(ki).
[0149] In addition, for each title level, a temporary font size template TmpFontTemplate can be set, where TmpFontTemplate[i] represents the temporary font size when the title level is i. At this time, first traverse i from 1 to MaxLevel. If the feature exists in Template[i], then TmpFontTemplate[i] = Template[i]. If not, first query from j = i-1 to the left. If Template[j] can be found, record leftFontSize = Template[j]. Similarly, query to the right to obtain rightFontSize. Use the linear interpolation algorithm to fill the value in TmpFontTemplate according to leftFontSize and rightFontSize.
[0150] In one or more optional embodiments of the present invention, before updating the features in the specified feature template to the average font size corresponding to the specified heading level, the method further includes:
[0151] If the first feature template is not found and the second feature template is found, performing linear interpolation calculation based on the first set font size, the average font size in the second feature template, and the second heading level to obtain the average font size corresponding to the specified heading level;
[0152] If the second feature template is not found and the first feature template is found, performing linear interpolation calculation based on the average font size in the second feature template, the second set font size, and the specified heading level to obtain the average font size corresponding to the specified heading level, wherein the first set font size is larger than the second set font size;
[0153] In the case where the first characteristic template and the second characteristic template are not searched, a linear interpolation calculation is performed according to the first set font size, the second set font size and a preset number to obtain an average font size corresponding to the specified title level.
[0154] In actual applications, for the specified feature template Template[i], if Template[j] (the first feature template) is not found, then record leftFontSize = the first set font size (such as 23.8), and at the same time find Template[k] (the second feature template), then record rightFontSize = Template[k], that is, record the right boundary font size as the average font size in the second feature template.
[0155] Furthermore, a linear interpolation algorithm is used to determine the average font size corresponding to the specified heading level based on leftFontSize and rightFontSize, as well as k (the second heading level): based on leftFontSize, rightFontSize and k, the font size interval M is first determined, that is, M = |leftFontSize-rightFontSize| / k, and then the average font size Template[i].fontSize of the specified feature template is determined based on leftFontSize and M, that is, Template[i].fontSize = leftFontSize-M*i, or the average font size Template[i].fontSize of the specified feature template is determined based on rightFontSize and M, that is, Template[i].fontSize = rightFontSize+M*(ki).
[0156] For the specified feature template Template[i], if Template[j] (the first feature template) is found, then record leftFontSize = Template[j], that is, record the left boundary font size as the average font size in the first feature template. If Template[k] (the second feature template) is not found, then record rightFontSize = the second set font size (such as 9.8).
[0157] Furthermore, a linear interpolation algorithm is used to determine the average font size corresponding to the specified title level based on leftFontSize and rightFontSize, as well as i (specified title level): based on leftFontSize, rightFontSize and i, first determine the font size interval M, that is, M = |leftFontSize-rightFontSize| / (MaxLevel+1-j), and then determine the average font size Template[i].fontSize of the specified feature template based on leftFontSize and M, that is, Template[i].fontSize = leftFontSize-M*(ij), or determine the average font size Template[i].fontSize of the specified feature template based on rightFontSize and M, that is, Template[i].fontSize = rightFontSize+M*(MaxLevel+1-i).
[0158] For the specified feature template Template[i], if Template[j] (first feature template) and Template[k] (second feature template) are not found, it means that the known title set is empty, then record leftFontSize = first set font size, rightFontSize = second set font size.
[0159] Furthermore, a linear interpolation algorithm is used to determine the average font size corresponding to the specified title level based on leftFontSize and rightFontSize, as well as i (specified title level): based on leftFontSize, rightFontSize and i, first determine the font size interval M, that is, M = |leftFontSize-rightFontSize| / (MaxLevel+2), and then determine the average font size Template[i].fontSize of the specified feature template based on leftFontSize and M, that is, Template[i].fontSize = leftFontSize-M*i, or determine the average font size Template[i].fontSize of the specified feature template based on rightFontSize and M, that is, Template[i].fontSize = rightFontSize+M*(MaxLevel+1-i).
[0160] In this way, it can be ensured that the average font size corresponding to the title level can be fully and accurately specified, that is, the average font size of the title feature can be specified.
[0161] In one or more optional embodiments of the present invention, the title features include an average font size, an alignment, and an indentation value; and the calculation of the matching degree between the title features of the unknown title and each of the updated title feature templates may be specifically implemented as follows:
[0162] For each of the said title feature templates that have been updated, do the following:
[0163] If the features in the title feature template include average font size, alignment, and indentation value, determining a font size score based on the average font size of the unknown title and the average font size in the title feature template; determining a format score based on the alignment and indentation value of the unknown title and the alignment and indentation value in the title feature template;
[0164] If the feature in the title feature template only includes the average font size, determining a font size score based on the average font size of the unknown title and the average font size in the title feature template; and determining the first set score as the format score;
[0165] The degree of matching between the title feature of the unknown title and the title feature template is determined according to the font size score and the format score.
[0166] In practical applications, for each feature template Template[i]:
[0167] If Template[i] contains an average font size, alignment, and indentation value, the font size score fontScore is calculated according to the average font size of the unknown title and the average font size in the title feature template according to the set font size scoring rules; and the format score is determined according to the alignment and indentation value of the unknown title and the alignment and indentation value in the title feature template according to the set format scoring rules.
[0168] If there is no alignment and indentation value in Template[i], that is, only the average font size exists, then the font size score fontScore is calculated according to the average font size of the unknown title and the average font size in the title feature template according to the set font size scoring rules; the first set score is determined as the format score, that is, the format score identScore = the first set score (such as 70).
[0169] Furthermore, the font size equalization and format score are weightedly calculated to obtain the matching degree score[i] of the unknown title relative to the title feature template Template[i], that is, score[i]=a*identScore[i]+b*fontScore[i], where a and b are weights, and a+b=1, for example, a=b=0.5.
[0170] In this way, different methods are selected to determine the matching degree according to the features in the title feature template, which greatly improves the accuracy and reliability of the matching degree.
[0171] In one or more optional embodiments of the present invention, determining the font size score based on the average font size of the unknown title and the average font size in the title feature template includes:
[0172] Calculating a first absolute value of a difference between a first average font size and a second average font size, wherein the first average font size is the average font size of the unknown title and the second average font size is the average font size in the title feature template;
[0173] The first absolute value is input into a formula for setting a font size score to obtain a font size score.
[0174] In practical applications, the first absolute value fontSizeDiff of the difference between the first average font size feature.fontSize and the second average font size Template[i].fontSize is calculated, that is, fontSizeDiff = | Template[i].fontSize - feature.fontSize |.
[0175] Furthermore, the first absolute value fontSizeDiff is calculated according to a set font size score formula to obtain a font size score fontScore, wherein the set font size score formula is: fontScore=100-tanh(fontSizeDiff*0.1)*100.
[0176] In this way, the precision and accuracy of the font size score can be guaranteed.
[0177] In one or more optional embodiments of the present invention, the format score is determined based on the alignment and indentation value of the unknown title and the alignment and indentation value in the title feature template. The specific implementation process may be as follows:
[0178] If a fourth condition is satisfied, determining the second set score as the format score, the second set score is greater than the first set score, and the fourth condition is that the alignment of the unknown title is justified or centered, and the alignment in the title feature template is justified or centered;
[0179] If a fifth condition is satisfied, determining the third set score as the format score, the third set score is less than the first set score, and the fifth condition is that the alignment of the unknown title is different from the alignment in the title feature template, and both the alignment of the unknown title and the alignment in the title feature template are not justified;
[0180] If the fourth condition is not met and the fifth condition is not met, calculate the second absolute value of the difference between the first indent value and the second indent value, the first indent value is the indent value of the unknown title, and the second indent value is the indent value in the title feature template; input the second absolute value into the set format score formula to obtain the format score.
[0181] In practical applications, 1 is used to indicate double alignment, 2 is used to indicate right alignment, 3 is used to indicate left alignment, and 4 is used to indicate center alignment.
[0182] If the alignment method Template[i].alignType in the title feature template and the alignment method feature.alignType of the unknown title are 1 or 4, that is, the combination of Template[i].alignType and feature.alignType belongs to any of 1-1, 1-4, 4-1 and 4-4, let the format score identScore = the second set score (such as 100).
[0183] If Template[i].alignType and feature.alignType are both greater than or equal to 2, and Template[i].alignType and feature.alignType are not equal, set the format score identScore = the third set score (such as 0).
[0184] In the remaining cases (i.e., when both Template[i].alignType and feature.alignType are left-aligned or right-aligned), the second absolute value identDiff of the difference between the first indent value feature.ident and the second indent value Template[i].ident is calculated, i.e., identDiff = |Template[i].ident - feature.ident|. Furthermore, the second absolute value identDiff is input into the set format score formula to obtain the format score identScore, where the set format score formula is identScore = 100 - tanh(identDiff / MIN(Template[i].fontSize, feature.Fontsize) * 0.1) * 100.
[0185] In this way, different methods are used to determine the format score for different alignment methods, which can ensure the accuracy and reliability of the format score.
[0186] In one or more optional embodiments of the present invention, the title level of the unknown title is determined according to each matching degree, and the specific implementation process may be as follows:
[0187] The title level of the target feature template is determined to be the title level of the unknown title, and the target feature template is the title feature template corresponding to the highest matching degree among the matching degrees.
[0188] In practical applications, for each unknown title in the unknown title set, after obtaining the corresponding matching degree score[i], the highest matching degree is determined from the matching degrees. The title feature template corresponding to the highest matching degree is then determined as the target feature template, and the title level of the target feature template is determined as the title level bestIdx of the unknown title, that is, bestIdx = argMax(Score[i]). In this way, the accuracy of the title level can be guaranteed.
[0189] It should be noted that the above-mentioned matching degree can be obtained using a matching score, a similarity percentage (or similarity) or other methods that can be realized based on the current solution. In one example, for each unknown title in the unknown title set, the similarity (such as cosine distance) between the title features of the unknown title and the updated title feature templates is calculated, and the title level of the unknown title is determined based on each similarity. For example, the closer the cosine distance is to 1, the higher the similarity is, and the title feature template corresponding to the cosine distance closer to 1 is determined as the title level of the unknown title.
[0190] In one or more optional embodiments of the present invention, after determining the title level of the unknown title according to each matching degree, the method further includes:
[0191] updating the target feature template according to the title feature of the unknown title;
[0192] Deleting the unknown title from the unknown title set;
[0193] Continue to determine the title level of the next unknown title in the unknown title set.
[0194] In practical applications, the title features of the current unknown title are stored in its corresponding title feature template Template[i], that is, in the target feature template, and then the current unknown title is removed from the unknown title set HeadingDetSet. Then, for the next unknown title in the unknown title set HeadingDetSet, the operation of determining the title level of the current unknown title is repeated until all unknown titles in HeadingDetSet are processed.
[0195] It should be noted that, when determining the title levels of unknown titles in an unknown title set, the title levels may be determined starting from the first unknown title in the unknown title set and continuing until the last unknown title.
[0196] For example, the method for determining the title level is as follows:
[0197] 1. Get all titles in the document. If the document already has title information, extract it and store it in the title set HeadingGTSet. If the document does not have title information, or if the number of titles needs to be expanded, store the identified titles in the document set HeadingDetSet. To automatically determine and repair the hierarchical structure of the original titles in the document, simply store all title data in HeadingGTSet in HeadingDetSet and clear HeadingGTSet.
[0198] 2. Set the maximum number of heading levels to MaxLevel = 6. Create a heading feature template Template, where Template[i] represents the feature for heading level i. Create a temporary font size feature template TmpFontTemplate, where TmpFontTemplate[i] represents the temporary font size for heading level i.
[0199] 3. Traverse each title in HeadingDetSet and HeadingGTSet and extract features according to the following format. Then, assign the extracted features to the title. Unless otherwise specified, the term "extracted features" will be used to refer to both the features and the title itself.
[0200] 3.1 Traverse each element in the title content, obtain its average font size, record it as FontSize, and store it in the corresponding feature. If the current document is a layout document, traverse all TextObjects in the title, obtain the number of Unicode characters in each TextObject and the corresponding font size, and calculate the average font size.
[0201] 3.2 Let the bounding rectangle of the current title content be HeadingBBox, and the bounding rectangle of the text area where the current title is located be SectBBox. Calculate the alignment type alignType and indent ident of the current title using the following formula:
[0202] leftDiff=HeadingBBox.left-SectBBox.left;
[0203] rightDiff = SectBBox.right - HeadingBBox.right;
[0204] maxDiff = Max(leftDiff, rightDiff);
[0205] minDiff = Min(leftDiff, rightDiff);
[0206] width = HeadingBBox.right - HeadingBBox.left;
[0207] height = HeadingBBox.bottom - HeadingBBox.top;
[0208] If maxDiff < height * 0.5, then alignType = 1 (justify both ends), ident = leftDiff;
[0209] If maxDiff < minDiff * 1.5 and minDiff > height * 2, or maxDiff < minDiff * 2 and minDiff > height * 4, then alignType = 4 (center alignment), ident = leftDiff;
[0210] If leftDiff > rightDiff and leftDiff > height * 2.5, then alignType = 2, ident = rightDiff, right alignment;
[0211] For the remaining cases, alignType = 3 (left alignment), ident = leftDiff.
[0212] 4. Traverse the features of all the headings (if any) in HeadingGTSet in the order of appearance. According to the level i given in its document, store the corresponding features in Template[i]. If there is already a result in Template[i], then directly overwrite it.
[0213] 5. First, traverse i from 1 to MaxLevel. If the feature exists in Template[i], then TmpFontTemplate[i] = Template[i]. If not, search leftward from j = i - 1. If Template[j] is found, record leftFontSize = Template[j]. If no suitable one is found, then record leftFontSize = 23.8. Similarly, search rightward to obtain rightFontSize. If no suitable one is found, then record rightFontSize = 9.8. Use linear interpolation to fill the value in TmpFontTemplate based on leftFontSize and rightFontSize.
[0214] 6. Take a title from HeadingDetSet. Calculate the title feature, Template, and TmpFontTemplate values using the following algorithm to obtain the format score identScore and fontScore. The format score identScore and fontScore for the title feature and level i are calculated as follows:
[0215] 6.1 If Template[i] exists:
[0216] If Template[i].alignType and feature.alignType are 1 or 4, identScore = 100;
[0217] If Template[i].alignType and feature.alignType are both greater than or equal to 2, but they are not equal, identScore = 0;
[0218] In the remaining cases, identDiff=|Template[i].ident-feature.ident|, identScore=100-tanh(identDiff / MIN(Template[i].fontSize,feature.Fontsize)*0.1)*100;
[0219] In addition, fontScore=100-tanh(fontSizeDiff*0.1)*100, where fontSizeDiff=|Template[i].fontSize-feature.fontSize|.
[0220] 6.2 If Template[i] does not exist:
[0221] identScore = 70;
[0222] fontScore=100-tanh(fontSizeDiff*0.1)*100, where fontSizeDiff=|Template[i].fontSize-TmpFontTemplate[i].fontSize|.
[0223] 7. The final matching degree is obtained by weighting according to the following formula, and then the one with the highest matching degree is selected. Its index bestIdx is the hierarchical result of the current title:
[0224] score[i]=0.5*identScore[i]+0.5*fontScore[i];
[0225] bestIdx=argMax(Score[i]).
[0226] 8. Store the feature of the current title in Template[i], then remove the current title from HeadingDetSet, and then repeat operations 5, 6, 7, and 8 until all titles in HeadingDetSet are processed.
[0227] 9. Reconstruct the complete title structure tree based on all the recalculated title levels.
[0228] In this embodiment, when a given document has structured information, the patented algorithm can be used to correct errors in the structured information. For example, when a user edits a document, they fail to mark it according to the corresponding heading level (e.g., marking it as heading 4 when it should be heading 2). When a given document does not have structured information, or when the structured information needs to be expanded, all headings can be identified and structured.
[0229] The method, device, and system for determining heading levels provided by this invention can, based on an alignment determination system and a heading level calculation system, correct incorrect heading structure trees in a document and expand and enrich the document's structured information based on the current structure tree. A template-based scoring and matching system is constructed, utilizing visual features and spatial information for comprehensive scoring, and then dynamically updating template features using a greedy algorithm.
[0230] The following describes the device for determining the title level provided by the present invention. The device for determining the title level described below and the method for determining the title level described above can be referenced to each other.
[0231] Figure 2 Schematic diagram of the structure of the device for determining the title level provided by the present invention. Figure 2 As shown, the apparatus 200 for determining title level includes: a first acquisition module 201, a first update module 202 and a calculation module 203, wherein:
[0232] A first acquisition module 201 is configured to acquire a known title set and an unknown title set of a target document, and create a plurality of title feature templates, wherein the known title set includes at least one known title of a known title level, and the unknown title set includes at least one unknown title of a title level to be identified, and each of the title feature templates corresponds to a title level;
[0233] A first updating module 202 is configured to update each title feature template according to the title feature of each known title in the known title set;
[0234] The calculation module 203 is configured to calculate the matching degree between the title features of each unknown title in the unknown title set and the updated title feature templates, and determine the title level of the unknown title according to each matching degree.
[0235] The device for determining title levels provided by the present invention obtains a known title set and an unknown title set of a target document and creates multiple title feature templates, wherein the known title set includes at least one known title of a known title level, and the unknown title set includes at least one unknown title of a title level to be identified, and each of the title feature templates corresponds to a title level; according to the title features of each known title in the known title set, each of the title feature templates is updated; for each unknown title in the unknown title set, the matching degree between the title features of the unknown title and each of the updated title feature templates is calculated, and the title level of the unknown title is determined based on each matching degree, so that the title level of each title in the document can be accurately and quickly identified.
[0236] In one or more optional embodiments of the present invention, the apparatus 200 for determining the title level further includes a second acquisition module configured to:
[0237] The following steps are performed for each designated title, where the designated title is the known title or the unknown title:
[0238] The average font size, alignment, and indent value of the designated title are obtained, and the average font size, alignment, and indent value are determined as title features of the designated title.
[0239] In one or more optional embodiments of the present invention, the second acquisition module is further configured to:
[0240] Get the font size of each element in the specified title;
[0241] Determining an average font size of the designated title based on the font sizes;
[0242] Obtain a first bounding rectangular frame of the designated title and a second bounding rectangular frame of the text area where the designated title is located;
[0243] An alignment mode and an indentation value of the designated title are determined according to the first circumscribed rectangular frame and the second circumscribed rectangular frame.
[0244] In one or more optional embodiments of the present invention, the second acquisition module is further configured to:
[0245] Calculating a left distance between a left border of the first circumscribed rectangular frame and a left border of the second circumscribed rectangular frame, and calculating a right distance between a right border of the first circumscribed rectangular frame and a right border of the second circumscribed rectangular frame;
[0246] Determine the larger and smaller distances between the left and right distances, and obtain the width and height of the first circumscribed rectangular frame;
[0247] If the first condition is met, determining that the alignment of the designated title is justified, and determining that the indent value of the designated title is left spacing, the first condition is that the larger spacing is less than a first product, and the first product is the product of the height and the first value;
[0248] If the second condition is met, determining that the alignment of the designated title is centered, and determining that the indent value of the designated title is left spacing, the second condition is that the larger spacing is smaller than the second product, and the smaller spacing is larger than a third product, the second product is the product of the smaller spacing and a second value, the third product is the product of the height and a third value, the third value is larger than the second value, and the second value is larger than the first value;
[0249] If a third condition is met, determining that the alignment of the designated title is right-aligned, and determining that the indentation value of the designated title is right spacing, the third condition being that the left spacing is greater than the right spacing, and the left spacing is greater than a fourth product, the fourth product being the product of the height and a fourth value, and the fourth value being greater than the second value;
[0250] If the first condition, the second condition, and the third condition are all not satisfied, the alignment of the designated title is determined to be left alignment, and the indent value of the designated title is determined to be left spacing.
[0251] In one or more optional embodiments of the present invention, the first updating module 202 is further configured to:
[0252] Starting from the first known title in the known title set, the features in the set feature template are updated to the average font size, alignment and indentation value of the known titles, and the set feature template is the title feature template corresponding to the title level of the known titles, until the last known title.
[0253] In one or more optional embodiments of the present invention, the apparatus 200 for determining the title level further includes a second updating module configured to:
[0254] For the designated feature template that has not been updated, searching for a first feature template and a second feature template from each of the updated title feature templates, wherein the first title level of the first feature template is higher than the designated title level, and the second title level of the second feature template is lower than the designated title level, and the designated title level is the title level of the designated feature template;
[0255] performing linear interpolation calculation based on the average font size in the first feature template, the average font size in the second feature template, and the level interval to obtain the average font size corresponding to the specified heading level, wherein the level interval is the difference between the second heading level and the first heading level;
[0256] The features in the specified feature template are updated to the average font size corresponding to the specified heading level.
[0257] In one or more optional embodiments of the present invention, the second update module is further configured to:
[0258] If the first feature template is not found and the second feature template is found, performing linear interpolation calculation based on the first set font size, the average font size in the second feature template, and the second heading level to obtain the average font size corresponding to the specified heading level;
[0259] If the second feature template is not found and the first feature template is found, performing linear interpolation calculation based on the average font size in the second feature template, the second set font size, and the specified heading level to obtain the average font size corresponding to the specified heading level, wherein the first set font size is larger than the second set font size;
[0260] In the case where the first characteristic template and the second characteristic template are not searched, a linear interpolation calculation is performed according to the first set font size, the second set font size and a preset number to obtain an average font size corresponding to the specified title level.
[0261] In one or more optional embodiments of the present invention, the title features include average font size, alignment, and indentation value;
[0262] The calculation module 203 is further configured to:
[0263] For each of the said title feature templates that have been updated, do the following:
[0264] If the features in the title feature template include average font size, alignment, and indentation value, determining a font size score based on the average font size of the unknown title and the average font size in the title feature template; determining a format score based on the alignment and indentation value of the unknown title and the alignment and indentation value in the title feature template;
[0265] If the feature in the title feature template only includes the average font size, determining a font size score based on the average font size of the unknown title and the average font size in the title feature template; and determining the first set score as the format score;
[0266] The degree of matching between the title feature of the unknown title and the title feature template is determined according to the font size score and the format score.
[0267] In one or more optional embodiments of the present invention, the calculation module 203 is further configured to:
[0268] Calculating a first absolute value of a difference between a first average font size and a second average font size, wherein the first average font size is the average font size of the unknown title and the second average font size is the average font size in the title feature template;
[0269] The first absolute value is input into a formula for setting a font size score to obtain a font size score.
[0270] In one or more optional embodiments of the present invention, the calculation module 203 is further configured to:
[0271] If a fourth condition is satisfied, determining the second set score as the format score, the second set score is greater than the first set score, and the fourth condition is that the alignment of the unknown title is justified or centered, and the alignment in the title feature template is justified or centered;
[0272] If a fifth condition is satisfied, determining the third set score as the format score, the third set score is less than the first set score, and the fifth condition is that the alignment of the unknown title is different from the alignment in the title feature template, and both the alignment of the unknown title and the alignment in the title feature template are not justified;
[0273] If the fourth condition is not met and the fifth condition is not met, calculate the second absolute value of the difference between the first indent value and the second indent value, the first indent value is the indent value of the unknown title, and the second indent value is the indent value in the title feature template; input the second absolute value into the set format score formula to obtain the format score.
[0274] In one or more optional embodiments of the present invention, the calculation module 203 is further configured to:
[0275] The title level of the target feature template is determined to be the title level of the unknown title, and the target feature template is the title feature template corresponding to the highest matching degree among the matching degrees.
[0276] In one or more optional embodiments of the present invention, the calculation module 203 is further configured to:
[0277] updating the target feature template according to the title feature of the unknown title;
[0278] Deleting the unknown title from the unknown title set;
[0279] Continue to determine the title level of the next unknown title in the unknown title set.
[0280] Figure 3 An example of a physical structure diagram of an electronic device is shown below. Figure 3As shown, the electronic device may include: a processor 310, a communication interface 320, a memory 330, and a communication bus 340, wherein the processor 310, the communication interface 320, and the memory 330 communicate with each other via the communication bus 340. The processor 310 may call the logic instructions in the memory 330 to execute a method for determining a title level, the method comprising: obtaining a known title set and an unknown title set of a target document, and creating a plurality of title feature templates, wherein the known title set includes at least one known title of a known title level, the unknown title set includes at least one unknown title of a title level to be identified, and each of the title feature templates corresponds to a title level; updating each of the title feature templates based on the title features of each of the known titles in the known title set; calculating, for each of the unknown titles in the unknown title set, a degree of matching between the title features of the unknown title and each of the updated title feature templates, and determining the title level of the unknown title based on each of the matching degrees.
[0281] In addition, the logic instructions in the above-mentioned memory 330 can be implemented in the form of a software functional unit and can be stored in a computer-readable storage medium when sold or used as an independent product. Based on this understanding, the technical solution of the present invention, 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 and includes several instructions for enabling a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present invention. The aforementioned storage medium includes: various media that can store program codes, such as a USB flash drive, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk.
[0282] On the other hand, the present invention also provides a computer program product, which includes a computer program, which can be stored on a computer-readable storage medium. When the computer program is executed by a processor, the computer can execute the method for determining the title level provided by the above methods, which includes: obtaining a known title set and an unknown title set of the target document, and creating multiple title feature templates, the known title set includes at least one known title of a known title level, and the unknown title set contains at least one unknown title of a title level to be identified, each of the title feature templates corresponding to a title level; updating each of the title feature templates according to the title features of each of the known titles in the known title set; for each of the unknown titles in the unknown title set, calculating the matching degree between the title features of the unknown title and each of the updated title feature templates, and determining the title level of the unknown title based on each matching degree.
[0283] On the other hand, the present invention also provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, is implemented to execute the method for determining the title level provided by the above-mentioned methods, the method comprising: obtaining a known title set and an unknown title set of the target document, and creating multiple title feature templates, the known title set including at least one known title of a known title level, the unknown title set containing at least one unknown title of a title level to be identified, each of the title feature templates corresponding to a title level; updating each of the title feature templates according to the title features of each of the known titles in the known title set; for each of the unknown titles in the unknown title set, calculating the matching degree between the title features of the unknown title and each of the updated title feature templates, and determining the title level of the unknown title according to each matching degree.
[0284] The device embodiments described above are merely illustrative. The units described as separate components may or may not be physically separate, and the components shown as units may or may not be physical units, i.e., they may be located in one location or distributed across multiple network units. Some or all of the modules may be selected based on actual needs to achieve the objectives of the present embodiment. Persons of ordinary skill in the art will be able to understand and implement the present invention without inventive effort.
[0285] Through the description of the above embodiments, those skilled in the art can clearly understand that each embodiment can be implemented by means of software plus a necessary general hardware platform, or of course, by hardware. Based on this understanding, the essence of the above technical solution or the part that contributes to the existing technology can be embodied in the form of a software product. The computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, a magnetic disk, an optical disk, etc., and includes a number of instructions for enabling a computer device (which can be a personal computer, a server, or a network device, etc.) to execute the methods described in each embodiment or certain parts of the embodiments.
[0286] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit it. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the various embodiments of the present invention.
Claims
1. A method for determining a title level, characterized in that: include: Acquire a known title set and an unknown title set of a target document, and create a plurality of title feature templates, wherein the known title set includes at least one known title of a known title level, and the unknown title set includes at least one unknown title of a title level to be identified, and each of the title feature templates corresponds to a title level; updating each of the title feature templates according to the title feature of each of the known titles in the known title set; For each unknown title in the unknown title set, the matching degree between the title feature of the unknown title and each updated title feature template is calculated, and the title level of the unknown title is determined according to each matching degree.
2. The method for determining title level according to claim 1, wherein: Before updating each of the title feature templates according to the title feature of each of the known titles in the known title set, the method further includes: The following steps are performed for each designated title, where the designated title is the known title or the unknown title: An average font size, alignment, and indentation value of the designated title are obtained, and the average font size, alignment, and indentation value are determined as title features of the designated title.
3. The method for determining title level according to claim 2, wherein: The obtaining of the average font size, alignment, and indentation value of the specified title includes: Get the font size of each element in the specified title; Determining an average font size of the designated title based on the font sizes; Obtain a first bounding rectangular frame of the designated title and a second bounding rectangular frame of the text area where the designated title is located; An alignment mode and an indentation value of the designated title are determined according to the first circumscribed rectangular frame and the second circumscribed rectangular frame.
4. The method for determining title level according to claim 3, wherein: The determining, based on the first circumscribed rectangular frame and the second circumscribed rectangular frame, an alignment mode and an indentation value of the designated title includes: Calculating a left distance between a left border of the first circumscribed rectangular frame and a left border of the second circumscribed rectangular frame, and calculating a right distance between a right border of the first circumscribed rectangular frame and a right border of the second circumscribed rectangular frame; Determine the larger and smaller distances between the left and right distances, and obtain the width and height of the first circumscribed rectangular frame; If the first condition is met, determining that the alignment of the designated title is justified, and determining that the indent value of the designated title is left spacing, the first condition is that the larger spacing is less than a first product, and the first product is the product of the height and the first value; If the second condition is met, determining that the alignment of the designated title is centered, and determining that the indent value of the designated title is left spacing, the second condition is that the larger spacing is smaller than the second product, and the smaller spacing is larger than a third product, the second product is the product of the smaller spacing and a second value, the third product is the product of the height and a third value, the third value is larger than the second value, and the second value is larger than the first value; If a third condition is met, determining that the alignment of the designated title is right-aligned, and determining that the indentation value of the designated title is right spacing, the third condition being that the left spacing is greater than the right spacing, and the left spacing is greater than a fourth product, the fourth product being the product of the height and a fourth value, and the fourth value being greater than the second value; If the first condition, the second condition and the third condition are all not satisfied, the alignment of the designated title is determined to be left alignment, and the indent value of the designated title is determined to be left spacing.
5. The method for determining title level according to claim 2, wherein: The updating of each title feature template according to the title feature of each known title in the known title set includes: Starting from the first known title in the known title set, the features in the set feature template are updated to the average font size, alignment and indentation value of the known titles, and the set feature template is the title feature template corresponding to the title level of the known titles, until the last known title.
6. The method for determining title level according to claim 5, characterized in that: The method further comprises: For the designated feature template that has not been updated, searching for a first feature template and a second feature template from each of the updated title feature templates, wherein the first title level of the first feature template is higher than the designated title level, and the second title level of the second feature template is lower than the designated title level, and the designated title level is the title level of the designated feature template; performing linear interpolation calculation based on the average font size in the first feature template, the average font size in the second feature template, and the level interval to obtain the average font size corresponding to the specified heading level, wherein the level interval is the difference between the second heading level and the first heading level; The features in the specified feature template are updated to the average font size corresponding to the specified heading level.
7. The method for determining title level according to claim 6, wherein: Before updating the features in the specified feature template to the average font size corresponding to the specified title level, the method further includes: If the first feature template is not found and the second feature template is found, performing linear interpolation calculation based on the first set font size, the average font size in the second feature template, and the second heading level to obtain the average font size corresponding to the specified heading level; If the second feature template is not found and the first feature template is found, performing linear interpolation calculation based on the average font size in the second feature template, the second set font size, and the specified heading level to obtain the average font size corresponding to the specified heading level, wherein the first set font size is larger than the second set font size; In the case where the first characteristic template and the second characteristic template are not searched, a linear interpolation calculation is performed according to the first set font size, the second set font size and a preset number to obtain an average font size corresponding to the specified title level.
8. The method for determining title level according to claim 1, wherein: Said title characteristics include average font size, alignment and indentation value; The calculating the matching degree between the title features of the unknown title and each of the updated title feature templates includes: For each of the said title feature templates that have been updated, do the following: If the features in the title feature template include average font size, alignment, and indentation value, determining a font size score based on the average font size of the unknown title and the average font size in the title feature template; determining a format score based on the alignment and indentation value of the unknown title and the alignment and indentation value in the title feature template; If the feature in the title feature template only includes the average font size, determining a font size score based on the average font size of the unknown title and the average font size in the title feature template; and determining the first set score as the format score; The degree of matching between the title feature of the unknown title and the title feature template is determined according to the font size score and the format score.
9. The method for determining title level according to claim 8, wherein: Determining the font size score according to the average font size of the unknown title and the average font size in the title feature template includes: Calculating a first absolute value of a difference between a first average font size and a second average font size, wherein the first average font size is the average font size of the unknown title and the second average font size is the average font size in the title feature template; The first absolute value is input into a formula for setting a font size score to obtain a font size score.
10. The method for determining title level according to claim 8 or 9, characterized in that: Determining a format score according to the alignment and indentation value of the unknown title and the alignment and indentation value in the title feature template includes: If a fourth condition is satisfied, determining the second set score as the format score, the second set score is greater than the first set score, and the fourth condition is that the alignment of the unknown title is justified or centered, and the alignment in the title feature template is justified or centered; If a fifth condition is satisfied, determining the third set score as the format score, the third set score is less than the first set score, and the fifth condition is that the alignment of the unknown title is different from the alignment in the title feature template, and both the alignment of the unknown title and the alignment in the title feature template are not justified; If the fourth condition is not met and the fifth condition is not met, calculate the second absolute value of the difference between the first indent value and the second indent value, the first indent value is the indent value of the unknown title, and the second indent value is the indent value in the title feature template; input the second absolute value into the set format score formula to obtain the format score.
11. The method for determining title level according to claim 1, wherein: Determining the title level of the unknown title according to each of the matching degrees includes: The title level of the target feature template is determined to be the title level of the unknown title, and the target feature template is the title feature template corresponding to the highest matching degree among the matching degrees.
12. The method for determining title level according to claim 11, characterized in that: After determining the title level of the unknown title according to the matching degrees, the method further includes: updating the target feature template according to the title feature of the unknown title; Deleting the unknown title from the unknown title set; Continue to determine the title level of the next unknown title in the unknown title set.
13. A device for determining a title level, characterized in that: include: A first acquisition module is configured to acquire a known title set and an unknown title set of a target document and create a plurality of title feature templates, wherein the known title set includes at least one known title of a known title level, and the unknown title set includes at least one unknown title of a title level to be identified, and each of the title feature templates corresponds to a title level; A first updating module is configured to update each of the title feature templates according to the title feature of each of the known titles in the known title set; The calculation module is configured to calculate the matching degree between the title features of each unknown title in the unknown title set and the updated title feature templates, and determine the title level of the unknown title based on each matching degree.