Template-based document style intelligent migration method and system

By constructing a template style feature library and adopting a hierarchical decision-making mechanism for document style migration, the problem of time-consuming and error-prone manual operation in existing technologies has been solved, and the automatic conversion and unification of document formats has been achieved.

CN122065775APending Publication Date: 2026-05-19E SURFING IOT CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202610126562.3
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-01-29
Publication Date
2026-05-19

AI Technical Summary

Technical Problem

Existing technologies rely on manual operation for document format conversion, which is time-consuming and prone to errors. Traditional tools lack intelligent judgment capabilities and cannot accurately identify and process directly formatted content, resulting in low conversion accuracy and difficulty in meeting the complex and ever-changing document format conversion needs.

Method used

By parsing template documents to construct a template style feature library, and using a hierarchical decision-making mechanism combined with name matching, semantic role matching, and feature similarity matching strategies, a mapping relationship between source elements and template styles is established to achieve automated document style migration.

Benefits of technology

It automates document formatting, improves conversion accuracy and robustness, shortens formatting time, ensures the uniformity and integrity of output document format, and avoids omissions and errors in manual operation.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122065775A_ABST
    Figure CN122065775A_ABST
Patent Text Reader

Abstract

The invention relates to the field of document processing, and provides a template-based document style intelligent migration method and system. The method comprises the following steps: performing style analysis on a template document to obtain a template style feature library; performing content analysis on the source document to obtain a source element feature set; according to the template style feature library and the source element feature set, establishing a mapping relationship between the source elements and template styles based on a hierarchical decision mechanism, and generating a mapping decision table; and reconstructing a target document according to the mapping decision table to obtain a style migration document. According to the invention, the accuracy and efficiency of document conversion are improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention belongs to the field of document processing technology, and in particular relates to a template-based intelligent migration method and system for document styles. Background Technology

[0002] In modern office environments, document formatting is crucial. To ensure consistency in visual style and structure across all documents, organizations typically develop standard Word templates. However, in practice, source documents submitted by different individuals often exhibit varying formats, frequently employing personal, customary formatting techniques rather than adhering to the standard styles defined in the template. Therefore, converting these inconsistently formatted source documents to a standard template format has become a common requirement in document processing.

[0003] Currently, document style conversion mainly relies on manual operation. Operators need to manually modify formatting attributes such as font, font size, spacing, and color by comparing each paragraph and sentence with the template. This work is extremely time-consuming and error-prone. Although Microsoft Word itself provides the function of "attach template" and "automatically update document styles," this function mainly depends on the existence of styles with the same name in the source document and the template document for replacement. It is completely ineffective for a large amount of directly formatted content or custom styles with mismatched names in the source document. In addition, some third-party plugins or macro scripts are mostly based on fixed and rigid rules for replacement, lacking the ability to intelligently judge the similarity of document content structure and style. They cannot accurately identify and process document elements with direct formatting, resulting in low conversion accuracy, limited applicability, and difficulty in meeting the complex and ever-changing document format conversion needs. Summary of the Invention

[0004] In view of the shortcomings of the prior art, the purpose of the invention is to provide a template-based intelligent migration method, system, device and storage medium for document styles.

[0005] The first aspect of this invention provides a template-based intelligent document style migration method, comprising: S1: Parse the template document to obtain the template style feature library; S2: Parse the source document to obtain a set of source element features; S3: Based on the template style feature library and the source element feature set, establish a mapping relationship between source elements and template styles based on a hierarchical decision mechanism, and generate a mapping decision table; S4: Reconstruct the target document based on the mapping decision table to obtain the style migration document.

[0006] According to the template-based intelligent document style migration method provided by the present invention, step S1 further includes: S11: Parse the underlying structure file of the template document to form a set of style definitions including style element nodes and category information; S12: Convert the format attributes of multiple style element nodes in the style definition set into style feature vectors; S13: Based on the rule-based scoring mechanism, infer semantic role labels for multiple style element nodes in the style definition set; S14: Summarize the style definition set, style feature vector, and semantic role tags to obtain the template style feature library.

[0007] According to the template-based intelligent document style migration method provided by the present invention, step S2 further includes: S21: Traverse the main content of the source document, identify paragraph elements and table elements in the source document, and obtain a set of source document elements including multiple elements; S22: Extract the text content and element type for each element in the source document element set, and calculate the effective feature vector of the current element after superimposing all format levels; S23: Infer semantic roles based on the position information, format features, and content patterns of each element in the source document element set; S24: Summarize the source document element set, text content, element type, effective feature vector, and semantic role of the source element feature set.

[0008] According to the template-based intelligent document style migration method provided by the present invention, the calculation of the effective feature vector in step S22 adopts a layered stacking mechanism, and further includes: S221: Obtain the feature vector of the document's default style as the initial vector; S222: When a named style is applied to the source element, extract the feature vector of the named style, and overwrite the corresponding field in the initial vector with the attribute values ​​of the feature vector of the named style to obtain the first optimized vector. S223: Parse the paragraph attribute child nodes and character attribute child nodes in the source element node, extract the directly set format attributes, and overwrite the corresponding fields in the first optimization vector with the attribute values ​​of the directly set format attributes to obtain the second optimization vector; S224: When a paragraph element contains multiple text blocks with different formats, the length of the text covered by the multiple text blocks is counted, the format attribute of the text block with the longest text length is selected as the representative character format of the paragraph, and the representative character format is merged into the second optimization vector to obtain the effective feature vector of the current source element.

