Automated report generation system and method for multimodal template free editing and parsing
By constructing a template structure relationship diagram and a business data hierarchy diagram, and combining edit distance and topology diffusion iteration, the problems of fragmented template tags and disordered layout in traditional automated report generation systems have been solved. This has enabled accurate mapping of multimodal data and anti-fragmentation layout, thereby improving the accuracy and quality of report generation.
Patent Information
- Application Number
- CN202610352221.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-03-20
- Publication Date
- 2026-06-26
AI Technical Summary
Traditional automated report generation systems suffer from problems when processing multidimensional structured data, such as fragmented underlying tags in template documents, inconsistent data and layout container levels, and layout errors when dynamically writing multimodal data, resulting in poor generation quality.
By extracting the source text nodes and container nodes of the template document, a template structure relationship diagram and a business data hierarchy diagram are constructed. Combining the edit distance between keys and placeholders and topological diffusion iteration, the final matching probability matrix between keys and placeholders is calculated, and anti-breakage typesetting tags are generated to achieve accurate mapping and dynamic injection of business data.
It achieves precise mapping between complex heterogeneous data and template placeholders, avoids chart truncation across pages, and significantly improves the accuracy of automated report generation and layout quality.
Smart Images

Figure CN122287564A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of big data service technology, specifically to an automated report generation system and method for freely editing and parsing multimodal templates. Background Technology
[0002] Automated report generation systems are often used as core components of information platforms to process heterogeneous, multi-dimensional structured business data. In enterprise information scenarios, it is typically necessary to automatically write multi-dimensional structured data (such as JSON data packets containing equipment images and fault lists) returned by interfaces of independent business systems into preset office document templates to generate standardized reports.
[0003] Traditional automated report generation relies heavily on regular expressions to perform pure string search and replace on the underlying content of documents, which has significant technical flaws, resulting in poor automated report generation quality. First, users freely format templates, fragmenting the source text nodes, making it difficult for the regular expression engine to locate data writing points due to its reliance on continuous strings. Second, it's difficult to directly map multi-level English keys in external data to Chinese placeholders in the template, and the inconsistent depth of the data and the layout container can easily lead to mismatches. Third, traditional solutions only perform pure text assignments; when dynamically writing multimodal data, they cannot perceive the logical integrity of the container, easily causing layout errors such as long tables being truncated across pages and images and captions being separated. Summary of the Invention
[0004] To address the technical problem of unsatisfactory results in existing automated report generation, the present invention aims to provide an automated report generation system and method with freely editable and parsed multimodal templates. The specific technical solution adopted is as follows: An automated report generation method for freely editing and parsing multimodal templates, including: Extract the source text nodes and container nodes at the bottom layer of the template document and concatenate them into a continuous plain text string; extract the placeholders and their corresponding text node sets from the plain text string, and backtrack the container nodes to construct a template structure relationship diagram; extract the key names of external business data corresponding to business values and nested paths, and construct a business data hierarchy diagram. An initial similarity matrix is constructed based on the edit distance between keys and placeholders; the template structure graph and the business data hierarchy graph are transformed into column-normalized adjacency matrices respectively; topological diffusion iteration is performed in combination with the initial similarity matrix to calculate the final matching probability matrix between keys and placeholders and determine all mapping combinations between keys and placeholders; whether to generate anti-breakage layout tags is determined based on the entity type of the key and the container node type of the placeholder in the mapping combination. Based on the mapping combination, the business value corresponding to the key name is written into the first source text node in the cleaned placeholder text node set. If an anti-break typesetting tag is generated, the anti-break typesetting tag is attached to the attribute subtree of the container node to which the first source text node belongs, and the serialized output report file is generated.
[0005] Furthermore, the method for concatenating continuous plain text strings includes: The internal text of the source text nodes is sequentially concatenated. During the concatenation process, if adjacent source text nodes belong to different container nodes, a virtual separator is inserted into the concatenated character sequence to obtain a continuous plain text string.
[0006] Furthermore, the method for obtaining the placeholder and its corresponding set of text nodes includes: Establish a dictionary to record character indexes, source text node addresses, and container paths; extract initial placeholders from plain text strings using regular expressions; use the dictionary to determine all source text nodes corresponding to the characters of the initial placeholders in the plain text strings; when all source text nodes have the same container path, use the initial placeholder as a placeholder, and use the set of all source text nodes as the set of text nodes corresponding to the placeholder.
[0007] Furthermore, the method for obtaining the template structure relationship diagram includes: For each set of text nodes corresponding to a placeholder, take any source text node within it as the starting point for backtracking, backtrack upwards in the document object model tree of the template document, and take the node corresponding to the first paragraph label or table row label as the container node. Placeholders and container nodes are used as graph nodes. The nesting relationship between container nodes and placeholders is used to determine the included directed edges. The order relationship of sibling container nodes in the bottom layer of the template document is used to determine the adjacent directed edges. The template structure relationship graph is then integrated and constructed.
[0008] Furthermore, the method for obtaining the business data hierarchy diagram includes: The key names are used as graph nodes. Directed edges are determined based on the nesting relationship between the key names. The graph nodes and directed edges are associated and assembled to integrate and construct a business data hierarchical graph.
[0009] Furthermore, the method for obtaining the column-normalized adjacency matrix includes: The template structure relationship graph and the business data hierarchy graph are used as target graphs in sequence; graph nodes with non-zero out-degree are extracted from the target graphs, and the transition probability of each graph node is evenly distributed to all its directed edges according to the out-degree of the graph node; dangling graph nodes with zero out-degree are extracted from the target graphs, and virtual directed edges pointing to all graph nodes with evenly balanced transition probabilities are added to the dangling graph nodes; the transition probabilities of each graph node are summarized to generate a column-normalized adjacency matrix with a column sum of 1.
[0010] Furthermore, the method for obtaining the final matching probability matrix includes: Based on the number of graph nodes in the template structure relationship graph and the business data hierarchy graph, the matrix dimension is determined and a null zero matrix is constructed; the initial similarity matrix is used to assign values to the null zero matrix, and the matching probability matrix is initialized. The initial similarity matrix is weighted using preset topological weights to obtain the literal baseline component; the initial matching probability matrix, the column normalized adjacency matrix of the business data hierarchy graph, and the transpose of the column normalized adjacency matrix of the template structure relationship graph are multiplied together, and the result is weighted using preset diffusion weights to obtain the structural diffusion component; the preset topological weights and preset diffusion weights are complementary. The process iterates continuously to obtain the structural diffusion component at each iteration depth, and then fuses the literal reference component with the structural diffusion component to determine the matching probability matrix at each iteration depth. Based on the difference between the matching probability matrices at adjacent iteration depths, it is determined whether the iteration has converged, and the matching probability matrix corresponding to the first convergence is taken as the final matching probability matrix.
[0011] Furthermore, the method for obtaining the mapping combination includes: In each column of the final matching probability matrix, the maximum element value greater than the preset effective benchmark threshold is extracted, and the key name and placeholder corresponding to the maximum element value are used as a mapping combination.
[0012] Furthermore, the determination of whether to generate anti-breakage typesetting labels includes: The anti-break typesetting tags include paragraph same-page attribute tags and inline anti-pagination attribute tags. For each mapping combination, if the entity type of the key name is an image entity and the container node type of the placeholder is a paragraph tag, then a paragraph same-page attribute tag is generated; if the entity type of the key name is a list entity and the container node type of the placeholder is a table row tag, then an inline anti-pagination attribute tag is generated; otherwise, no anti-break typesetting tags are generated.
[0013] An automated report generation system for free editing and parsing of multimodal templates, the system comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the computer program to implement the steps of the automated report generation method for free editing and parsing of multimodal templates.
[0014] The present invention has the following beneficial effects: This invention first extracts the source text nodes and container nodes at the bottom layer of the template document and concatenates them into a continuous plain text string. This prepares for extracting placeholders and their corresponding text node sets from the plain text string. Then, it backtracks the container nodes to construct a template structure relationship graph representing the spatial nesting logic of the template document. Next, it extracts the business values and nesting paths corresponding to the key names of external business data to construct a business data hierarchy graph representing the spatial nesting logic of the business data. This prepares for subsequent alignment of the document's spatial nesting logic with the logical hierarchy of external business data, mapping business data to placeholders for automatic report generation. Then, based on the edit distance between key names and placeholders, it constructs an initial similarity matrix representing literal similarity. Finally, it transforms the template structure relationship graph and the business data hierarchy graph into column normalization. The adjacency matrix, combined with the initial similarity matrix, performs topological diffusion iteration, fusing literal and topological hierarchical features to calculate the final matching probability matrix between keys and placeholders. It also determines all mapping combinations for one-to-one mapping between keys and placeholders, helping to achieve accurate mapping between complex heterogeneous data (business data) and template placeholders. Furthermore, it determines whether to generate anti-fragmentation tags based on the entity type of the key and the container node type of the placeholder in the mapping combination. Finally, based on the mapping combination, the business value corresponding to the key is written into the first source text node in the cleaned placeholder text node set. If an anti-fragmentation tag is generated, it is attached to the attribute subtree of the container node to which the first source text node belongs to avoid chart truncation across pages, and the report file is serialized and output. This invention overcomes parsing failures caused by fragmented template underlying tags; it fuses literal and topological hierarchical features to achieve accurate mapping between complex heterogeneous data (business data) and template placeholders; and it dynamically injects anti-fragmentation tags for multimodal data, solving the problem of chart truncation across pages, significantly improving the accuracy and layout quality of automated report generation. Attached Figure Description
[0015] To more clearly illustrate the technical solutions and advantages in the embodiments of the present invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0016] Figure 1 This is a flowchart of an automated report generation method for free editing and parsing of multimodal templates, provided as an embodiment of the present invention. Detailed Implementation
[0017] To further illustrate the technical means and effects adopted by the present invention to achieve its intended purpose, the following, in conjunction with the accompanying drawings and preferred embodiments, details the specific implementation, structure, features, and effects of an automated report generation system and method for free editing and parsing of multimodal templates proposed according to the present invention. In the following description, different "one embodiment" or "another embodiment" do not necessarily refer to the same embodiment. Furthermore, specific features, structures, or characteristics in one or more embodiments can be combined in any suitable form.
[0018] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as commonly understood by one of ordinary skill in the art to which this invention pertains.
[0019] The following description, in conjunction with the accompanying drawings, details the specific scheme of the automated report generation system and method for free editing and parsing of multimodal templates provided by this invention.
[0020] Please see Figure 1 The diagram illustrates a flowchart of an automated report generation method for free editing and parsing of multimodal templates, provided by an embodiment of the present invention, specifically including: Step S1: Extract the source text nodes and container nodes at the bottom layer of the template document and concatenate them into a continuous plain text string; extract the placeholders in the plain text string and their corresponding text node sets, and backtrack the container nodes to construct a template structure relationship diagram; extract the key names of external business data corresponding to business values and nested paths, and construct a business data hierarchy diagram.
[0021] In one embodiment of the present invention, a static template document file (such as a commonly used .docx file) uploaded by the user is first obtained, the template document file is decompressed, the underlying Extensible Markup Language (XML) code file (such as document.xml) carrying the main content is extracted from the decompressed file directory, and the Document Object Model (DOM) parser is called to parse the XML code file into a tree-like hierarchical document object model tree. Then, a depth-first search (DFS) algorithm is used to perform a full scan of the document object model tree. During the traversal, two types of core nodes are identified by their tag names: the first type is the source text node that carries the text content (e.g., <w:t>The second category is container nodes that carry the layout structure (such as paragraphs). <w:p>or table row <w:tr>Label).
[0022] For the extracted source text nodes, read the fragmented text contained within them to prepare for subsequent sequential concatenation to obtain plain text strings for extracting placeholders; placeholders are markers reserved by users in template documents, usually with specific custom formats; only by extracting the placeholders can they be aligned with the key names in external business interfaces to automatically generate reports.
[0023] Because users may freely modify the formatting within the template (such as adjusting the font), the originally complete placeholder text will be truncated into multiple fragments at the XML level. <w:t>Fragments, therefore character splicing is required; and different paragraphs ( <w:p>) or table row ( <w:tr>Logically independent, direct concatenation may result in text concatenation across containers (such as across paragraphs or tables). For example, the last character of the previous paragraph and the first character of the next paragraph may accidentally concatenate into a "false" placeholder, which may affect the accuracy of subsequent report output. Based on this, in a preferred embodiment of the present invention, the method for concatenating continuous plain text strings includes: The internal text of the source text nodes is concatenated sequentially. During the concatenation process, if adjacent source text nodes belong to different container nodes, a virtual delimiter is inserted into the concatenated character sequence to obtain a continuous plain text string.
[0024] Specifically, the document object model tree is traversed, the internal text (fragmented text) of the source text node is read and concatenated sequentially. When the container node label is encountered (i.e., adjacent source text nodes belong to different container nodes), a preset virtual delimiter (such as the invisible control character \u0007) is forcibly inserted into the concatenation sequence. The concatenation is continued until a continuous plain text string that ignores the truncation of the underlying label and has the physical isolation characteristics of the container is obtained.
[0025] Further extract placeholders and their corresponding text node sets from the plain text string; placeholders are markers reserved by the user in the template document to prepare for subsequent matching of key names in external business data to generate reports; the text node set is the set of source text nodes corresponding to the placeholders, which defines the operation boundary range of the actual business data written into the underlying document.
[0026] Considering that the regular expression engine can accurately identify placeholders based on preset feature symbols (such as {{}} or specific business prefixes); if the container paths of all characters corresponding to the placeholder are inconsistent, it means that the placeholder is physically across paragraphs or cells, and is an invalid interference item; only when the paths are consistent can it be said that the placeholder is a real placeholder within the same typesetting unit, which was cut off by the underlying layer only due to formatting adjustments; in order to determine the container path of the character corresponding to the placeholder, a dictionary can be further constructed to query the container path; thus, the set of source text nodes to which all characters corresponding to the placeholder belong can be determined, i.e., the set of text nodes. Based on this, in a preferred embodiment of the present invention, the method for obtaining the placeholder and its corresponding set of text nodes includes: Create a dictionary that records character indices, source text node addresses, and container paths; use regular expressions to extract initial placeholders from plain text strings; use the dictionary to determine all source text nodes that correspond to the characters of the initial placeholders in the plain text strings; when all source text nodes have the same container path, use the initial placeholder as the placeholder, and use the set of all source text nodes as the set of text nodes corresponding to the placeholder.
[0027] Specifically, while concatenating plain text strings, the index position (sequential position) of each character is recorded simultaneously, as well as the original text to which each character belongs. <w:t>The memory address of a node is the address of its source text node, which is obtained through the parent backtracking interface of the Document Object Model tree. <w:t>The absolute XPath path of the innermost container node containing the node is the container path; finally, a dictionary is generated, consisting of all triple arrays composed of "character index, source text node address, and container path"; Further configure a regular expression that ignores specific control character encodings (such as the invisible control character \u0007) and includes preset placeholder features (such as containing specific double curly braces {{}} or specific business prefixes); use this regular expression to perform a global scan search in the plain text string to extract all initial placeholders in the plain text string; For each initial placeholder, determine its starting and ending character indices in the plain text string to obtain an index range. Use a dictionary to look up the character corresponding to the index range and the source text node corresponding to the character, and query the container path of the source text node. If the container paths of all source text nodes are consistent, use the initial placeholder as the placeholder, and use the set of all source text nodes as the text node set. If the container paths of all source text nodes are inconsistent, the initial placeholder extracted by the regular expression is determined to be an invalid placeholder and is discarded directly to avoid the regular expression matching crossing paragraph or table boundaries, which would prevent the subsequent correct location of the injected business data object.
[0028] After extracting placeholders and determining the corresponding set of text nodes, the container nodes are further traced back in the document object model tree to construct a template structure relationship diagram. The template structure relationship diagram can represent the spatial nesting logic of the document, avoid the hierarchical mismatch problem of placeholders with the same name, and provide a foundation for aligning the spatial nesting logic of the document with the logical hierarchy of external business data and automatically generating reports. At the same time, the document's streaming rendering engine rules determine the anti-break tags (such as paragraphs on the same page). <w:keepnext>Or prevent breakage <w:cantsplit>) must be mounted in paragraph ( <w:p>) or table row ( <w:tr>In the attribute subtree of ), write directly in the source text node ( <w:t>If the placeholder cannot be identified and is not effective, trace back to the space container level to which it belongs to construct a template structure relationship diagram, which can provide a unique physical insertion point for subsequent injection of anti-breakage tags.
[0029] Since each placeholder corresponds to a set of text nodes that essentially represent the same logical placeholder and have the same corresponding container node, we can choose any source text node as the starting point to trace back upwards to determine the container node. Then, we can determine the included directed edges based on the nesting relationship between the container node and the placeholder. However, if the subordinate relationship is established solely by including directed edges, placeholders in different positions within the same paragraph will exhibit the same leaf node characteristics in the graph structure, which may lead to ambiguity in the subsequent external business data filling mapping. By establishing adjacent directed edges, external business data can be accurately mapped to placeholders using the topological dependency relationship at similar nesting depths, thus solving the problem of row order confusion when writing multiple records. Based on this, in a preferred embodiment of the present invention, the method for obtaining the template structure relationship diagram includes: For each set of text nodes corresponding to a placeholder, take any source text node within it as the starting point for backtracking, backtrack upwards in the document object model tree of the template document, and take the node corresponding to the first paragraph label or table row label as the container node. Placeholders and container nodes are used as graph nodes. The nesting relationship between container nodes and placeholders is used to determine the included directed edges. The order relationship of sibling container nodes in the bottom layer of the template document is used to determine the adjacent directed edges. The template structure relationship graph is then integrated and constructed.
[0030] Specifically, for each set of text nodes corresponding to a placeholder, the first source text node within it is used as the starting point for backtracking. The get_parent interface is called to recursively address upwards in the document object model tree of the template document, and the first recognized paragraph tag ( <w:p>) or table row labels ( <w:tr>The corresponding node is used as a container node; where the first identified label is a table cell label ( <w:tc>The recursive addressing must continue upwards until the table row label enclosing it is identified. <w:tr>); Then, each placeholder and the container node determined by backtracking are treated as graph nodes in the graph structure. If the container node Cj is the ancestor node of the first source text node Pi corresponding to the placeholder Pi in the document object model tree, and does not pass through other container nodes of the same type in between, then a directed edge is created from the container node Cj to the placeholder Pi, and this directed edge is used as the containing directed edge. In order to distinguish multiple placeholders with the same name at the same level, all structured container nodes at the same level are extracted in the order of document rendering. If container node C1 is displayed in the document flow immediately before container node C2, a directed edge is created from container node C1 to container node C2, and this directed edge is used as an adjacent directed edge. Finally, all graph nodes and all directed edges (including directed edges and adjacent directed edges) are associated and assembled to output a template structure relationship graph that reflects the topological characteristics of the document's internal layout space.
[0031] After obtaining the template structure joint diagram, further extract the business values and nesting paths corresponding to the key names of external business data to construct a business data hierarchy diagram; in preparation for aligning the spatial nesting logic of the document with the logical hierarchy of external business data, match and map the business data into placeholders to automatically generate reports.
[0032] In one embodiment of the present invention, a structured business data packet (usually in a lightweight format such as JSON) is first received from an external third-party interface, i.e., external business data; a JSON parser is called to perform a full traversal and parsing of the external business data, extracting all key names, the business values corresponding to the key names, and the nested paths of the key names (for example, a key name named data contains a subkey name named list, and the two form a parent-child nested relationship); wherein, in order to prevent physical overlap of key names with the same name at different levels in the graph, the "full path string from root to leaf" of the key name is hashed and used as the unique physical identifier of the key name.
[0033] Preferably, in one embodiment of the present invention, the method for obtaining the business data hierarchy diagram includes: Using key names as graph nodes, directed edges are determined based on the nesting relationships between key names. Graph nodes and directed edges are associated and assembled to integrate and construct a business data hierarchy graph.
[0034] Specifically, all key names are used as graph nodes in the graph structure, and all directed edges (parent to child) are determined by using the nested paths of the key names. Furthermore, all graph nodes are associated with all directed edges and assembled to output a business data hierarchy graph that reflects the logical hierarchical characteristics of external business data.
[0035] In one embodiment of the present invention, the entity type of the business value corresponding to each key name is also identified in advance, providing a basis for the subsequent targeted generation of anti-breakage tags for the pagination rules of the constraint document streaming rendering engine.
[0036] Specifically, for each key name's business value, read the data protocol prefix or file extension information contained in the business value. If the string starting segment of the business value is detected to contain a Base64 image encoding prefix of data:image / , or contains a standard Hypertext Transfer Protocol header (such as http: / / ) and the string ends with a common image format extension such as .png, .jpg or .jpeg, then append an image entity identifier to the key name corresponding to the business value. If the data structure of the business value is detected to be an array object containing multiple isomorphic records (i.e., the Array structure in the JSON specification, often used to represent lists or detailed tables), append a list entity identifier to the key name corresponding to the business value; It should be noted that, considering the potential differences in data specifications returned by actual business interfaces (for example, an image may only return an object storage service object ID without a formatted suffix), a defensive fallback processing logic is introduced here to ensure that subsequent processing is not interrupted due to the inability to identify the data type. If no clear image encoding features or suffix are detected, and no array object structure of multiple records is detected, the business value is classified as regular plain text data, and a plain text entity identifier is appended to the key name corresponding to the business value.
[0037] Step S2: Construct an initial similarity matrix based on the edit distance between the key name and the placeholder; convert the template structure relationship graph and the business data hierarchy graph into column-normalized adjacency matrices respectively; perform topological diffusion iteration in combination with the initial similarity matrix to solve the final matching probability matrix between the key name and the placeholder, and determine all mapping combinations between the key name and the placeholder; determine whether to generate anti-breakage layout tags based on the entity type of the key name and the container node type of the placeholder in the mapping combination.
[0038] Since key names and placeholders represent attribute definitions, analyzing their similarity can help establish basic semantic anchors or mapping relationships, which is an important reference for subsequently filling the template with mapped business values and preparing for filling the placeholders in the template to generate a report; therefore, this embodiment of the invention first constructs an initial similarity matrix based on the edit distance between key names and placeholders. The initial similarity matrix represents the literal similarity between different key names and placeholders, preparing for subsequent comprehensive matching and mapping relationships by combining nested hierarchical structures.
[0039] Considering that external third-party interfaces usually return English key names, while the placeholders in the template document are mostly Chinese words, directly calculating the edit distance between these two strings belonging to different character sets would lose the mathematical and engineering significance (i.e., the similarity would approach zero). Therefore, it is necessary to unify the languages of the two first.
[0040] Specifically, it can call a pre-built Chinese-English dictionary to find the Chinese translation result corresponding to the English key name, or call an externally mounted machine translation program interface (API) to convert the English key name field into a Chinese string; it can also convert the Chinese placeholder name and the English key name into a common Pinyin encoding sequence.
[0041] In one embodiment of the present invention, taking any key name in the business data hierarchy diagram and any placeholder in the template structure joint diagram as an example, the Levinstein string edit distance between the key name and the placeholder after unifying the language is represented by the minimum number of single-character edit operations (including insertion, deletion or replacement) required to convert one string into another string. Meanwhile, to eliminate the scaling effect of string length on the edit distance value, the maximum length value between the key name string length and the placeholder string length is determined. The Levenstein string edit distance is divided by the maximum length value for normalization. The normalization value is then subtracted from the constant 1, thereby converting the edit distance into literal similarity. Furthermore, the literal similarity values corresponding to each key name and each placeholder are written into a matrix in index order to construct an initial similarity matrix. Each matrix element in the initial similarity matrix represents the literal similarity between the key name and the placeholder of the corresponding index.
[0042] Because simply filling the template with mapping business values based on basic literal similarity is prone to misjudgment and misalignment in scenarios involving business aliases or abbreviations, this embodiment of the invention introduces the network topology alignment algorithm (IsoRank) into the matching mapping process, combined with a nested hierarchical structure as a supplement. It utilizes the topological probability diffusion effect between adjacent graph nodes in the graph structure to correct the deviation of single literal calculation, thereby helping business data to be accurately mapped to placeholders for automatic report generation.
[0043] Network topology alignment algorithms can determine whether different networks have corresponding relationships based on the assumption of similarity in network topology. Therefore, network topology alignment algorithms can be used to evaluate the correspondence between key names in the business data hierarchy diagram and placeholders in the template structure joint diagram, and then determine the probability of matching mapping.
[0044] Since the network topology alignment algorithm is essentially a probabilistic transition process based on Markov chains, converting the template structure graph and the business data hierarchy graph into column-normalized adjacency matrices for probabilistic inference can ensure that the "matching confidence" of each graph node in the template structure graph and the business data hierarchy graph remains stable in total during each Markov transition. It can also improve the stability of numerical calculation in scenarios where the graph node scales of heterogeneous graphs are inconsistent.
[0045] Based on this, the embodiments of the present invention first convert the template structure relationship graph and the business data hierarchy graph into column-normalized adjacency matrices, respectively, in order to prepare for subsequent topological diffusion iteration in combination with the initial similarity matrix, so as to automatically optimize the topological similarity in the two heterogeneous graph structures (template structure relationship graph and business data hierarchy graph) and thus solve the final matching probability matrix between key names and placeholders.
[0046] Preferably, in one embodiment of the present invention, considering that the leaf nodes at the lowest level of the template structure relationship graph and the business data hierarchy graph have no child nodes (dangling graph nodes with an out-degree of 0), during the topology diffusion iteration process, when the probability flows to this dangling node, the outflow probability will be 0, thus making subsequent topology diffusion iterations meaningless, and the final calculated matching mapping probability is 0; to avoid algorithm failure, it is necessary to forcibly add virtual directed edges for transition probabilities to the dangling graph nodes, so that the probability can continue to circulate in the graph, ensuring that the algorithm can converge normally; therefore, the method for obtaining the normalized adjacency matrix includes: The template structure relationship graph and the business data hierarchy graph are used as target graphs in sequence; graph nodes with non-zero out-degree are extracted from the target graphs, and the transition probability of each graph node is evenly distributed to all its directed edges according to the out-degree of the graph node; dangling graph nodes with zero out-degree are extracted from the target graphs, and virtual directed edges pointing to all graph nodes with evenly balanced transition probabilities are added to the dangling graph nodes; the transition probabilities of each graph node are summarized to generate a column-normalized adjacency matrix with a column sum of 1.
[0047] Specifically, the template structure relationship diagram and the business data hierarchy diagram are analyzed and processed in the same way, so the template structure relationship diagram and the business data hierarchy diagram are used as target diagrams for analysis and processing in turn. Assuming the target graph is a template structure graph, extract all graph nodes from the template structure graph and assign a unique index number (1 to N, where N is the total number of graph nodes) to each graph node according to the traversal order. Initialize an N×N all-zero matrix, traverse all directed edges in the template structure graph, and if there is a directed edge from graph node i to node j, modify the element value in the j-th row and i-th column of the all-zero matrix to 1 to determine the initial template matrix. Perform out-degree detection on the initial template matrix and calculate the sum of elements in each column of the matrix. If the sum of elements in a column is 0, determine that the graph node corresponding to the column is a dangling graph node. Assign all element values in the column where the dangling node is located to the reciprocal of the total number of graph nodes (i.e., 1 / N) to ensure that the leaf nodes at the end can generate uniform probability feedback to all nodes in the graph, thus avoiding computational deadlock during the Markov transition process. Further extract the sum of the elements in each column of the initial template matrix, divide each element in each column by the sum, obtain the normalized value, and overwrite the element in the original position with the normalized value to output the column normalized adjacency matrix of the template structure graph; at this time, the sum of the elements in any column of the column normalized adjacency matrix is strictly equal to 1.
[0048] Similarly, the column-normalized adjacency matrix corresponding to the business data hierarchy graph can be determined, which will not be elaborated further.
[0049] After obtaining two column-normalized adjacency matrices, topological diffusion iteration can be performed in conjunction with the initial similarity matrix to solve the final matching probability matrix between the key name and the placeholder. Each element in the final matching probability matrix represents the matching confidence between the key name under the corresponding index and the placeholder under the corresponding index, which prepares for determining the mapping combination in subsequent matching mapping.
[0050] In a preferred embodiment of the present invention, the method for obtaining the final matching probability matrix includes: Based on the number of graph nodes in the template structure relationship graph and the business data hierarchy graph, the matrix dimension is determined and a null zero matrix is constructed; the null zero matrix is assigned values based on the initial similarity matrix, and the matching probability matrix is initialized. The initial similarity matrix is weighted using preset topological weights to obtain the literal baseline component; the initial matching probability matrix, the column normalized adjacency matrix of the business data hierarchy graph, and the transpose of the column normalized adjacency matrix of the template structure relationship graph are multiplied together, and the result is weighted using preset diffusion weights to obtain the structural diffusion component; the preset topological weights and preset diffusion weights are complementary. The process iterates continuously to obtain the structural diffusion component at each iteration depth, and then fuses the literal reference component with the structural diffusion component to determine the matching probability matrix at each iteration depth. Based on the difference between the matching probability matrices at adjacent iteration depths, it is determined whether the iteration has converged, and the matching probability matrix corresponding to the first convergence is taken as the final matching probability matrix.
[0051] Specifically, in the initialization phase of the solution process, an identifier parameter k representing the current iteration number and a matching probability matrix Rk representing the k-th iteration are established. Let the initial value k=0. Based on the number of graph nodes N in the template structure relationship graph and the number of graph nodes M in the business data hierarchy graph, a null zero matrix R0 is created to store the matching probability between key names and placeholders. The dimension of the null zero matrix R0 is M×N. Then, the literal similarity values between each pair of key names and placeholders in the initial similarity matrix are fully filled into R0 to obtain the initial matching probability matrix, which represents the initial baseline state of the topology diffusion iterative deduction. Further configure preset topology weights , Constrained at (0,1), to ensure the dominance of literal similarity while also taking into account fine-tuning of topological structure, this embodiment... We set the value to 0.85; we then iterate further to obtain the matching probability matrix at each iteration depth; the expression for the matching probability matrix is: ;in, This is the matching probability matrix after the (k+1)th iteration; Preset topology weights; This is the initial similarity matrix; The preset diffusion weights are complementary to the preset topology weights. The column-normalized adjacency matrix corresponding to the business data hierarchy graph; This is the matching probability matrix after the k-th iteration; This is the column-normalized adjacency matrix corresponding to the template structure relationship graph; It is the transpose symbol; As a literal baseline component, it ensures that the literal basic spelling similarity feature always occupies a fixed proportion of the dominant weight in each iteration, preventing the matching result from deviating from the semantic attributes of the data itself after multiple topological diffusions; Let Rk be the structural diffusion component, representing the single-step Markov walk state of the matching probability matrix Rk after the k-th iteration under the structural constraints of the template structure graph and the business data hierarchy graph. This reflects the similarity of the relative nested positions of the key names and placeholders in their respective graph structures. Specifically, at the mathematical and engineering level... The essence of continuous multiplication is that if there is a high probability of matching between the key name and the parent (or child) node of the placeholder, then this high probability will be passed proportionally along the edges of the graph (nesting relationship) through matrix multiplication, thereby increasing the confidence of matching between the key name and the placeholder. This is used to control the proportion of trust in the total matching probability due to the topological diffusion effect; the larger the structural diffusion component, the better. By adding the literal reference component to the structural diffusion component, the isomorphic features of local nesting depth are used to effectively compensate for the computational error caused by literal translation. Further extraction and The matrix norm difference is used to measure the difference between matching probability matrices at adjacent iteration depths. For example, the absolute values of the differences between elements at the same index position in two matching probability matrices are summed to obtain the matrix norm difference. This is iterated continuously, and the matrix norm difference obtained in each iteration is compared with a preset convergence constant. The matrix norm difference is compared, and if the difference is less than the preset convergence constant, then convergence is determined, and the matching probability matrix at the first convergence is taken as the final matching probability matrix.
[0052] In addition, a maximum allowed number of iterations (e.g., 500 times) should be set to prevent computational deadlock when the matrix is extremely sparse or disconnected.
[0053] After obtaining the final matching probability matrix, all mapping combinations between key names and placeholders can be further determined; the mapping combinations represent the matching mapping relationship between key names and placeholders, preparing for subsequent report generation.
[0054] Preferably, in one embodiment of the present invention, the method for obtaining the mapping combination includes: In each column of the final matching probability matrix, the maximum element value greater than the preset effective benchmark threshold is extracted, and the key name and placeholder corresponding to the maximum element value are used as a mapping combination.
[0055] Specifically, in each column of the final matching probability matrix, a greedy assignment extraction algorithm is executed to extract the maximum element value. A preset effective benchmark threshold is further set to filter out invalid mapping associations with insufficient probability after topology deduction. In this embodiment, the preset effective benchmark threshold is 0.5. The position index of the maximum element value greater than 0.5 in each column is determined in the final matching probability matrix. The row index (key name index) and column index (placeholder index) corresponding to this element can uniquely determine a mapping combination between a key name and a placeholder.
[0056] When the maximum element value in each column is not greater than the preset effective baseline threshold of 0.5, it is determined that the placeholder has no matching data, and the underlying text of the placeholder is preserved as is during the final replacement.
[0057] By combining greedy assignment with a baseline lower bound extraction method, a memory write conflict deadlock caused by a placeholder being incorrectly allocated multiple data due to global proportional truncation is avoided.
[0058] For each mapping combination, the entity type of the key name and the container node type of the placeholder can be extracted, and it can be determined whether to generate anti-breakage layout tags, in order to prepare for the subsequent targeted generation of document pagination rules to improve the report generation effect.
[0059] Preferably, in one embodiment of the present invention, determining whether to generate a break-resistant typesetting label includes: The anti-break typesetting tags include paragraph same-page attribute tags and inline anti-pagination attribute tags. For each mapping combination, if the entity type of the key name is an image entity and the container node type of the placeholder is a paragraph tag, then a paragraph same-page attribute tag is generated; if the entity type of the key name is a list entity and the container node type of the placeholder is a table row tag, then an inline anti-pagination attribute tag is generated; otherwise, no anti-break typesetting tags are generated.
[0060] Specifically, for each mapping combination, the determination is based on image page cross-page protection and list row truncation protection as the main scenarios: If the entity type of the key name is an image entity and the container node type of the placeholder is a paragraph tag, then a paragraph same page attribute tag is generated, thereby forcing the current paragraph (the paragraph containing the image) and its next adjacent paragraph (usually the caption text) to remain on the same page during rendering, avoiding spatial separation between the image and the text; If the entity type of the key name is a list entity and the container node type of the placeholder is a table row label, generate an inline anti-pagination attribute label to inform the rendering engine to prohibit cross-page physical splitting of the current table row when calculating the page height, ensuring that the content of the row is displayed completely on the same page. When neither of the above two conditions exists, i.e. the entity type of the key name is a plain text entity and the container node type of the placeholder does not belong to paragraph or table row, no anti-break typesetting tag is generated.
[0061] In another embodiment of the present invention, considering that forcibly adding the anti-breakage attribute to table rows containing excessively long text or excessively large images may cause the rendering engine to crash or result in severe layout white space when the maximum physical size of a single page is exceeded, the estimated layout height after the corresponding business value is written can be calculated based on the image size or the number of rows in the list data before "determining whether to generate the anti-breakage layout label". The determination logic for generating the anti-breakage layout label is executed only if the estimated layout height is less than the preset maximum single-page height threshold. The maximum single-page height threshold needs to be determined based on the actual document parameters of the report file.
[0062] Step S3: Based on the mapping combination, write the business value corresponding to the key name into the first source text node in the cleaned placeholder text node set. If an anti-breakage typesetting tag is generated, attach the anti-breakage typesetting tag to the attribute subtree of the container node to which the first source text node belongs, and serialize the output report file.
[0063] In one embodiment of the present invention, taking the mapping and filling (business value) of placeholders and key names in any mapping combination as an example: First, the Document Object Model standard interface is called. Following the top-to-bottom reading order of the document flow, the first and first source text nodes in the set of text nodes corresponding to placeholders are extracted. This first and second source text node and its outer running fragment node (i.e., ...) are retained. <w:r>and <w:rpr>The original font size, font, color, and other layout style attributes included in ). Since users may set different styles for different parts of the same placeholder when editing the template (such as red for the first half and blue for the second half), in order to prevent style inheritance conflicts, the style of the first and second source text nodes is used as the benchmark for overriding. The first and second source text nodes that retain the benchmark style are established as the first data writing node. The child node removal function of the document object model interface is further called to clear all redundant source text nodes in the text node set except for the first and second source text nodes, so as to provide a basis for subsequent business data writing. After node cleaning, the business value and entity type identifier of the key name in the mapping combination are extracted. Multimodal data formatting is then performed based on the entity type identifier. If the entity type identifier is a plain text entity identifier or a list entity identifier, the text string attribute of the business value is directly extracted. Based on the placeholders, the start and end character indices in the text within the first node of the data write are used to perform a local substring replacement operation on the index range. If the entity type identifier is an image entity identifier, the image encoded data (e.g., Base64 encoded stream) contained in the business value is extracted. The absolute physical size of the image is calculated and written to the attribute label. An image decoder is then called to restore the image encoded data to a binary bitmap stream. This binary bitmap stream is then encapsulated into a graphical object node conforming to the document's underlying standard (e.g., ...). <w:drawing>The tag is then attached as a child node to the outer running fragment node where the data is written first, replacing the original plain text. After the business value is written, the underlying pagination rule intervention operation is executed: if the mapping combination is determined to generate anti-breakage typesetting tags, for the first node where the data is written, an upward backtracking operation is performed using the node's parent attribute to locate the innermost structured container node (i.e., the paragraph node) that wraps the first node where the data is written. <w:p>or table row node <w:tr>), and find the attribute subtree label corresponding to the structured container node (i.e., the label defining the paragraph attribute). <w:ppr>Tags, or those defining table row attributes <w:trpr>(Tag); call the node append operation interface to forcibly insert the anti-break layout tag as a child node and mount it inside the attribute subtree tag, so that the downstream streaming rendering engine can read the forced unbreakable or forced same-page constraint when calculating the page height and performing pagination, thereby moving the entire container object to the next page and avoiding layout truncation.
[0064] After the anti-break typesetting tag is attached, the complete document object model tree containing all written nodes and newly added attributes is traversed, and a standard format serialization encoding operation is performed on the document object model tree. The continuously extensible markup language text stream generated by the encoding is further converted into a standardized office document file format; the document file is saved and output as an automated report file.
[0065] Based on the same inventive concept, this invention also proposes an automated report generation system for free editing and parsing of multimodal templates. The system includes a memory, a processor, and a computer program stored in the memory and capable of running on the processor. When the processor executes the computer program, it implements the automated report generation method for free editing and parsing of multimodal templates described in steps S1-S3.
[0066] In summary, this invention first constructs a template structure relationship diagram and a business data hierarchy diagram, then iteratively calculates the final matching probability matrix between key names and placeholders to determine all mapping combinations between key names and placeholders; further, it determines whether to generate anti-fragmentation layout tags; then, based on the mapping combinations, it writes the business value corresponding to the key name into the first source text node in the cleaned placeholder text node set, determines whether to attach anti-fragmentation layout tags, and serializes and outputs the report file. This invention overcomes the parsing failure caused by fragmented template underlying tags; it integrates literal and topological hierarchy features to achieve accurate mapping of complex heterogeneous data; and it dynamically injects anti-fragmentation tags for multimodal data to solve the problem of chart truncation across pages, significantly improving the accuracy of automated report generation and layout quality.
[0067] It should be noted that the order of the above embodiments of the present invention is merely for descriptive purposes and does not represent the superiority or inferiority of the embodiments. The processes depicted in the accompanying drawings do not necessarily require a specific or sequential order to achieve the desired result. In some embodiments, multitasking and parallel processing are also possible or may be advantageous.
[0068] The various embodiments in this specification are described in a progressive manner. The same or similar parts between the various embodiments can be referred to each other. Each embodiment focuses on describing the differences from other embodiments.< / w:trpr> < / w:ppr> < / w:tr> < / w:p> < / w:drawing> < / w:rpr> < / w:r> < / w:tr> < / w:tc> < / w:tr> < / w:p> < / w:t> < / w:tr> < / w:p> < / w:cantsplit> < / w:keepnext> < / w:t> < / w:t> < / w:tr> < / w:p> < / w:t> < / w:tr> < / w:p> < / w:t>
Claims
1. An automated report generation method for free editing and parsing of multimodal templates, characterized in that, include: Extract the source text nodes and container nodes at the bottom layer of the template document, and concatenate them into a continuous plain text string; Extract placeholders and their corresponding text node sets from plain text strings, and backtrack container nodes to construct a template structure relationship graph; extract key names from external business data, corresponding business values and nested paths, and construct a business data hierarchy graph; Construct an initial similarity matrix based on the edit distance between key names and placeholders; The template structure relationship diagram and the business data hierarchy diagram are respectively converted into column-normalized adjacency matrices. Combined with the initial similarity matrix, topological diffusion iteration is performed to solve the final matching probability matrix between key names and placeholders, and to determine all mapping combinations between key names and placeholders. Based on the entity type of the key name and the container node type of the placeholder in the mapping combination, it is determined whether to generate anti-breakage layout tags. Based on the mapping combination, the business value corresponding to the key name is written into the first source text node in the cleaned placeholder text node set. If an anti-break typesetting tag is generated, the anti-break typesetting tag is attached to the attribute subtree of the container node to which the first source text node belongs, and the serialized output report file is generated.
2. The automated report generation method for free editing and parsing of multimodal templates according to claim 1, characterized in that, The method for concatenating continuous plain text strings includes: The internal text of the source text nodes is sequentially concatenated. During the concatenation process, if adjacent source text nodes belong to different container nodes, a virtual separator is inserted into the concatenated character sequence to obtain a continuous plain text string.
3. The automated report generation method for free editing and parsing of multimodal templates according to claim 1, characterized in that, The method for obtaining the placeholder and its corresponding text node set includes: Establish a dictionary to record character indexes, source text node addresses, and container paths; extract initial placeholders from plain text strings using regular expressions; use the dictionary to determine all source text nodes corresponding to the characters of the initial placeholders in the plain text strings; when all source text nodes have the same container path, use the initial placeholder as a placeholder, and use the set of all source text nodes as the set of text nodes corresponding to the placeholder.
4. The automated report generation method for free editing and parsing of multimodal templates according to claim 1, characterized in that, The method for obtaining the template structure relationship diagram includes: For each set of text nodes corresponding to a placeholder, take any source text node within it as the starting point for backtracking, backtrack upwards in the document object model tree of the template document, and take the node corresponding to the first paragraph label or table row label as the container node. Placeholders and container nodes are used as graph nodes. The nesting relationship between container nodes and placeholders is used to determine the included directed edges. The order relationship of sibling container nodes in the bottom layer of the template document is used to determine the adjacent directed edges. The template structure relationship graph is then integrated and constructed.
5. The automated report generation method for free editing and parsing of multimodal templates according to claim 1, characterized in that, The method for obtaining the business data hierarchy diagram includes: The key names are used as graph nodes. Directed edges are determined based on the nesting relationship between the key names. The graph nodes and directed edges are associated and assembled to integrate and construct a business data hierarchical graph.
6. The automated report generation method for free editing and parsing of multimodal templates according to claim 1, characterized in that, The method for obtaining the column-normalized adjacency matrix includes: The template structure relationship graph and the business data hierarchy graph are used as target graphs in sequence; graph nodes with non-zero out-degree are extracted from the target graphs, and the transition probability of each graph node is evenly distributed to all its directed edges according to the out-degree of the graph node; dangling graph nodes with zero out-degree are extracted from the target graphs, and virtual directed edges pointing to all graph nodes with evenly balanced transition probabilities are added to the dangling graph nodes; the transition probabilities of each graph node are summarized to generate a column-normalized adjacency matrix with a column sum of 1.
7. The automated report generation method for free editing and parsing of multimodal templates according to claim 1, characterized in that, The method for obtaining the final matching probability matrix includes: Based on the number of graph nodes in the template structure relationship graph and the business data hierarchy graph, the matrix dimension is determined and a null zero matrix is constructed; the initial similarity matrix is used to assign values to the null zero matrix, and the matching probability matrix is initialized. The initial similarity matrix is weighted using preset topological weights to obtain the literal baseline component; the initial matching probability matrix, the column normalized adjacency matrix of the business data hierarchy graph, and the transpose of the column normalized adjacency matrix of the template structure relationship graph are multiplied together, and the result is weighted using preset diffusion weights to obtain the structural diffusion component; the preset topological weights and preset diffusion weights are complementary. The process iterates continuously to obtain the structural diffusion component at each iteration depth, and then fuses the literal reference component with the structural diffusion component to determine the matching probability matrix at each iteration depth. Based on the difference between the matching probability matrices at adjacent iteration depths, it is determined whether the iteration has converged, and the matching probability matrix corresponding to the first convergence is taken as the final matching probability matrix.
8. The automated report generation method for free editing and parsing of multimodal templates according to claim 7, characterized in that, The method for obtaining the mapping combination includes: In each column of the final matching probability matrix, the maximum element value greater than the preset effective benchmark threshold is extracted, and the key name and placeholder corresponding to the maximum element value are used as a mapping combination.
9. The automated report generation method for free editing and parsing of multimodal templates according to claim 1, characterized in that, The determination of whether to generate anti-breakage typesetting labels includes: The anti-break typesetting tags include paragraph same-page attribute tags and inline anti-pagination attribute tags. For each mapping combination, if the entity type of the key name is an image entity and the container node type of the placeholder is a paragraph tag, then a paragraph same-page attribute tag is generated; if the entity type of the key name is a list entity and the container node type of the placeholder is a table row tag, then an inline anti-pagination attribute tag is generated; otherwise, no anti-break typesetting tags are generated.
10. An automated report generation system for free editing and parsing of multimodal templates, the system comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that, When the processor executes the computer program, it implements the steps of the automated report generation method for free editing and parsing of multimodal templates as described in any one of claims 1 to 9.