[0009] According to the template-based intelligent document style migration method provided by the present invention, the hierarchical decision mechanism in step S3 includes multiple matching strategies, specifically including: name matching strategy, semantic role matching strategy and feature similarity matching strategy.

[0010] According to the template-based intelligent migration method for document styles provided by the present invention, the name matching strategy specifically includes: Detect whether the current source element has an explicitly applied named style. If a named style is applied, extract the applied style name, search the template style feature library for template styles with the same style name as the applied style name and whose style type is compatible with the element type of the current source element. If the search is successful, establish a mapping relationship between the current source element and the retrieved template style and terminate the subsequent matching process. The semantic role matching strategy specifically includes: Extract the semantic role of the current source element, and filter all template styles in the template style feature library whose semantic role tags are the same as the semantic role of the current source element to form a candidate style set; When the candidate style set contains a single template style, a mapping relationship is established; When the candidate style set contains multiple template styles, calculate the weighted cosine similarity between the effective feature vector of the current source element and the feature vectors of multiple template styles in the candidate style set, and select the template style with the highest similarity value to establish a mapping relationship. The feature similarity matching strategy specifically includes: In the template style feature library, select all template styles whose style type is compatible with the element type of the current source element. Calculate the weighted cosine similarity between the effective feature vector of the current source element and the feature vectors of the selected template styles. Select the template style with the highest similarity value to establish a mapping relationship.

[0011] According to the template-based intelligent document style migration method provided by the present invention, step S4 further includes: S41: Create the target document framework based on the template document, retaining the template document's style definitions, page setup, theme configuration, header and footer, and list definitions; S42: Traverse the source element feature set in the original order of the source document elements, and for each source element, query the corresponding target style identifier according to the mapping decision table; S43: Create a new element in the target document frame that corresponds to the current source element type, and apply the template style corresponding to the target style identifier to the new element; S44: Deeply copy the text content, inline formatting, and special objects of the current source element to the new element. For paragraph elements, it iterates through all text block nodes and preserves character-level inline formatting. For table elements, it copies the row node and cell node structure and preserves the merge attribute. For image objects, it copies the image file and establishes a reference relationship. S45: Complete the migration of all source elements and encapsulate and generate a style migration document.

[0012] A second aspect of the present invention provides a template-based intelligent document style migration system, comprising: Template document parsing module: used to parse the style of template documents and obtain the template style feature library; Source document parsing module: used to parse the content of the source document and obtain the source element feature set; Establishment module: used to establish a mapping relationship between source elements and template styles based on the template style feature library and the source element feature set, and generate a mapping decision table; Reconstruction module: Used to reconstruct the target document based on the mapping decision table to obtain the style migration document.

[0013] A third aspect of the present invention provides a template-based intelligent document style migration device, comprising: A memory and at least one processor, wherein the memory stores instructions; At least one of the processors invokes the instructions in the memory to cause a template-based document style intelligent migration device to perform a template-based document style intelligent migration method as described in any of the preceding claims.

[0014] A fourth aspect of the present invention provides a computer-readable storage medium storing instructions that, when executed by a processor, implement a template-based intelligent document style migration method as described in any of the preceding claims.

[0015] This invention provides a template-based intelligent document style migration method, system, device, and storage medium. First, it deeply analyzes the style definitions of template documents and constructs a template style feature library containing style feature vectors and semantic role tags, laying a precise standard benchmark for subsequent intelligent matching. Second, by employing a layered overlay mechanism to calculate effective feature vectors for source document elements, this invention accurately captures the final appearance of all format levels, including direct formatting, solving the core problem that traditional methods cannot handle directly formatted content. This makes the system applicable to documents with chaotic formatting and extensive use of direct formatting, significantly expanding the applicability of document style conversion. Furthermore, by adopting a layered decision-making mechanism of name matching, semantic role matching, and feature similarity matching, this invention respects the user's explicit intent and can intelligently infer from structural function and visual similarity levels when names do not match. This invention significantly improves the accuracy and robustness of mapping, enabling it to handle more complex and varied real-world scenarios compared to traditional tools that rely on single rules. Furthermore, by introducing weighted cosine similarity calculation and assigning differentiated weights to different format attributes, the system can better capture the essence rather than the form of the format, achieving accurate matching even with subtle differences between the source element and the template style. The invention also preserves the inherent attributes of text such as inline formatting, hyperlinks, and footnotes during style migration through a deep copy mechanism, ensuring the integrity and accuracy of the converted document content. The entire solution reduces manual formatting work, which can take hours or even days, to seconds or minutes, automating document formatting and revolutionizing production efficiency. Simultaneously, the automatic application of standard styles by the program fundamentally eliminates omissions and errors that may result from manual operation, ensuring that all output documents have absolutely standardized and uniform formats. Attached Figure Description

[0016] The accompanying drawings are for illustrative purposes only and are not intended to limit the invention. Throughout the drawings, the same reference numerals denote the same parts. It is obvious that the drawings described below are merely some embodiments of the present invention, and those skilled in the art can obtain other drawings based on these drawings.

[0017] Figure 1 A schematic diagram of a template-based intelligent document style migration method provided in an embodiment of the present invention; Figure 2 This is a schematic diagram of a template-based intelligent document style migration system provided in an embodiment of the present invention. Detailed Implementation

[0018] To enable those skilled in the art to better understand the technical solutions in the embodiments of the present invention, the technical solutions of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, not all embodiments. It should be understood that these descriptions are merely exemplary and are not intended to limit the scope of the present invention. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort should fall within the scope of protection of the present invention.

[0019] Furthermore, descriptions of well-known structures and techniques are omitted in the following description to avoid unnecessarily obscuring the concepts disclosed in this invention.

[0020] In the description of this invention, it should be noted that, unless otherwise explicitly specified and limited, the terms "center," "upper," "lower," "left," "right," "vertical," "horizontal," "inner," and "outer," etc., indicating orientation or positional relationships based on the orientation or positional relationships shown in the accompanying drawings, are only for the convenience of describing the invention and simplifying the description, and do not indicate or imply that the device or element referred to must have a specific orientation, or be constructed and operated in a specific orientation, and therefore should not be construed as a limitation of the invention. Furthermore, the terms "first," "second," and "third" are used for descriptive purposes only and should not be construed as indicating or implying relative importance. The terms "installed," "connected," and "linked" should be interpreted broadly; for example, they can refer to a fixed connection, a detachable connection, or an integral connection; they can refer to a mechanical connection or an electrical connection; they can refer to a direct connection or an indirect connection through an intermediate medium; and they can refer to the internal communication of two components. Those skilled in the art can understand the specific meaning of the above terms in this invention based on the specific circumstances.

[0021] Exemplary embodiments will now be described in detail, examples of which are illustrated in the accompanying drawings. When the following description relates to the drawings, unless otherwise indicated, the same numerals in different drawings denote the same or similar elements. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with the present invention. Rather, they are merely examples of methods and systems consistent with some aspects of the invention as detailed in the appended claims.

[0022] To better understand this invention, the technical terms appearing in the embodiments of this invention will be explained below.

[0023] Source Document: Refers to a user-provided Microsoft Word document (.docx, .doc, etc.) with its original format that needs to be styled. Its formatting may be irregular and may contain a large amount of direct formatting.

[0024] Template Document: Refers to a user-provided Microsoft Word document (.docx, .dotx, etc.) that defines standard style specifications. It contains a series of preset, named styles, such as paragraph styles, character styles, table styles, etc.

[0025] Target Document: Refers to a newly generated Microsoft Word document whose content is the same as the source document after processing by the system of this invention, but whose style has been completely converted to the template document specification.

[0026] Style: refers to the collection of formatting attributes in a Word document, which can be divided into paragraph styles, character styles, table styles, list styles, etc.

[0027] Direct Formatting refers to the operation where users format text, paragraphs, and other elements directly without applying preset styles, such as selecting text and clicking the "bold" button or changing the font size.

[0028] Style Feature Vector: A style feature vector is a multi-dimensional vector created by quantifying or labeling multiple key formatting attributes (such as font, font size, color, weight, line spacing, alignment, etc.) of a style. This vector is used to represent and compare the similarity between different styles.

[0029] Semantic Role: Refers to the logical role that a document content element plays in its context, such as "document main title", "first-level chapter title", "image caption", "body text", etc.

[0030] The embodiments of the present invention are described below with reference to the figures.

[0031] like Figure 1 As shown, the first aspect of the present invention provides a template-based intelligent document style migration method, comprising: S1: Parse the template document to obtain the template style feature library.

[0032] Step S1 further includes: S11: Parse the underlying structure file of the template document to form a set of style definitions including style element nodes and category information.

[0033] Furthermore, this invention first accesses the underlying open XML structure of the template document, locates and reads the style definition file, which stores all style definitions in XML format. This invention traverses each style element node in the file, extracts its type attribute value for each node, and determines the style type based on this attribute value. Specifically, when the type attribute is paragraph, the node is marked as a paragraph style element; when the type attribute is character, it is marked as a character style element; when the type attribute is table, it is marked as a table style element; and when the type attribute is number, it is marked as a list style element. Subsequently, the style identifier attribute is extracted from each style node as a unique identifier, and the value attribute of the style name child node is extracted as the user-visible name. Finally, this invention organizes the extracted style element nodes, corresponding style types, style identifiers, and style names into structured data records, and all records are summarized to form a style definition set.

[0034] S12: Convert the format attributes of multiple style element nodes in the style definition set into style feature vectors.

[0035] In step S12, for each style element node in the style definition set, the present invention locates its contained character attribute child nodes and paragraph attribute child nodes. First, it reads the font tag's Western or Chinese font attribute from the character attribute node to obtain the font family name. Simultaneously, it reads the value attribute of the font size tag to obtain the font size value, reads the existence of the bold tag to obtain the bold identifier, reads the existence of the italic tag to obtain the italic identifier, reads the value attribute of the underline tag to obtain the underline type, and reads the value attribute of the color tag to obtain the color hexadecimal value. Subsequently, it reads the value attribute of the alignment tag from the paragraph attribute node to obtain the alignment method, reads the line spacing value and line spacing rule attribute of the spacing tag to obtain the line spacing value and rule, reads the left indent, right indent, and first-line indent attribute of the indentation tag to obtain the indentation distance, and reads the paragraph before and after attributes of the spacing tag to obtain the paragraph spacing.

[0036] Subsequently, the present invention divides the font size value by 2 to convert it to points, divides the indentation and spacing values ​​by 20 to convert them to points, and maps all extracted format attributes to key-value pairs according to predefined key names. For example, the font size is mapped to the font size point value key corresponding to 22.0, and the alignment is mapped to the alignment key corresponding to the center value.

[0037] When a style element node has a style-based child node, its value attribute is extracted to obtain the parent style identifier. The feature vector corresponding to the parent style identifier is found in the processed styles. The parent style feature vector is copied to the base feature vector. Then, the key-value pairs of the current node are used to overwrite the keys with the same name in the base feature vector one by one, and finally the complete style feature vector of the current style element node is formed.

[0038] S13: Based on the rule scoring mechanism, infer semantic role labels for multiple style element nodes in the style definition set.

[0039] In step S13, the present invention pre-establishes a role definition library, which includes predefined semantic roles such as document main title, first-level headings, second-level headings, body text, image captions, and table captions. Each role is associated with multiple recognition rules, which are divided into two categories: name rules and feature rules. Specifically, name rules are defined in the form of regular expressions. For example, the name rule for the document main title role includes a matching pattern of title or heading and assigns a weight of 100 points, and a matching pattern of the words "document" and "title" and assigns a weight of 80 points. Feature rules are defined in the form of functions. For example, the feature rule for the document main title role includes a function to check whether the font size is the maximum value among all paragraph styles, and a function to check whether the alignment is centered. When both functions are satisfied, a weight of 60 points is assigned.

[0040] After establishing the rule base, this invention extracts the style name and style feature vector for each style element node in the style definition set. Then, it performs regular expression matching between the style name and the name rules of all predefined semantic roles in the role definition base. When a match is successful, the weight score of the corresponding rule is added to the score of the role.

[0041] Then, the feature detection function is called, taking the style feature vector as input. The function reads attribute values ​​such as font size, alignment, etc. from the vector and performs conditional judgment. If the judgment is successful, the weight score of the corresponding rule is added to the score of the character.

[0042] After traversing all predefined semantic roles, this invention finds the role with the highest cumulative score. When the highest score exceeds a preset confidence threshold, the role is assigned as its semantic role label to the current style element node; otherwise, it is marked as an unknown role.

[0043] S14: Summarize the style definition set, style feature vector, and semantic role tags to obtain the template style feature library.

[0044] This invention uses the style identifier of each style element node in the style definition set as the primary key, and uses the corresponding style type, style name, style feature vector generated in step S12, and semantic role label inferred in step S13 as associated attributes to construct a data structure.

[0045] In addition, this invention establishes three types of index structures: the first type is a hash index based on style name to support precise queries; the second type is a grouped index based on style type to support type filtering; and the third type is a grouped index based on semantic role tags to support role retrieval. Finally, all data structures and index structures are integrated to form a template style feature library.

[0046] S2: Parse the source document to obtain the set of source element features.

[0047] Step S2 further includes: S21: Traverse the main content of the source document, identify paragraph elements and table elements in the source document, and obtain a set of source document elements including multiple elements.

[0048] In step S21, the present invention accesses the underlying open XML structure of the source document, locates and reads the main node in the document's main file. After reading, the present invention sequentially traverses all child nodes under the main node and identifies the node tag type. When a paragraph tag is encountered, the node is marked as a paragraph element; when a table tag is encountered, the node is marked as a table element.

[0049] This invention assigns a unique element identifier to each identified element, records its position index in the document, and organizes the element node, element type, and position information into data records. Finally, all records are summarized in the original document order to form a source document element set.

[0050] S22: Extract the text content and element type for each element in the source document element set, and calculate the effective feature vector of the current element after superimposing all format levels.

[0051] In step S22, the calculation of the effective feature vector adopts a layered stacking mechanism, which further includes: S221: Obtain the feature vector of the document's default style as the initial vector.

[0052] In step S221, the present invention searches for style element nodes with the style identifier set to the default value in the style definition file of the source document. This node defines the default paragraph style of the document. Subsequently, the present invention parses the character attribute child nodes and paragraph attribute child nodes of this node according to the method in step S12, extracts format attributes such as font family, font size, bold, italic, alignment, and line spacing, performs unit conversion, maps them to key-value pairs, and constructs the feature vector of the default style as the initial vector.

[0053] S222: When a named style is applied to the source element, extract the feature vector of the named style, and use the attribute values ​​of the feature vector of the named style to overwrite the corresponding fields in the initial vector to obtain the first optimized vector.

[0054] In step S222, the present invention checks whether the source element node contains paragraph attribute child nodes. If it does, it searches for paragraph style tags in those child nodes. When a paragraph style tag exists, its value attribute is extracted as the applied style name. Subsequently, the present invention searches for style element nodes in the style definition of the source document whose style identifier is equal to the applied style name, and parses the style node according to the method in step S12 to generate a feature vector of the named style.

[0055] After generating the named style feature vector, this invention deeply copies the initial vector to the first optimized vector, and then iterates through all key-value pairs in the named style feature vector, writing the attribute value corresponding to each key into the same key in the first optimized vector to achieve attribute value overwriting.

[0056] S223: Parse the paragraph attribute child nodes and character attribute child nodes in the source element node, extract the directly set format attributes, and overwrite the corresponding fields in the first optimization vector with the attribute values ​​of the directly set format attributes to obtain the second optimization vector.

[0057] In step S223, this invention parses the paragraph attribute child nodes in the source element nodes and the character attribute child nodes in the text block nodes. It reads the directly set attribute values ​​such as alignment tags, spacing tags, and indentation tags from the paragraph attributes, and the directly set attribute values ​​such as font tags, font size tags, bold tags, and color tags from the character attributes. This invention performs unit conversion on these attribute values ​​and maps them to key-value pairs to form a direct formatting attribute set. Subsequently, this invention deeply copies the first optimized vector to a second optimized vector, traverses all key-value pairs in the direct formatting attribute set, and writes the attribute value corresponding to each key into the same-name key in the second optimized vector, completing the second overwrite.

[0058] S224: When a paragraph element contains multiple text blocks with different formats, the length of the text covered by the multiple text blocks is counted, the format attribute of the text block with the longest text length is selected as the representative character format of the paragraph, and the representative character format is merged into the second optimization vector to obtain the effective feature vector of the current source element.

[0059] Furthermore, this invention traverses all text block child nodes under the paragraph element node, extracts the text content tags contained in each text block node, counts the character length of the text content, and extracts the character attribute child nodes of the text block node and parses their format attributes.

[0060] Subsequently, this invention compares the character lengths of all text blocks, selects the text block with the longest character length, and extracts the font family, font size, bold, italic, and other attributes defined in the character attributes of this text block as representative character formats. Finally, this invention writes the attribute values ​​of the representative character formats into the character attribute key of the second optimization vector to form the effective feature vector of the current source element.

[0061] S23: Infer semantic roles based on the position information, format features, and content patterns of each element in the source document element set.

[0062] In step S23, for each element in the source document element set, the present invention obtains its position index and effective feature vector in the document. When the position index is 0 and the element type is paragraph, the present invention marks the semantic role of the element as the main title of the document. Subsequently, the present invention extracts the text content of the element, uses regular expressions to match the pattern starting with the image number, and marks the semantic role as the image caption when the match is successful; uses regular expressions to match the pattern starting with the table number, and marks the semantic role as the table caption when the match is successful; uses regular expressions to match the pattern starting with the number or letter number, and marks the semantic role as a list item when the match is successful.

[0063] Then, this invention extracts the font size attribute from the effective feature vector, calculates the ratio of the font size of the element to its preceding and following elements, and marks the semantic role as a chapter title when the ratio is greater than 1.3, the bold attribute in the effective feature vector is true, and the paragraph spacing attribute is greater than 12. Finally, this invention marks the semantic role of elements that do not meet the above conditions as body text.

[0064] S24: Summarize the source document element set, text content, element type, effective feature vector, and semantic role of the source element feature set.

[0065] In step S24, the present invention uses the element identifier of each element in the source document element set as the primary key, and associates and binds the corresponding text content, element type, effective feature vector calculated in step S22, and semantic role inferred in step S23 to construct a data record. All data records are organized according to the original order of elements in the document to form a source element feature set.

[0066] S3: Based on the template style feature library and the source element feature set, establish a mapping relationship between source elements and template styles based on a hierarchical decision-making mechanism, and generate a mapping decision table.

[0067] The hierarchical decision-making mechanism in step S3 includes multiple matching strategies, specifically: name matching strategy, semantic role matching strategy, and feature similarity matching strategy.

[0068] The name matching strategy specifically includes: The system checks whether a named style is explicitly applied to the current source element. If a named style is applied, the applied style name is extracted. The system then searches the template style feature library for template styles whose style names are the same as the applied style names and whose style types are compatible with the element type of the current source element. If the search is successful, a mapping relationship is established between the current source element and the retrieved template style, and the subsequent matching process is terminated.

[0069] Furthermore, in the name matching strategy, this invention first detects whether the source element node contains paragraph attribute child nodes, and then searches for the existence of paragraph style tags in those child nodes. If the paragraph style tag does not exist, it is determined that the source element has not applied a named style, and the name matching strategy is skipped. If the paragraph style tag exists, its value attribute is extracted as the applied style name.

[0070] Subsequently, this invention searches for template styles whose style names are equal to the applied style names in the name index of the template style feature library, ignoring case differences and leading and trailing whitespace characters in the name strings during the search.

[0071] Subsequently, this invention extracts the style type attribute of the queried template style, performs compatibility verification between the style type and the element type of the source element, and determines compatibility when the source element type is paragraph and the template style type is paragraph style, and when the source element type is table and the template style type is table style.

[0072] After the compatibility check is passed, the present invention creates a new record in the mapping decision table, records the element identifier of the source element and the style identifier of the queried template style, forms a mapping relationship pair, sets the matching completion flag of the source element to true, and terminates the subsequent strategy execution for the source element.

[0073] The semantic role matching strategy specifically includes: Extract the semantic role of the current source element, and filter all template styles in the template style feature library whose semantic role tags are the same as those of the current source element to form a candidate style set. When the candidate style set contains a single template style, establish a mapping relationship. When the candidate style set contains multiple template styles, calculate the weighted cosine similarity between the effective feature vector of the current source element and the feature vectors of multiple template styles in the candidate style set, and select the template style with the highest similarity value to establish a mapping relationship.

[0074] Furthermore, in the semantic role matching strategy, this invention checks the matching completion flag of the source element. When the flag is true, the strategy is skipped; when the flag is false, the semantic role attribute of the source element is extracted. Subsequently, this invention retrieves all template style records whose semantic role tags are equal to the semantic role attribute of the source element from the role index of the template style feature library, and organizes the retrieval results into a candidate style set.

[0075] After obtaining the candidate style set, this invention counts the number of template styles in the candidate style set. When the number is 0, the semantic role matching is determined to be unsuccessful, and the feature similarity matching strategy is continued. When the number is 1, the style identifier of the unique template style is extracted, a mapping relationship pair between the source element identifier and the style identifier is created in the mapping decision table, and the matching completion flag of the source element is set to true. When the number is greater than 1, this invention enters the sub-decision process, extracts the effective feature vector of the source element, extracts its style feature vector for each template style in the candidate style set, and calculates the weighted cosine similarity value between the effective feature vector of the source element and the feature vector of the current template style.

[0076] Finally, this invention iterates through all calculation results, finds the maximum similarity value and the corresponding template style, creates a mapping relationship between the source element identifier and the template style identifier in the mapping decision table, and sets the matching completion flag of the source element to true.

[0077] The feature similarity matching strategy specifically includes: filtering all template styles in the template style feature library whose style type is compatible with the element type of the current source element; calculating the weighted cosine similarity between the effective feature vector of the current source element and the feature vectors of the multiple selected template styles; and selecting the template style with the highest similarity value to establish a mapping relationship.

[0078] Furthermore, in the feature similarity matching strategy, this invention checks the matching completion flag of the source element. When the flag is true, the strategy is skipped; when the flag is false, the element type attribute of the source element is extracted. Specifically, this invention retrieves all template styles whose style type is compatible with the source element type from the type index of the template style feature library. When the source element type is paragraph, paragraph styles are retrieved; when the source element type is table, table styles are retrieved. The retrieval results are then organized into a set of type-compatible styles.

[0079] Subsequently, this invention extracts the effective feature vector of the source element. For each template style in the type-compatible style set, it extracts its style feature vector and calculates the weighted cosine similarity value between the effective feature vector of the source element and the feature vector of the current template style. After traversing all calculation results, this invention finds the maximum similarity value and the corresponding template style, and creates a mapping relationship between the source element identifier and the template style identifier in the mapping decision table.

[0080] Furthermore, in the aforementioned weighted cosine similarity, this invention predefines a feature weight vector, which assigns a weight value to each format attribute key: font size key is assigned a weight of 1.0, bold key is assigned a weight of 0.8, alignment key is assigned a weight of 0.9, line spacing key is assigned a weight of 0.7, color key is assigned a weight of 0.3, and underline type key is assigned a weight of 0.2.

[0081] Subsequently, this invention extracts attribute values ​​from the source element's valid feature vector and the template style feature vector in the same key order, constructing two numerical sequences. When the attribute value is a Boolean type, true values ​​are converted to 1, and false values ​​are converted to 0; when the attribute value is an enumeration type, center alignment is mapped to 2, left alignment to 1, right alignment to 3, and justified alignment to 4.

[0082] In the calculation, the weighted point accumulator is initialized to 0. It iterates through each position index of the two numerical sequences, multiplies the value of the current position of the first sequence by the value of the current position of the second sequence, multiplies it by the weight value of the corresponding position in the feature weight vector, and accumulates the result to the weighted point accumulator.

[0083] Subsequently, this invention calculates the weighted modulus lengths of the two numerical sequences. For the first sequence, it iterates through each position index, multiplies the square of the current position value by the corresponding weight value, sums the results, and takes the square root of the sum to obtain the first weighted modulus length. After obtaining the first weighted modulus length, the same calculation is performed on the second sequence to obtain the second weighted modulus length. Finally, this invention divides the value of the weighted point accumulator by the product of the first and second weighted moduli lengths to obtain the weighted cosine similarity value.

[0084] S4: Reconstruct the target document based on the mapping decision table to obtain the style migration document.

[0085] Step S4 further includes: S41: Create a target document framework based on the template document, preserving the template document's style definitions, page setup, theme configuration, header and footer, and list definitions.

[0086] In step S41, the present invention first creates a copy of the template document in memory. Then, the present invention accesses the document body file of the copy file, locates the main node, and deletes all paragraph child nodes and table child nodes under that node, clearing the document body content. At the same time, the present invention retains the style definition file, document settings file, theme definition file, header file, footer file, and numbering definition file in the copy file without modification, forming the target document framework.

[0087] S42: Traverse the source element feature set in the original order of the source document elements, and for each source element, query the corresponding target style identifier according to the mapping decision table.

[0088] Furthermore, in step S42, the present invention extracts the element identifiers of the source elements one by one according to the element order recorded in the source element feature set. For each element identifier, the present invention queries the target style identifier corresponding to the element identifier in the mapping decision table, and records the query result as the target style identifier of the current source element.

[0089] S43: Create a new element in the target document frame that corresponds to the current source element type, and apply the template style corresponding to the target style identifier to the new element.

[0090] In step S43, the present invention extracts the element type attribute of the current source element. When the element type is paragraph, the present invention creates a new paragraph child node under the main node of the target document frame; when the element type is table, the present invention creates a new table child node under the main node of the target document frame.

[0091] After executing the above process, the present invention inserts paragraph attribute sub-nodes or table attribute sub-nodes into the newly created paragraph sub-nodes or table sub-nodes, inserts paragraph style tags or table style tags into the attribute sub-nodes, and sets the value attribute of the tags to the target style identifier queried in step S42, thereby completing the application of the template style.

[0092] S44: Deeply copies the text content, inline formatting, and special objects of the current source element to the new element. For paragraph elements, it iterates through all text block nodes and preserves character-level inline formatting. For table elements, it copies the row and cell node structures and preserves merge attributes. For image objects, it copies the image file and establishes a reference relationship.

[0093] Furthermore, when the current source element type is paragraph, the present invention traverses all text block child nodes under the source element node. After traversal, for each text block child node, the present invention creates a corresponding new text block child node in the new paragraph node of the target document, extracts the text string from the text content tag of the source text block, and writes the string into the text content tag of the new text block.

[0094] Subsequently, this invention extracts the character attribute child nodes of the source text block. These child nodes contain inline formatting definitions such as bold tags, italic tags, underline tags, hyperlink tags, and footnote citation tags. This invention completely copies these character attribute child nodes to the character attribute positions of the new text block, ensuring that the inline formatting is not covered by paragraph styles.

[0095] When the current source element type is a table, this invention iterates through all row child nodes under the source table node, and creates a corresponding new row child node in the new table node of the target document for each row child node. Specifically, this invention iterates through all cell child nodes under each source row child node, creates a corresponding new cell child node in the new row child node for each cell child node, extracts the cross-column merge attribute and cross-row merge attribute of the source cell, and copies these attribute values ​​to the new cell node. This invention recursively iterates through the paragraph child nodes contained in the source cell, and copies the paragraph content and inline formatting to the paragraph in the new cell according to the paragraph text block copying process.

[0096] When an image object is embedded in a source element node, this invention extracts the relationship identifier of the image object, searches for the image file path corresponding to the identifier in the relationship file of the source document, copies the image file under the media directory of the source document to the media directory of the target document, creates a new relationship record in the relationship file of the target document pointing to the copied image file, inserts an image reference tag in the node of the new element and sets its relationship identifier to the newly created relationship identifier.

[0097] S45: Complete the migration of all source elements and encapsulate and generate a style migration document.

[0098] In step S45, after traversing all source elements in the source element feature set, the present invention checks all newly created element nodes under the main node of the target document framework. Specifically, the present invention organizes all components in the target document framework, such as style definition files, document body files, relationship files, and media files, according to the directory structure of the Open XML specification, uses a compression algorithm to package all files into a single compressed file, sets the extension of the compressed file to the document format suffix, and generates a style migration document.

[0099] like Figure 2 As shown, a second aspect of the present invention provides a template-based intelligent document style migration system, comprising: Template document parsing module 100: Used to parse the style of the template document and obtain the template style feature library; Source document parsing module 200: Used to parse the content of the source document and obtain the source element feature set; Establishment module 300: used to establish a mapping relationship between source elements and template styles based on the template style feature library and the source element feature set, and generate a mapping decision table; Reconstruction module 400: Used to reconstruct the target document according to the mapping decision table to obtain the style migration document.

[0100] The present invention also provides a template-based intelligent document style migration device, comprising: a memory and at least one processor, wherein the memory stores instructions; at least one processor invokes the instructions in the memory to cause the template-based intelligent document style migration device to perform a template-based intelligent document style migration method as described in any of the preceding claims.

[0101] A fourth aspect of the present invention provides a computer-readable storage medium storing instructions that, when executed by a processor, implement a template-based intelligent document style migration method as described in any of the preceding claims.

[0102] Based on the present invention, a template-based intelligent document style migration method, system, device, and storage medium is proposed. The present invention proposes a method for feature extraction and vectorization of directly formatted content, which can parse unstyled, directly formatted document elements and generate style feature vectors for quantitative comparison in real time, which is the basis for realizing intelligent conversion of any document.

[0103] Secondly, this invention proposes an intelligent style mapping method that integrates multiple strategies. The core of the method is a multi-rule decision engine, which integrates three strategies in order of priority: precise matching of style names, semantic role logical matching, and fuzzy matching of style feature vector similarity. This multi-level decision mechanism greatly improves the accuracy and robustness of the mapping.

[0104] In addition, this invention proposes a document style migration system architecture that includes parsing, mapping, and generation modules, clearly defining the complete processing flow from input to output, including the construction of a template style library, structured parsing of source document elements, core intelligent mapping decisions, and the reconstruction and generation of the final document.

[0105] Compared to traditional manual editing, this invention reduces work time from hours or even days to seconds or minutes, achieving one-click document formatting and revolutionizing productivity. Secondly, through its intelligent mapping engine, particularly its comprehensive judgment of content semantics and style features, this invention can handle extremely complex source document formats. Its conversion accuracy far surpasses existing simple tools that rely on styles with the same name, achieving near-human level precision or even exceeding human accuracy. Thirdly, this invention does not require source documents to use standardized styles; it is equally effective for documents filled with direct formatting and chaotic formats, solving a common pain point in the industry and possessing strong practical application value. Furthermore, since all styles come from a unique standard template and are automatically applied by the program, it avoids the oversights and errors that may arise from manual operation, ensuring the absolute standardization and uniformity of all output documents.

[0106] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the embodiments of the present invention, and are not intended to limit them. Although the present invention has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features; and these modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of the present invention. Any changes or substitutions that can be easily conceived by those skilled in the art within the scope of the technology disclosed in the present invention should be included within the protection scope of the present invention.

Claims

1. A template-based intelligent document style migration method, characterized in that, Includes the following steps: S1: Parse the template document to obtain the template style feature library; S2: Parse the source document to obtain a set of source element features; S3: Based on the template style feature library and the source element feature set, establish a mapping relationship between source elements and template styles based on a hierarchical decision mechanism, and generate a mapping decision table; S4: Reconstruct the target document based on the mapping decision table to obtain the style migration document.

2. The template-based intelligent document style migration method according to claim 1, characterized in that, Step S1 further includes: S11: Parse the underlying structure file of the template document to form a set of style definitions including style element nodes and category information; S12: Convert the format attributes of multiple style element nodes in the style definition set into style feature vectors; S13: Based on the rule-based scoring mechanism, infer semantic role labels for multiple style element nodes in the style definition set; S14: Summarize the style definition set, style feature vector, and semantic role tags to obtain the template style feature library.

3. The template-based intelligent document style migration method according to claim 1, characterized in that, Step S2 further includes: S21: Traverse the main content of the source document, identify paragraph elements and table elements in the source document, and obtain a set of source document elements including multiple elements; S22: Extract the text content and element type for each element in the source document element set, and calculate the effective feature vector of the current element after superimposing all format levels; S23: Infer semantic roles based on the position information, format features, and content patterns of each element in the source document element set; S24: Summarize the source document element set, text content, element type, effective feature vector, and semantic role of the source element feature set.

4. The template-based intelligent document style migration method according to claim 3, characterized in that, The calculation of the effective feature vector in step S22 adopts a layered stacking mechanism, which further includes: S221: Obtain the feature vector of the document's default style as the initial vector; S222: When a named style is applied to the source element, extract the feature vector of the named style, and overwrite the corresponding field in the initial vector with the attribute values ​​of the feature vector of the named style to obtain the first optimized vector. S223: Parse the paragraph attribute child nodes and character attribute child nodes in the source element node, extract the directly set format attributes, and overwrite the corresponding fields in the first optimization vector with the attribute values ​​of the directly set format attributes to obtain the second optimization vector; S224: When a paragraph element contains multiple text blocks with different formats, the length of the text covered by the multiple text blocks is counted, the format attribute of the text block with the longest text length is selected as the representative character format of the paragraph, and the representative character format is merged into the second optimization vector to obtain the effective feature vector of the current source element.

5. The template-based intelligent document style migration method according to claim 1, characterized in that, The hierarchical decision-making mechanism in step S3 includes multiple matching strategies, specifically: name matching strategy, semantic role matching strategy, and feature similarity matching strategy.

6. The template-based intelligent document style migration method according to claim 5, characterized in that, The name matching strategy specifically includes: Detect whether the current source element has an explicitly applied named style. If a named style is applied, extract the applied style name, search the template style feature library for template styles with the same style name as the applied style name and whose style type is compatible with the element type of the current source element. If the search is successful, establish a mapping relationship between the current source element and the retrieved template style and terminate the subsequent matching process. The semantic role matching strategy specifically includes: Extract the semantic role of the current source element, and filter all template styles in the template style feature library whose semantic role tags are the same as the semantic role of the current source element to form a candidate style set; When the candidate style set contains a single template style, a mapping relationship is established; When the candidate style set contains multiple template styles, calculate the weighted cosine similarity between the effective feature vector of the current source element and the feature vectors of multiple template styles in the candidate style set, and select the template style with the highest similarity value to establish a mapping relationship. The feature similarity matching strategy specifically includes: In the template style feature library, select all template styles whose style type is compatible with the element type of the current source element. Calculate the weighted cosine similarity between the effective feature vector of the current source element and the feature vectors of the selected template styles. Select the template style with the highest similarity value to establish a mapping relationship.

7. The template-based intelligent document style migration method according to claim 1, characterized in that, Step S4 further includes: S41: Create the target document framework based on the template document, retaining the template document's style definitions, page setup, theme configuration, header and footer, and list definitions; S42: Traverse the source element feature set in the original order of the source document elements, and for each source element, query the corresponding target style identifier according to the mapping decision table; S43: Create a new element in the target document frame that corresponds to the current source element type, and apply the template style corresponding to the target style identifier to the new element; S44: Deeply copy the text content, inline formatting, and special objects of the current source element to the new element. For paragraph elements, it iterates through all text block nodes and preserves character-level inline formatting. For table elements, it copies the row node and cell node structure and preserves the merge attribute. For image objects, it copies the image file and establishes a reference relationship. S45: Complete the migration of all source elements and encapsulate and generate a style migration document.

8. A template-based intelligent document style migration system, characterized in that, include: Template document parsing module: used to parse the style of template documents and obtain the template style feature library; Source document parsing module: used to parse the content of the source document and obtain the source element feature set; Establishment module: used to establish a mapping relationship between source elements and template styles based on the template style feature library and the source element feature set, and generate a mapping decision table; Reconstruction module: Used to reconstruct the target document based on the mapping decision table to obtain the style migration document.

9. A template-based intelligent document style migration device, characterized in that, include: A memory and at least one processor, wherein the memory stores instructions; At least one of the processors invokes the instructions in the memory to cause a template-based document style intelligent migration device to perform a template-based document style intelligent migration method as described in any one of claims 1 to 7.

10. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores instructions that, when executed by a processor, implement a template-based intelligent document style migration method as described in any one of claims 1 to 7.