An intelligent template generation method based on double document comparison
By using an intelligent template generation method based on dual-document comparison, the problem of inaccurate positioning of nodes with complex layout differences in existing technologies is solved, and clear generation and stability of structured document templates are achieved.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- 星汇智云科技(江苏)有限公司
- Filing Date
- 2026-04-22
- Publication Date
- 2026-07-10
Smart Images

Figure CN122366400A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of natural language processing technology, specifically to an intelligent template generation method based on dual-document comparison. Background Technology
[0002] In the field of enterprise information technology and document automation, rapidly generating structured document templates based on historical documents or dual-document comparison is an important technological application direction. Existing technologies generally employ template generation methods that combine plain text sequence comparison with shallow DOM tree parsing. This involves using string matching or single-node comparison to identify text differences between the baseline and comparison documents. Within a pre-defined rule framework, the difference fragments are automatically extracted and replaced with static placeholders. This is currently the mainstream technology for achieving automated document template generation.
[0003] However, existing technical solutions have significant shortcomings in terms of template generation structure preservation and semantic segmentation accuracy. The underlying logic used for comparison and replacement suffers from flattening and lack of spatial features. Existing comparison methods are mostly based on one-dimensional text sequences. Their comparison process often strips away the original document's absolute physical offset, row and column nesting, and hierarchical depth, making it difficult to accurately locate and match differential load nodes with complex layout formats. This leads to spatial misalignment in the replacement of target placeholders. The system only performs "mechanical" boundary segmentation when differential characters are triggered for recognition, failing to achieve contextual topological mapping. It cannot determine the lexical dependencies and master-slave dependencies before and after the differential text, nor does it have a mechanism to dynamically constrain placeholder boundaries using structural nesting constraint parameters. The generation of semantic tags suffers from a one-way black box problem, relying solely on natural language processing output without fusing and reversing the topological edge features of the document's physical space. This results in the final structured document template being prone to layout errors and collapse, with blurred logical placeholder boundaries and semantic breaks. It lacks the reliability to maintain structural constraints and simplify data mapping in complex document scenarios.
[0004] To address this, an intelligent template generation method based on dual-document comparison is proposed. Summary of the Invention
[0005] The purpose of this invention is to provide an intelligent template generation method based on dual-document comparison to solve the problems mentioned in the background art.
[0006] To achieve the above objectives, the present invention provides the following technical solution: an intelligent template generation method based on dual-document comparison, comprising: The system receives a baseline document and a comparison document, performs hierarchical parsing, outputs a baseline model tree and a comparison model tree, performs matching calculations, and outputs the features of the differing documents, spatial coordinate identifiers, and offset matrices. Lexical boundary attributes of differential document features are extracted and injected into associated nodes within the offset matrix to perform topological mapping calculations, outputting a text topological dependency graph and topological edge features; based on the text topological dependency graph, offset matrix, and baseline model tree, text concatenation is extracted and output as a multidimensional joint tensor; The multidimensional joint tensor is input into the semantic recognition network to perform weight allocation calculation, outputting a set of semantic labels. Then, reverse boundary calibration calculation is performed through topological edge features to output a set of verification semantic labels. The set of verification semantic labels, differential document features, spatial coordinate labels and text topological dependency graph are fused to output a mapping data structure. Perform parsing processing on the mapped data structure and output a set of logical placeholders; locate the differential load nodes in the baseline model tree according to the spatial coordinates, replace the differential load nodes with the associated placeholders in the set of logical placeholders, and output the constraint model tree; perform serialization processing on the constraint model tree and output a structured document template.
[0007] Preferably, the specific process of outputting the difference document features, spatial coordinate identifiers, and offset matrix includes: importing the benchmark document and the comparison document into a preset document parsing engine to perform document structure tree stripping processing, generating a benchmark model tree and a comparison model tree containing node depth parameters, absolute offsets, and row and column nesting attributes; performing same-level breadth traversal and cross-level depth traversal node comparison calculations on the benchmark model tree and the comparison model tree, extracting nodes with different attributes to form a difference node sequence; performing plain text stripping processing on the internal loads of the difference node sequence to form difference document features; retrieving the absolute offsets and row and column nesting attributes recorded in the benchmark model tree, combining them with the difference node sequence to perform spatial dimension encoding calculations, and constructing spatial coordinate identifiers; retrieving the node depth parameters recorded in the benchmark model tree, measuring the level depth difference and same-level displacement deviation between adjacent nodes in the difference node sequence, and performing matrix initialization operations based on the measurement results to establish an offset matrix.
[0008] Preferably, the specific process of outputting the text topological dependency graph and topological edge features includes: performing word segmentation and slicing calculations on the differential document features to generate a lexical boundary attribute set carrying boundary length attributes and part-of-speech dependency tags; retrieving the node grid parameters recorded in the offset matrix, locating the associated nodes within the offset matrix, injecting the boundary length attributes and part-of-speech dependency tags from the lexical boundary attribute set into the located associated nodes to perform feature overwrite operations, generating a fused node attribute matrix; performing graph theory node connection relationship construction processing on the fused node attribute matrix, selecting node pairs with master-slave dependency relationships to establish directed connection links, and constructing the text topological dependency graph; analyzing the association parameters of the directed connection links within the text topological dependency graph to generate the topological edge features.
[0009] Preferably, the specific process of outputting the multidimensional joint tensor includes: locating the difference center node in the baseline model tree according to the node relationship recorded in the text topology dependency graph; searching for the static context nodes adjacent to the difference center node and extracting static text parameters; assembling and generating a context feature slice set; inputting the offset matrix into the multilayer perceptron network for nonlinear dimensionality reduction mapping calculation to obtain spatial feature vectors; performing word embedding mapping calculation on the context feature slice set to generate slice word vectors; and performing feature channel dimension stacking and concatenated vector splicing operations on the spatial feature vectors and the slice word vectors to synthesize a multi-channel tensor data structure as the multidimensional joint tensor.
[0010] Preferably, the specific process of outputting the verification semantic label set includes: importing the multidimensional joint tensor into the self-attention mechanism layer inside the semantic recognition network to perform self-projection feature matrix multiplication calculation, and extracting the hidden state context tensor; importing the hidden state context tensor into a preset fully connected classification layer to perform feature dimension mapping and sampling activation calculation, and obtaining the semantic label set; parsing the topological edge features, and extracting the structural nesting constraint parameters between the master node and the subordinate nodes; for the initial labels belonging to the subordinate nodes in the semantic label set, if it is determined that the natural language coverage value exceeds the spatial threshold set by the structural nesting constraint parameters, performing forced truncation and reclassification calculation on the lexical sequence of the initial labels according to the structural nesting constraint parameters, and outputting the final verification label; summarizing the original labels and the final verification labels in the semantic label set that have not undergone truncation calculation, and generating the verification semantic label set.
[0011] Preferably, the specific process of outputting the mapping data structure includes: performing hash calculation on the spatial coordinate identifier to generate a unique hash value for the node; retrieving the unique hash value of the node, the final verification label and the original label recorded inside the verification semantic label set, and performing a tuple binding operation in combination with the differential document features to concatenate them into a basic multidimensional tuple; extracting the pointing parameters of the directed connection links from inside the text topological dependency graph to establish topological constraint feature items; performing a tensor encapsulation operation on the basic multidimensional tuple and the topological constraint feature items to generate a multimodal combination carrier as the mapping data structure, and recording the final verification label, the original label and the topological constraint feature items in the mapping data structure.
[0012] Preferably, the specific process of outputting the constraint model tree includes: disassembling the mapping data structure and performing field unpacking processing; retrieving the final verification label, original label, and topological constraint feature item of the internal record and performing string formatting concatenation calculation to generate the associated placeholders; and assembling all the generated associated placeholders into the logical placeholder set; extracting the absolute offset and row / column nesting attributes contained in the spatial coordinate identifier, performing a search and addressing operation within the baseline model tree, locking and extracting the differential load nodes; for the differential load nodes, retrieving the corresponding associated placeholders within the logical placeholder set and performing a memory address overwrite operation, clearing the differential text within the differential load nodes and loading the placeholder data, and reconstructing to generate the constraint model tree.
[0013] Preferably, the specific generation process of the structured document template includes: receiving the constraint model tree and performing a node-level traversal operation to separate and extract the static text payload and document layout features carried by the internal nodes; searching and extracting the data type restriction attributes and hierarchical nesting association parameters carried by the associated placeholders from within the constraint model tree; retrieving the static text payload, the document layout features, the data type restriction attributes, and the hierarchical nesting association parameters to perform markup language syntax encoding and concatenation calculations, and converting them into a low-level format byte stream; performing file header protocol encapsulation and memory persistence writing operations on the low-level format byte stream, compiling to generate and outputting the structured document template.
[0014] Compared with the prior art, the beneficial effects of the present invention are as follows: 1. By extracting the lexical boundary attributes of the differential document features and injecting them into the associated nodes within the offset matrix to perform topological mapping calculations, a text topological dependency graph and topological edge features are output. Based on the text topological dependency graph, offset matrix, and baseline model tree, text concatenation is extracted, and a multidimensional joint tensor is output. Subsequently, this multidimensional joint tensor is input into a semantic recognition network to perform weight allocation calculations, and a set of semantic labels is output. By fusing the lexical boundary attributes with the spatial location offset matrix and constructing a text topological dependency graph, a joint representation of semantic information and spatial structure is achieved. This allows for full utilization of the contextual associations and typographic features in the multidimensional joint tensor when generating semantic labels, obtaining clear logical placeholder boundaries and avoiding semantic gaps, thus improving the accuracy of feature mapping.
[0015] 2. By analyzing the topological edge features, structural nesting constraint parameters between the master node and subordinate nodes are extracted. Then, reverse boundary calibration calculation is performed using the topological edge features. Specifically, for the initial tags belonging to subordinate nodes within the semantic tag set, when it is determined that their natural language coverage value exceeds the spatial threshold set by the structural nesting constraint parameters, the lexical sequence of the initial tags is forcibly truncated and reclassified according to the structural nesting constraint parameters, and the final verification tag is output. This process uses the topological edge features as a hard constraint indicator of spatial dimension to intervene in semantic recognition, and performs forced truncation and reclassification calculation on the initial tags that exceed the limit. This effectively eliminates the black-box error caused by unidirectional calculation and ensures that the semantic tag output range strictly follows the document nesting level.
[0016] 3. Locate the differential load nodes within the baseline model tree according to spatial coordinates, replace the differential load nodes with associated placeholders from the logical placeholder set, output the constraint model tree, and then separate and extract the static text loads and document layout features carried by the internal nodes. Subsequently, retrieve the static text loads, document layout features, data type restriction attributes, and hierarchical nesting association parameters, perform markup language syntax encoding and concatenation calculations, convert and generate the underlying format byte stream, compile and generate and output the structured document template. This process, by replacing the differential load nodes within the constraint model tree while retaining the document layout features and static text loads, ensures seamless integration between the replacement operation and the original document's physical space, eliminates the risk of layout format disorder and collapse, and maintains structural constraints.
[0017] 4. By fusing the set of verification semantic tags, differential document features, spatial coordinate identifiers, and text topological dependency graph, a mapping data structure is output. This structure then deeply binds the final verification tags, original tags, and topological constraint feature terms, achieving efficient coupling of multimodal data. Subsequently, the mapping data structure is parsed to output a set of logical placeholders. These placeholders are then combined with spatial coordinate identifiers and a baseline model tree to reconstruct a constraint model tree and the final structured document template. This constructs a closed-loop system from bottom-level physical offset extraction and mid-level topological semantic calibration to top-level template serialization output. This ensures that spatial layout constraints and dynamic semantic mapping remain highly synchronized within the overall framework, maintaining the integrity of multidimensional features during the transformation process and improving the system stability and data flow continuity during automated processing of complex layout documents. Attached Figure Description
[0018] Figure 1 A flowchart illustrating an intelligent template generation method based on dual-document comparison, as proposed in an embodiment of this invention application; Figure 2 This is a diagram illustrating the multidimensional feature extraction and joint tensor construction process proposed in an embodiment of this invention. Figure 3 This is a diagram illustrating the reverse boundary calibration process of semantic tags proposed in an embodiment of this invention. Detailed Implementation
[0019] The technical solutions of the embodiments 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, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0020] Please see Figures 1-3 The present invention provides an intelligent template generation method based on dual-document comparison, the specific steps of which are as follows: The system receives a baseline document and a comparison document, performs hierarchical parsing, outputs a baseline model tree and a comparison model tree, performs matching calculations, and outputs the features of the differing documents, spatial coordinate identifiers, and offset matrices. Lexical boundary attributes of differential document features are extracted and injected into associated nodes within the offset matrix to perform topological mapping calculations, outputting a text topological dependency graph and topological edge features; based on the text topological dependency graph, offset matrix, and baseline model tree, text concatenation is extracted and output as a multidimensional joint tensor; The multidimensional joint tensor is input into the semantic recognition network to perform weight allocation calculation, outputting a set of semantic labels. Then, reverse boundary calibration calculation is performed through topological edge features to output a set of verification semantic labels. The set of verification semantic labels, differential document features, spatial coordinate labels and text topological dependency graph are fused to output a mapping data structure. Perform parsing processing on the mapped data structure and output a set of logical placeholders; locate the differential load nodes in the baseline model tree according to the spatial coordinates, replace the differential load nodes with the associated placeholders in the set of logical placeholders, and output the constraint model tree; perform serialization processing on the constraint model tree and output a structured document template.
[0021] The technical solution of the present invention will be further described in detail below with reference to specific embodiments.
[0022] Example 1 This application discloses an intelligent template generation method based on dual-document comparison, see embodiments. Figure 1 The specific steps proposed in this invention include: S1. Receiving a baseline document and a comparison document, performing hierarchical parsing, outputting a baseline model tree and a comparison model tree, and performing matching calculations to output the differences in document features, spatial coordinate identifiers, and offset matrix; S2. Extracting the lexical boundary attributes of the differences in document features and injecting them into the associated nodes within the offset matrix to perform topological mapping calculations, outputting a text topological dependency graph and topological edge features; extracting text concatenation based on the text topological dependency graph, offset matrix, and baseline model tree, and outputting a multidimensional joint tensor; S3. Inputting the multidimensional joint tensor into a semantic recognition network to perform weight allocation calculations. The process involves: outputting a semantic label set; performing reverse boundary calibration calculations using topological edge features to output a verification semantic label set; fusing the verification semantic label set, differential document features, spatial coordinate identifiers, and text topological dependency graph to output a mapping data structure; parsing the mapping data structure to output a logical placeholder set; locating differential load nodes within the baseline model tree according to spatial coordinate identifiers; replacing differential load nodes with associated placeholders within the logical placeholder set to output a constraint model tree; and performing serialization processing on the constraint model tree to output a structured document template.
[0023] Further, the system receives the baseline document and the comparison document, performs hierarchical parsing, outputs the baseline model tree and the comparison model tree, performs matching calculations, and outputs the differences in document features, spatial coordinate identifiers, and offset matrices; corresponding to step S1 above; the specific implementation process includes: The benchmark and comparison documents are imported into a preset document parsing engine and subjected to document structure tree stripping processing to generate a benchmark model tree and a comparison model tree containing node depth parameters, absolute offsets, and row and column nesting attributes. Breadth-first traversal and depth-first traversal node comparison calculations are performed on the benchmark and comparison model trees at the same level to extract nodes with dissimilar attributes and form a sequence of differing nodes. Plain text stripping processing is performed on the internal loads of the sequence of differing nodes to form differing document features. The absolute offsets and row and column nesting attributes recorded in the benchmark model tree are retrieved and combined with the sequence of differing nodes to perform spatial dimension encoding calculations to construct spatial coordinate identifiers. The node depth parameters recorded in the benchmark model tree are retrieved to measure the level depth difference and level displacement deviation between adjacent nodes in the sequence of differing nodes. Based on the calculation results, a matrix initialization operation is performed to establish an offset matrix.
[0024] Specifically, the processes for identifying differential document features, spatial coordinate identifiers, and offset matrices include: The system first receives two data inputs: a baseline document and a comparison document. Both documents typically use open, standardized document formats. The baseline and comparison documents are then imported into a pre-defined document parsing engine to perform a document structure tree stripping process.
[0025] This pre-defined document parsing engine is built upon an underlying Extensible Markup Language (EXPLAIN) parser. Its data generation process involves the engine reading the document's underlying markup code or byte stream line by line, stripping away redundant code such as version declarations and compatibility tags, and mapping structured tags like paragraphs, tables, rows, cells, and text fields to node objects in memory. By establishing a parent-child node reference mechanism, a baseline model tree and a comparison model tree are generated. During this process, the parsing engine traverses each generated node and assigns three key attributes as output: the first is the node depth parameter, recording the node's hierarchical span from the root node; the second is the absolute offset, recording the physical position index of the node's internal text start and end points within the entire document's plain text character stream; and the third is the row and column nesting attribute, used to identify the two-dimensional coordinates within grid structures such as tables.
[0026] After outputting the baseline model tree and the comparison model tree, these two model trees are used as input to perform breadth-first traversal at the same level and depth-first traversal across levels for node alignment calculations. The data generation process is as follows: a comparison queue and a comparison stack are instantiated. First, a breadth-first search is performed using the queue to compare whether any additions or deletions have occurred in the macro structure layer by layer. Then, a depth-first search is performed using the stack to delve into each specific text domain node and compare whether the micro-text has been modified. By comparing the hash signatures inside the nodes, nodes with different attributes or payloads are extracted, and these nodes are arranged according to their natural reading order in the document to form a sequence of differing nodes.
[0027] In this embodiment, a local smoothing aggregation calculation based on spatial and hierarchical span weighting is performed on the assembled sequence of dissimilar nodes. The document structure span and character spacing between adjacent dissimilar nodes are calculated. When the span is less than a preset smoothing merging threshold, fragmented micro-dissimilar nodes are merged into a continuous macro-dissimilar node block.
[0028] Specifically, the initially generated sequence of difference nodes is traversed. For any two adjacent first and second difference nodes, their absolute offsets and node depth parameters in the baseline model tree are extracted. The physical character spacing between the two nodes (i.e., the second absolute offset minus the first absolute offset minus the text length of the first node) is calculated, and the hierarchical jump (i.e., the absolute value of the difference between the node depth parameters) is calculated. A smooth merging evaluation function is defined. To eliminate the difference in the dimensional series of features of different dimensions, numerical normalization is introduced before weighting. The specific calculation logic is as follows: the physical character spacing is divided by the set baseline line width constant (which is set to 50 based on A4 paper standard typesetting experience), multiplied by a weight coefficient of 0.6, and the hierarchical jump is multiplied by a weight coefficient of 0.4. This weight allocation is based on the statistical principle that character continuity is superior to structural continuity in document typesetting. The smooth merging threshold is set to 1.5. This threshold is selected based on empirical statistical analysis of the average phrase character length and regular word spacing in the target domain documents to ensure that fragmented phrases are merged rather than complete long sentences.
[0029] The node merging mechanism is triggered only when the physical character spacing between two nodes does not exceed the preset maximum merged character distance threshold (set to 100 characters in this embodiment based on A4 typesetting experience to ensure the merging range is strictly limited to the phrase level), the calculation result of the evaluation function is less than or equal to 1.5, and the distance between the nearest common ancestor nodes of the baseline model trees containing the two nodes does not exceed 2 levels (this span threshold is chosen to be 2 levels because nodes exceeding 2 levels belong to cross-paragraph or cross-block differences, and forced merging would destroy the overall macro DOM structure of the document), and the node merging mechanism is triggered. When the physical character spacing exceeds 100 characters, merging is not triggered regardless of the calculation result of the evaluation function. During merging, the text payload of the second difference node is concatenated to the end of the first difference node with a space, the absolute offset range of the first difference node is updated, and the second difference node is removed from the sequence. This process is iterated until the sequence length no longer changes, and the optimized difference node sequence is finally output. The above process reduces the fragmentation of difference nodes, optimizes addressing memory usage, and improves the coherence of contextual semantic slices.
[0030] Next, plain text stripping is performed on the internal payloads of the difference node sequences. This process removes all typographical embellishments and tags, retaining only the pure character sequences, thus forming and outputting the difference document features. The difference document features are plain text strings representing all substantial textual differences between the two documents.
[0031] To locate the specific spatial position of these differing texts in the deep learning model, the absolute offset and row / column nesting attributes recorded in the baseline model tree are retrieved. Spatial dimension encoding calculation is then performed using the differing node sequence to construct and output spatial coordinate identifiers. The steps for calculating the spatial coordinate identifiers are as follows: the node depth parameter, the combined value of the row / column nesting attributes, and the absolute offset are sequentially converted into string format, and a concatenation calculation is performed using underscores "_" as preset delimiters to generate a combined string; subsequently, a non-cryptographic hash mapping calculation (using the MurmurHash3 algorithm in this embodiment) is performed on this combined string, and the output hash value is the final spatial coordinate identifier.
[0032] In addition, it is necessary to establish the relative relationships between the different nodes. By retrieving the node depth parameters recorded in the baseline model tree, the hierarchical depth difference between adjacent nodes in the different node sequence and the displacement deviation at the same level are calculated, and the offset matrix is established and output.
[0033] The formula for calculating the values of elements within the offset matrix is as follows: Extract the absolute value of the difference in layer depth between adjacent nodes in the comparison node sequence, divide it by the preset maximum layer depth (in this embodiment, the maximum nesting depth is set to 10 based on the statistical maximum nesting depth of the target domain document), normalize it, and then multiply it by the layer attenuation coefficient of 0.7 to obtain the first value; calculate the absolute value of the displacement deviation of the two nodes at the same layer in the sequence, divide this absolute value by the set baseline paragraph length constant (this constant is set to 500), take the maximum value and truncate it to 1, and multiply it by the displacement attenuation coefficient of 0.3 to obtain the second value; add the first value and the second value, and the sum is used as the element value of the corresponding coordinate position of the two nodes in the offset matrix. After the above processing, both values are in the range [0, 1], and the weight coefficients of 0.7 and 0.3 truly reflect the contribution ratio of each dimension. The selection of the hierarchical attenuation coefficient and displacement attenuation coefficient in the formula is determined by combining the grid search algorithm with empirical statistics on semantic fragmentation of contract text. Since the probability of semantic fragmentation caused by vertical level cross-paragraphs is greater than the impact of character displacement within the same horizontal level, the hierarchical attenuation coefficient is set to 0.7 and the displacement attenuation coefficient is set to 0.3. The offset matrix is an N×N square matrix, where N equals the total number of nodes in the difference node sequence calculated by comparing the current document; the element value at position (i, j) in the matrix records the spatial offset between the i-th difference node and the j-th difference node calculated according to the above formula, and the diagonal elements (when i=j) are assigned a value of 0.
[0034] At this point, the baseline model tree, the comparison model tree, the differences in document features, the spatial coordinate labels, and the offset matrix have been output.
[0035] The benchmark and comparison documents are imported into the parsing engine to perform tree stripping processing to generate a model tree with multi-dimensional attributes. Then, plain text stripping and spatial dimension encoding calculation are performed on the internal loads of the difference node sequences to construct spatial coordinate labels. Subsequently, the node depth parameters are retrieved to calculate the depth difference and the displacement deviation of the same level to establish an offset matrix. This step quantifies the spatial displacement relationship between document nodes through depth parameters and absolute offset, providing a rigid mathematical spatial basis for subsequent topological mapping and feature extraction, and effectively avoiding physical hierarchy disorder during placeholder replacement.
[0036] Further, the lexical boundary attributes of the differential document features are extracted and injected into the associated nodes within the offset matrix to perform topological mapping calculations, outputting a text topological dependency graph and topological edge features; based on the text topological dependency graph, offset matrix, and baseline model tree, text concatenation is extracted, outputting a multidimensional joint tensor; this corresponds to step S2 above; see [reference needed]. Figure 2 The specific implementation process includes: The differential document features are segmented and sliced to generate a lexical boundary attribute set carrying boundary length attributes and part-of-speech dependency tags. The node grid parameters recorded in the offset matrix are retrieved, and the associated nodes are located within the offset matrix. The boundary length attributes and part-of-speech dependency tags from the lexical boundary attribute set are injected into the located associated nodes, and a feature overwrite operation is performed to generate a fused node attribute matrix. Graph theory node connection relationship construction is performed on the fused node attribute matrix, and node pairs with master-slave dependency relationships are selected to establish directed connection links, forming the text topology dependency graph. The association parameters of the directed connection links within the text topology dependency graph are analyzed to generate the topology edge features.
[0037] Specifically, the process of text topological dependency graph and topological edge features includes: Using the differential document features as input, word segmentation and slicing calculations are performed. The data generation process involves calling a natural language processing word segmentation engine to segment the strings contained in the differential document features into tokens. The engine calculates the character length of each token and performs part-of-speech tagging (NOT, VOT, etc.). This information is then aggregated to generate and output a set of lexical boundary attributes carrying boundary length attributes and part-of-speech dependency tags.
[0038] Subsequently, using the generated offset matrix as input, the node grid parameters recorded within it (i.e., the row and column indices of the corresponding node in the matrix) are retrieved. The corresponding associated nodes are located within the offset matrix, and the boundary length attribute and part-of-speech dependency tag from the lexical boundary attribute set are used as additional feature vectors. These are then injected into the located associated nodes to perform a feature overwrite operation, generating a fused node attribute matrix, which is then output.
[0039] Using the fused node attribute matrix as input, graph theory node connection relationship construction is performed. The data generation process is as follows: before using the dependency parsing algorithm, the set threshold is that the word length does not exceed 3 Chinese characters (or English words). Fragment nodes below this threshold trigger the template library completion process. Each record in the domain business template library contains three fields: a trigger root word list, a standard preposition string, and a standard postposition string. The trigger root word list is matched by the longest common subsequence search in the template library using the root words after part-of-speech tagging. If no record is found in the search, the completion step is skipped, and the fragment nodes are directly tagged with part-of-speech and then subjected to graph theory connection processing.
[0040] When the template library fails to find any record, or when the confidence score of the found record (i.e., the ratio of the longest common subsequence matching length to the fragment lexical length) is less than 0.5, the template matching is deemed to have failed. The pseudo-complete sentence completion step is skipped, and part-of-speech tagging is directly performed on the fragment nodes. The isolated part-of-speech tagging results are used to participate in the subsequent graph theory connection relationship construction process to avoid systematic semantic biases introduced by incorrect prepositions / postpositions.
[0041] The completed pseudo-complete sentence is processed using a dependency parsing algorithm. The grammatical structure of the words represented by each node is analyzed. By maintaining a state stack and input queue, shift or reduction operations are performed to filter node pairs with subject-verb, verb-object, or other dependency relationships. Directed connections are established between node pairs to construct and output a text topology dependency graph.
[0042] Further analysis of the association parameters of the directed connection links in the graph, including dependency type encoding, direction indicator and confidence probability, and simultaneously extracting the physical layout boundary attributes such as table border offset limit or paragraph line break constraint corresponding to the associated nodes from the offset matrix, and vectorizing the two together to generate and output the topological edge features.
[0043] The differential document features are segmented and sliced to generate a set of lexical boundary attributes. The boundary length attribute and part-of-speech dependency tag are then injected into the associated nodes located by the offset matrix to generate a fused node attribute matrix. Subsequently, node pairs with master-detail dependency relationships are selected to construct a text topological dependency graph and generate topological edge features. This physically binds the lexical dependencies of natural language to the document space grid, enabling the model to perceive the logical connections of context across a single typesetting level and enhancing the model's ability to understand the structure of complex nested documents.
[0044] According to the node relationships recorded in the text topology dependency graph, the difference center node is located in the baseline model tree. The static context nodes adjacent to the difference center node are searched and the static text parameters are extracted and compiled to generate a set of context feature slices. The offset matrix is input into the multilayer perceptron network for nonlinear dimensionality reduction mapping calculation to obtain spatial feature vectors. Word embedding mapping calculation is performed on the set of context feature slices to generate slice word vectors. The spatial feature vectors and the slice word vectors are retrieved and feature channel dimension stacking and concatenated vector splicing operations are performed to synthesize a multi-channel tensor data structure as the multidimensional joint tensor.
[0045] Specifically, the generation process of the multidimensional joint tensor includes: Guided by the text topology dependency graph, the difference center node is located within the baseline model tree. Since isolated difference texts can be semantically ambiguous, the data generation process involves: using the difference center node as the origin, searching for adjacent static context nodes along the reading direction of the model tree and extracting static text parameters, then concatenating and outputting a set of context feature slices. The selection of the number of nodes extracted is based on statistical analysis of the semantic boundary window periods of tens of thousands of documents in the target domain. To balance contextual integrity and memory consumption, this specific number was set to 5 nodes.
[0046] In this embodiment, dynamic noise filtering based on word frequency and inverse document frequency (IVF) is introduced into the generated context feature slice set. The domain weight score of each word within the slice is calculated, combined with a distance decay factor, to filter out common stop words and redundant typographical tags with scores below a set threshold. An offline corpus containing 500,000 documents in the target domain (such as procurement documents) is pre-loaded, and the global IVF of each word in the dictionary is calculated. The calculation process is as follows: extract the total number of documents in the offline corpus, divide it by the number of documents containing the specific word, and calculate the logarithm to the natural constant of the quotient to obtain the global IVF. After obtaining the extracted context feature slice set, word frequency statistics are performed on the internal static text parameters. For any word within the slice set, its local importance score is calculated, which is equal to the word frequency multiplied by the global IVF, and then multiplied by the position decay weight. The positional attenuation weight is calculated based on the absolute physical character distance of the lexical unit from the difference center node. Specifically, it is calculated as the natural constant raised to the power of -0.05. This attenuation coefficient of 0.05 is chosen based on the empirical half-life of contextual influence, aiming to ensure that when the physical distance exceeds approximately 14 characters, the semantic influence weight of adjacent words attenuates to below 50%. In other words, words closer to the difference center node have an exponentially increasing retention priority. A dynamic retention threshold of 0.15 is set. This threshold is determined by offline analysis of the TF-IDF score distribution of tens of thousands of corpora, truncating empirical quantiles at the edge of noise in the long-tail distribution. All lexical units in the slice set are traversed, and redundant lexical units with a local importance score less than 0.15 and whose part-of-speech tags do not belong to domain-specific terms or core entities are forcibly removed (e.g., meaningless conjunctions, residual list numbers, etc.). After filtering, the remaining high-weight lexical units are reassembled in their original reading order, and the denoised context feature slice set is updated and output. The above process effectively eliminates redundant noise data that interferes with semantic recognition, allowing the language model's self-attention mechanism to focus more on core features.
[0047] Using the offset matrix as input, a nonlinear dimensionality reduction mapping calculation is performed within a multilayer perceptron network to obtain and output a spatial feature vector. The calculation steps for the nonlinear dimensionality reduction mapping of the offset matrix are described as follows: First, the variable-dimensional offset matrix is imported into an adaptive pooling layer for spatial feature compression. Since the offset matrix records the relative distance features between discrete nodes, the pooling layer performs block-based dynamic step-size partitioning and local maximum pooling aggregation calculations on the input matrices of different scales according to a preset fixed grid size of 8×8. This extracts the most significant spatial jump features between blocks of each local text sequence, outputting a feature matrix with a constant number of rows and columns of 8×8, totaling 64 elements. Subsequently, this feature map is flattened into a fixed-length 64-dimensional feature vector, which serves as the input to the first hidden layer of the MLP. The input dimension of the first hidden layer weight matrix is 64, and the output dimension is set to 128. The output dimension of the second hidden layer is also set to 64, aligned with the subsequent slice word vector channels. Finally, the feature map is flattened into a fixed-length 1-dimensional feature vector. Next, the 1D feature vector is multiplied by the weight matrix of the first hidden layer, and the bias vector of the first hidden layer is added element-wise to the result. This intermediate matrix is then input into the rectified linear unit activation function, where all values less than zero are set to zero, while values greater than zero remain unchanged. The activated matrix is then multiplied by the weight matrix of the second hidden layer, and the bias vector of the second hidden layer is added. The result is the dimensionality-reduced spatial feature vector. Regarding the parameter selection in the calculation formula, the output dimension of the first hidden layer is set to 128 dimensions for the initial feature compression; the output dimension of the second hidden layer is set to 64 dimensions to ensure alignment with the channel of the sliced word vectors.
[0048] For text features, taking the set of context feature slices as input, a pre-trained language model (e.g., a bidirectional encoder representation model based on the Transformer architecture, such as the BERT base network) is invoked to perform word embedding mapping calculations, converting character slices into dense vectors, and generating and outputting slice word vectors. The choice of slice word vector dimension is directly determined by the underlying pre-trained language model architecture; in this embodiment, the mainstream standard of 768 dimensions is chosen.
[0049] After obtaining the two types of features, the 64-dimensional spatial feature vector and the 768-dimensional slice word vector are concatenated and spliced in memory on the feature channel axis to synthesize and output a multi-channel tensor data structure with a total dimension of 832 as a multi-dimensional joint tensor.
[0050] The static context nodes before and after the difference center node are searched according to the text topological dependency graph to generate a set of feature slices. The spatial feature vector obtained by nonlinear dimensionality reduction of the offset matrix is stacked and concatenated with the slice word vectors through channel dimension stacking. The multi-channel tensor data structure synthesized by this operation forces the downstream semantic recognition network to take into account both the semantic connotation and physical layout structure of the text when extracting latent state features, thereby improving the representation accuracy of complex multimodal features from the bottom data input end.
[0051] Further, the multidimensional joint tensor is input into the semantic recognition network to perform weight allocation calculation, outputting a set of semantic labels. Then, reverse boundary calibration calculation is performed through topological edge features to output a set of verification semantic labels. The set of verification semantic labels, differential document features, spatial coordinate labels, and text topological dependency graph are fused to output a mapped data structure; this corresponds to step S3 above; see [link to relevant documentation]. Figure 3 The specific implementation process includes: The multidimensional joint tensor is imported into the self-attention mechanism layer inside the semantic recognition network to perform self-projection feature matrix multiplication calculation, and the hidden state context tensor is extracted. The hidden state context tensor is imported into a preset fully connected classification layer to perform feature dimension mapping and sampling activation calculation, resulting in a semantic label set. The topological edge features are parsed to extract the structural nesting constraint parameters between the master node and the subordinate nodes. For the initial labels belonging to the subordinate nodes in the semantic label set, if the natural language coverage value exceeds the spatial threshold set by the structural nesting constraint parameters, the lexical sequence of the initial labels is forcibly truncated and reclassified according to the structural nesting constraint parameters, and the final verification label is output. The original labels that have not undergone truncation calculation and the final verification labels in the semantic label set are summarized to generate a verification semantic label set.
[0052] Specifically, the process of outputting the set of semantic tags for verification includes: The semantic recognition network used in this embodiment is a model based on the Transformer encoder architecture. This encoder architecture has a stacked layer count of 6 layers, with each layer containing 12 attention heads in a multi-head attention mechanism. The hidden layer dimension of its internal feedforward neural network is set to 3072 dimensions. The feature channels input to this network have a dimension of 832 dimensions, and the output layer connects to a fully connected classification layer, with the number of classification categories strictly corresponding to the total number of categories in the target domain semantic label set.
[0053] The 832-dimensional multidimensional joint tensors corresponding to all the difference nodes in the current batch are stacked into an N×832-dimensional sequence input matrix according to the natural reading order of the difference nodes in the document, where N is the number of difference nodes in the current batch. At the same time, a learnable absolute position encoding vector of dimension 832 is generated. The position information is injected into each row of the sequence matrix by element-wise addition operation to obtain the sequence feature matrix carrying the position information. Then, it is sent to the self-attention mechanism layer inside the semantic recognition network.
[0054] The multidimensional joint tensor is imported into the self-attention mechanism layer inside the semantic recognition network to perform self-projection feature matrix multiplication. The formula for calculating the self-projection feature matrix multiplication of the extracted hidden state context tensor can be described as follows: the input multidimensional joint tensor (with a feature channel dimension of 832) is multiplied by three independent learnable projection matrices (the projection matrices are non-square matrix weight matrices that map 832 dimensions to 768 dimensions), thereby generating a query matrix, key matrix, and value matrix with a unified feature dimension of 768. First, the inner product of the query matrix and the transpose of the key matrix is calculated. Then, each element of this inner product matrix is divided by the square root of the feature dimension of the key matrix to scale and smooth it, so as to avoid the activation function entering the gradient saturation region. Next, the scaled matrix is input into a normalized exponential function (such as the Softmax function) for calculation, so that the sum of the probability weight values of each row in the mapped matrix is always equal to 1. Finally, matrix multiplication is performed using the normalized probability weight matrix and the value matrix, and the output result is the hidden state context tensor after global context weighting adjustment. The key matrix feature dimension in this formula is determined by dividing the mapped overall feature dimension by the number of attention heads configured in the network. For example, if the overall dimension is set to 768 and the number of attention heads is selected as 12, the key matrix feature dimension is set to 64.
[0055] The hidden state context tensor is imported into the fully connected classification layer, feature dimension mapping and sampling activation calculation are performed, the one with the highest probability is extracted as the predicted classification, and a preliminary set of semantic labels is output.
[0056] To ensure the inference ability of the semantic recognition network, the model training steps are performed. The construction of the model training set is completed by aggregating the dual-document comparison sets in the real industry. Specifically, in the offline phase, manual expert annotation combined with a regular expression engine is used to forcibly identify the real business field categories corresponding to the differential load nodes in the comparison set. In this embodiment, the semantic label set is set to a total of 20 basic categories, covering the core business field types in the contract document field, specifically including but not limited to: transaction amount, signing date, institution name, product specification model, purchase quantity, performance period, etc.; the model training set is composed of no less than 20,000 dual-document comparison sets cross-annotated by manual experts and the regular expression engine, and the real category is converted into a one-hot encoding format as the real semantic label for supervised learning training. The regular expression engine performs a preliminary screening according to the preset pattern library in the field. Example core rules of the pattern library include: the matching rule for the amount field is \d+(\.\d+)?[wan|yuan|yi], the matching rule for the date field is \d{4} year \d{1,2} month \d{1,2} day, and the matching rule for the institution name field is dictionary matching based on the preset institution name dictionary. When the recognition result of the regular engine is inconsistent with the judgment of the manual expert, the judgment of the manual expert shall prevail, and the recognition result of the engine is only used as a reference mark.
[0057] The multi-layer perceptron network and the semantic recognition network are trained using a joint end-to-end optimization method in the same training phase: in each round of forward propagation calculation, the offset matrix sequentially outputs the spatial feature vector through the multi-layer perceptron network, and after being spliced with the sliced word vector to form a multi-dimensional joint tensor, it is sent into the semantic recognition network to complete the semantic label prediction; the weight gradient of the multi-layer perceptron network is backpropagated layer by layer from the loss value of the fully connected classification layer to each parameter layer of the multi-layer perceptron network by the backpropagation algorithm; the weights of the multi-layer perceptron network are initialized using the He normal distribution, and the learning rate scheduling and optimizer parameters are consistent with those of the semantic recognition network.
[0058] The loss function chosen is a weighted cross-entropy loss function to address the class imbalance problem caused by the difference in the frequency of different semantic labels. In each round of forward propagation training, the predicted classification probability distribution output by the fully connected classification layer is extracted, aligned with the one-hot encoding of the real semantic labels, and input into the weighted cross-entropy formula to perform logarithmic calculation, obtaining the final loss value. Based on this loss value, the gradient is calculated using the backpropagation algorithm. The optimizer parameters are chosen to use an adaptive moment estimation weight decay optimizer to perform gradient descent. Its initial learning rate parameter is chosen to be a small 0.00002 to avoid destroying the pre-trained weights, and a linear decay scheduling strategy is adopted. The training batch size parameter is chosen to be set to 32 based on the empirical balance point between hardware memory capacity and parallel processing efficiency. To prevent the model from overfitting during training, the overfitting prevention mechanism parameter is chosen to be a randomly deactivated layer configured in front of the fully connected layer. After comparing the feature transfer efficiency of different values through ablation experiments, its random dropout rate threshold is set to 0.1.
[0059] The semantic recognition network's classification head adopts a domain-adaptive design, and the general underlying encoding weights can be shared across domains. For new application domains, only the semantic label set needs to be replaced, and the classification head needs to be fine-tuned using no less than 500 target domain dual-document comparison sets. Domain transfer can be achieved without training the entire network from scratch.
[0060] The initial semantic label set may exceed its bounds. The topological edge features are analyzed to extract structural nesting constraint parameters between the master node and subordinate nodes. This parameter records the table border offset limit or paragraph line break constraint. Subsequently, the natural language coverage values of the initial labels are extracted.
[0061] In this embodiment, adaptive elastic relaxation calculation is performed on the structural nesting constraint parameters. Based on the rendering attributes of the subordinate node in the baseline model tree, an elastic expansion floating value, calculated adaptively based on the font scaling rate and the remaining white space of the container, is superimposed on the fixed pure physical character limit. Specifically, after obtaining the original structural nesting constraint parameters (such as the pure physical character limit), the dynamic rendering attributes of the subordinate node in the typesetting object model are extracted, including the current font size, the minimum font shrinkage rate allowed by the document rules (fixed at 0.85, i.e., allowing the font to shrink to 85%, determined based on the visual coherence threshold test of the rasterization rendering engine; experiments have shown that when the font shrinkage rate is lower than 85%, the stroke adhesion rate of the characters will increase exponentially, leading to serious misreading in subsequent optical character recognition or manual verification), and the adaptive line break flag of the container where the node is located (a flag of 1 indicates that adaptive height is allowed, and a flag of 0 indicates that the grid is locked). The rules for calculating the elastic expansion floating value are as follows: If the line break flag is 0, the volume expansion coefficient is calculated based on the minimum font shrinkage rate (i.e., a constant 1 divided by the minimum font shrinkage rate of 0.85, then subtracted from the constant 1). The elastic expansion floating value is equal to the upper limit of the pure physical characters multiplied by this volume expansion coefficient, relying solely on implicit font shrinkage to provide space. If the line break flag is 1, the remaining bottom white space pixels of the container and the current default line height are extracted, and the maximum number of lines that can be added is calculated (i.e., the white space pixels divided by the line height, rounded down). In this case, the elastic expansion floating value is equal to the space provided by the font shrinkage mentioned above, plus the upper limit of the pure physical characters multiplied by the maximum number of lines that can be added. The calculated elastic expansion floating value is added to the original capacity upper limit to obtain the final elastic physical space tolerance threshold, which serves as the updated structural nesting constraint parameter. The above process provides a typesetting flexibility mechanism for hard boundary checks, avoiding erroneous truncation in scenarios where font adaptive scaling or line wrapping is allowed.
[0062] The formula for calculating the boundary violation determination of forced truncation can be described as follows: Extract the natural language coverage value of the initial label output by the model, that is, the total number of characters actually occupied by the semantic label in the document string, and subtract it from the physical space tolerance threshold set by the structural nesting constraint parameter to calculate a difference metric. If the difference is greater than zero, it is determined that a natural language semantic boundary violation has occurred. The physical space tolerance threshold in the formula is selected by directly reading the upper limit of the remaining available character capacity of the current target node in the document layout object model. For example, if the current parsing is an independent fixed-width table cell, and the cell can accommodate a maximum of 20 characters according to the layout attributes, then the threshold is strictly set to 20. When a boundary violation is determined, forced truncation is performed on the lexical sequence of the initial label according to the structural nesting constraint parameter to remove the excess tokens.
[0063] For the remaining lexical sequence after truncation, the same pre-trained language model as in the previous steps is invoked to perform word embedding mapping calculations, regenerating 768-dimensional truncated slice word vectors. Subsequently, the 64-dimensional spatial feature vector corresponding to the original difference center node is retrieved, and this spatial feature vector and the truncated slice word vector are re-concatenated along the feature channel axis to synthesize a truncated multidimensional joint tensor with a dimension restored to 832. This 832-dimensional truncated multidimensional joint tensor is then imported into the self-attention mechanism layer of the semantic recognition network for complete forward computation. After extracting the hidden state context tensor, it is then imported into a pre-defined fully connected classification layer for reclassification calculation to ensure that the feature distribution of the truncated path and the normal path input to the fully connected classification layer remains consistent, outputting the final verification label. The original labels and the final verification labels are summarized to generate and output a set of verification semantic labels.
[0064] The topological edge features are analyzed to extract structural nesting constraint parameters between the master node and subordinate nodes. When the natural language coverage of the initial label exceeds the set spatial threshold, forced truncation and reclassification are performed based on the parameter to calculate and output the final verification label. This reverse boundary calibration mechanism introduces the layout rules as a hard constraint indicator into the deep learning network, which effectively suppresses the boundary overflow and structural illusion problems that are easily generated by the single self-attention mechanism, and helps the output range of the final semantic label to strictly adhere to the physical nesting level of the original document.
[0065] A hash calculation is performed on the spatial coordinate identifier to generate a unique hash value for the node; the unique hash value of the node, the final verification label and the original label recorded in the verification semantic label set are retrieved, and a tuple binding operation is performed in combination with the differential document features to concatenate them into a basic multidimensional tuple; the pointing parameters of the directed connection links are extracted from the text topological dependency graph to establish topological constraint features; the basic multidimensional tuple and the topological constraint features are fused and a tensor encapsulation operation is performed to generate a multimodal combination carrier as the mapping data structure, and the final verification label, the original label and the topological constraint features are recorded in the mapping data structure.
[0066] Specifically, the specific generation process of the mapping data structure includes: A one-way hash algorithm (such as SHA-256) is used to calculate the multi-dimensional spatial coordinate identifier. To optimize memory lookup speed, the first 64 bits of the hash digest are extracted as the base hash value. To ensure the uniqueness of nodes, the base hash value is searched in memory for collisions. If a hash collision occurs, the node depth parameter of the colliding node is extracted as a salt value for secondary string concatenation, and the one-way hash operation is re-executed to probe until a collision-free digest truncation value is generated. Finally, this value is output as the unique hash value of the node.
[0067] The process involves retrieving the unique hash value of each node, verifying the final verification label and the original label within the semantic label set, and combining this with the differential document features to perform tuple binding operations in memory, concatenating them into a basic multidimensional tuple. Simultaneously, the pointing parameters of directed connections are extracted from the text topological dependency graph to establish topological constraint feature terms. The basic multidimensional tuple and topological constraint feature terms are then fused together and subjected to tensor encapsulation operations. A serialization protocol is used to package and generate a multimodal combination carrier, which is then output as a mapping data structure and its associated labels and features are persistently recorded.
[0068] A hash calculation is performed on the spatial coordinate identifier to generate a unique hash value for the node, and the semantic tags and differential document features are retrieved and concatenated to form a basic multidimensional tuple. Then, topological constraint features are extracted, fused, and encapsulated using tensor quantization to generate a multimodal combination carrier as a mapping data structure. This process achieves efficient deep binding of spatial physical positioning, semantic verification results, and topological constraints, and optimizes the memory reading and mapping matching efficiency in the process of addressing massive nodes and loading placeholders.
[0069] Further, the mapped data structure is parsed to output a set of logical placeholders; the differential load nodes are located within the baseline model tree according to their spatial coordinates, and the differential load nodes are replaced with associated placeholders from the set of logical placeholders, outputting a constraint model tree; the constraint model tree is serialized to output a structured document template; this corresponds to step S4 above; the specific implementation process includes: The mapping data structure is disassembled and field unpacking is performed. The final verification label, original label, and topological constraint feature item of the internal record are retrieved and string formatting concatenation calculation is performed to generate the associated placeholders. All generated associated placeholders are assembled into the logical placeholder set. The absolute offset and row and column nesting attributes contained in the spatial coordinate identifier are extracted. A search and addressing operation is performed in the baseline model tree to locate and extract the differential load node. For the differential load node, the corresponding associated placeholder in the logical placeholder set is retrieved and a memory address overwrite operation is performed to clear the differential text in the differential load node and load the placeholder data to reconstruct and generate the constraint model tree.
[0070] Specifically, the process of generating the constraint model tree includes: Taking the mapped data structure as input, it performs decomposition and field unpacking processing. The data generation process is as follows: read the final verification label, original label, and topological constraint feature item of the unpacked internal record, and call the built-in character parsing engine to perform string formatting and concatenation calculation. For example, the parsed semantic label "Contract_Amount" and the topological constraint "Type=Currency" are concatenated according to the macro variable syntax specification of the template engine (such as {{}} or ${} syntax) to generate a parameterized string. Among them, the placeholder format is uniformly specified as {{semantic label|data type constraint|character length limit}}, and the fields are separated by vertical bars "|"; the data type constraint is directly mapped by the Type field in the topological constraint feature item, and the character length limit is filled in by the elastic physical space tolerance threshold in the structure nesting constraint parameters; when the same difference node corresponds to multiple topological constraints, the strictest constraint is taken, that is, the smallest character length limit is taken, and the data type constraint is taken according to the priority order of the highest precision type.
[0071] These are the generated associated placeholders. All generated associated placeholders of this type are collected into a logical placeholder set and stored in a buffer.
[0072] Subsequently, since a hash mapping table was established in memory during the initial construction phase, the original physical characteristics such as absolute offsets and row / column nesting attributes are stored as data payloads, and the corresponding spatial coordinate identifiers are used as the retrieval keys for this mapping table. At this point, the spatial coordinate identifiers are input into the hash mapping table as retrieval credentials to perform a lookup, locking and extracting the absolute offsets and row / column nesting attributes of the associated records. Using these coordinate parameters, a search and addressing operation is performed within the baseline model tree retained from the first phase. Thanks to the previous hash mapping and positioning, the differential payload nodes that need to be replaced can be locked and extracted from thousands of tree nodes.
[0073] For locked differential payload nodes, the corresponding associated placeholders within the logical placeholder set are retrieved, and a memory address overwrite operation is performed. During this process, the document is not slowly re-rendered; instead, the memory space pointer occupied by the original differential text within the differential payload node is directly erased in the runtime memory block where the baseline model tree resides. The pointer is then redirected to load the generated associated placeholder data. Since the placeholders themselves incorporate topological constraints (such as character length constraints and data type constraints), this overwrite step reconstructs the original static DOM tree into a constraint model tree with data validation and dynamic filling capabilities. Through the above operations, only the text content pointers of differential payload nodes are redirected and replaced in-situ. The overall structure of the baseline model tree, parent-child node references, and the static text payloads of all non-differential nodes remain unchanged. Thus, without re-rendering or recreating the entire model tree, the baseline model tree is transformed from a state that only stores static text into a constraint model tree with data validation and dynamic filling capabilities.
[0074] The mapping data structure is decomposed to generate a set of logical placeholders, and the absolute offset and row and column nesting attributes are extracted to lock the differential load nodes in the baseline model tree. Then, the corresponding associated placeholders are retrieved to perform memory address overwriting operations to reconstruct and generate the constraint model tree. This addressing and overwriting mechanism ensures that the new placeholder data can be seamlessly embedded into the original text position with memory-level coordinates, preserving the static layout characteristics of the surrounding nodes and reducing the risk of page structure collapse caused by dynamic data replacement.
[0075] The system receives the constraint model tree and performs a node-level traversal operation to separate and extract the static text payload and document layout features carried by the internal nodes; it searches and extracts the data type restriction attributes and hierarchical nesting association parameters carried by the associated placeholders from within the constraint model tree; it retrieves the static text payload, the document layout features, the data type restriction attributes, and the hierarchical nesting association parameters and performs markup language syntax encoding and concatenation calculation to generate a low-level format byte stream; it then performs file header protocol encapsulation and memory persistence writing operations on the low-level format byte stream, compiles it, and outputs the structured document template.
[0076] Specifically, the process of generating a structured document template includes: Receive the newly generated constraint model tree and initiate the serialization output process. Perform node-level traversal operations (e.g., using preorder traversal). During the traversal, separate and extract the static text payload and document layout features (such as font size, paragraph spacing, table border styles, etc.) carried by the unmodified internal nodes. Simultaneously, search and extract the data type constraint attributes and hierarchical nesting association parameters carried by the associated placeholders from within the constraint model tree.
[0077] Next, these two parts are intersected, and the static text payload, document layout features, data type restriction attributes, and hierarchical nesting parameters are retrieved. Markup language syntax encoding and concatenation calculations are then performed strictly according to the target output format (such as the Office Open XML international standard format or the Adobe PDF XFDF protocol). This calculation process downgrades the object model, transforming it into a low-level format byte stream.
[0078] Finally, for this underlying format byte stream, a file header protocol encapsulation is performed at its very beginning (e.g., if the output is a Word document, a magic number header of a ZIP compressed file of PK\x03\x04 is encapsulated; if it is a PDF, a %PDF-1.7 protocol header is encapsulated), and a memory persistent write operation is performed (the byte stream in the buffer is flushed to storage media such as a solid-state drive via I / O stream). The final structured document template is then generated and output through compilation.
[0079] The system receives a constraint model tree to separate static text payloads from document layout features, and searches for data type restriction attributes and hierarchical nesting parameters carried by associated placeholders. Then, it performs markup language syntax encoding and concatenation calculation to convert the data into a low-level format byte stream, and performs file header protocol encapsulation and memory persistence writing. This low-level compilation mechanism ensures that the final output structured document template has strict syntax compliance and data type enforcement, improving the stability of the template during cross-platform parsing and reverse rendering.
[0080] This invention provides an intelligent template generation method based on dual-document comparison. It extracts lexical boundary attributes of the differences between documents, injects them into associated nodes within an offset matrix, performs topological mapping calculations, and outputs a text topological dependency graph and topological edge features. Based on these features, it extracts text concatenation and outputs a multidimensional joint tensor. Subsequently, the multidimensional joint tensor is input into a semantic recognition network to output a set of semantic labels. Then, it performs reverse boundary calibration calculations using topological edge features to output a set of verified semantic labels. Finally, it fuses the output mapping data structure and, after locating and replacing the differences in load nodes within a baseline model tree, outputs a structured document template. This end-to-end mechanism, by fusing one-dimensional lexical boundaries with a multidimensional spatial matrix and introducing physical topology rules to perform forced truncation and boundary calibration on semantic labels, fundamentally achieves deep coupling between dynamic semantic recognition and static physical typesetting. This not only ensures the accuracy of logical placeholder boundaries but also reduces the risk of typesetting misalignment that is easily generated during complex document conversion, improving the accuracy and reliability of automated template generation.
[0081] Example 2 This embodiment takes an intelligent template generation method based on dual-document comparison as an example, applying it to the comparison and structured template generation of medical equipment procurement contracts.
[0082] The system receives a standard medical equipment procurement contract as the baseline document and a modified contract from a medical device supplier as the comparison document. Both documents are imported into a document parsing engine and subjected to a document structure tree stripping process to generate a baseline model tree and a comparison model tree. Each node outputs three core attributes: hierarchical depth parameter, absolute offset, and row / column nesting attribute. Breadth-first search and depth-first search traversals are performed at the same level to compare nodes, extracting nodes with dissimilar attributes to form a sequence of differing nodes. After removing formatting and decoration tags, the differences in document features are output. Spatial dimension encoding is then performed: the hierarchical depth parameter, the combined value of the row / column nesting attribute, and the absolute offset are sequentially converted into string features, and delimiter concatenation is performed. Subsequently, a one-way hash mapping is performed on the concatenated joint string to obtain spatial coordinate identifiers. Simultaneously, an offset matrix is established, and the calculation process for its internal element values is as follows: extract the absolute value of the difference in layer depth between adjacent nodes in the difference node sequence, multiply it by the layer attenuation coefficient of 0.7; calculate the absolute value of the displacement deviation at the same layer, divide it by the set reference segment length constant (such as 500) for dimension normalization, and then multiply it by the displacement attenuation coefficient of 0.3; finally, add the two together to obtain the result.
[0083] The output differential document features are segmented and sliced to generate a lexical boundary attribute set carrying boundary length attributes and part-of-speech dependency tags such as nouns and verbs. The offset matrix grid parameters are retrieved to locate associated nodes, and the lexical boundary attribute set is injected into the associated nodes to perform feature overwriting, outputting a fused node attribute matrix. A dependency parsing algorithm is used to analyze the lexical and grammatical structure of the nodes, selecting subject-verb, verb-object, and other subject-subordinate dependency relationship node pairs, establishing directed connection links, and outputting a text topological dependency graph. The dependency type encoding, direction indicator, and confidence probability of the above links are extracted to generate and output topological edge features.
[0084] Based on the text topology dependency graph, the difference center node is located within the baseline model tree. Five static context nodes are selected and set forward and backward along the reading flow direction (this number is statistically selected based on the semantic boundary window period to balance contextual integrity and memory consumption). Static text parameters are then concatenated to output a set of context feature slices. The offset matrix is input into a multilayer perceptron network for nonlinear dimensionality reduction mapping. The calculation process is as follows: the offset matrix is multiplied by the first hidden layer weight matrix and a first bias vector is added. This result is then input into a rectified linear unit activation function, where values less than 0 are set to 0, and values greater than 0 remain unchanged. The matrix after activation is then multiplied by the second hidden layer weight matrix and a second bias vector is added, outputting a 64-dimensional spatial feature vector. The first hidden layer output dimension is set to 128 for initial feature compression, and the second hidden layer output dimension is strictly set to 64 to facilitate concatenation with subsequent word vectors using feature channel dimensions. A pre-trained language model is then called to perform word embedding mapping calculations on the context feature slice set, outputting 768-dimensional slice word vectors. In memory, the 64-dimensional spatial feature vector and the 768-dimensional slice word vector are concatenated and spliced on the feature channel axis to synthesize a multidimensional joint tensor with an overall dimension of 832.
[0085] A multidimensional joint tensor is imported into the self-attention mechanism layer within the semantic recognition network. The computation process of the hidden state context tensor is as follows: the multidimensional joint tensor is multiplied by three learnable projection matrices to generate a query matrix, a key matrix, and a value matrix; the inner product of the query matrix and the transpose of the key matrix is calculated; each element of the inner product matrix is scaled and smoothed by dividing it by the square root of the key matrix's feature dimension 64 (8); the result is input into a normalized exponential function so that the sum of the probability weights of each row of the mapped matrix equals 1; the probability weight matrix is multiplied by the value matrix to output the hidden state context tensor. This is then imported into a fully connected classification layer to output a preliminary set of semantic labels. Subsequently, a reverse boundary calibration calculation is performed: topological edge features are parsed to extract structural nesting constraint parameters, and the natural language coverage value of the initial labels is subtracted from the physical space tolerance threshold set by the structural nesting constraint parameters. This spatial threshold is selected by directly reading the upper limit of the remaining available character capacity of the current typesetting object model. For example, if the upper limit of the independent table cell in the current medical procurement list is 20, then the threshold is set to 20. If the difference between the subtraction and the result is greater than 0, then the lexical sequence of the initial label is forcibly truncated according to the structural nesting restriction parameter, the excess words are removed and reclassified, and the untruncated labels and the reclassified labels are summarized to output a set of validation semantic labels.
[0086] A one-way hash calculation is performed on the spatial coordinate identifier, and the first 64 bits of the hash digest are extracted to generate a unique hash value for the node. This unique hash value is retrieved, and the semantic tag set and differential document features are verified. A tuple binding operation is then performed in memory, and these are concatenated into a basic multidimensional tuple. Directed connection link parameters are extracted from the text topological dependency graph to establish topological constraint feature terms. The aforementioned basic multidimensional tuple and topological constraint feature terms are packaged and encapsulated according to a preset serialization protocol, and a multimodal combination carrier is output as the mapping data structure.
[0087] The mapping data structure is disassembled, and semantic tags and topological constraint features are concatenated and calculated using template macro variable syntax to generate associated placeholders, forming a logical placeholder set. Absolute offsets and row / column nesting attributes are extracted using spatial coordinate identifiers, and a search and addressing operation is performed within the baseline model tree to locate differential load nodes. For the located nodes, the corresponding associated placeholders are retrieved, and memory address overwriting operations are performed. The original text pointer references are directly erased in runtime memory, and the placeholder data is redirected and loaded, reconstructing the constraint model tree. The constraint model tree is then received, and node hierarchy traversal operations are performed to separate and extract the static text loads, document layout features, data type constraint attributes, and hierarchical nesting association parameters of unmodified nodes. Markup language syntax encoding and concatenation calculations are performed to generate a low-level format byte stream. File header protocol encapsulation and memory persistence writing operations are performed on the low-level format byte stream, compiling and outputting the final structured medical equipment procurement contract template.
[0088] Although embodiments of the invention have been shown and described, it will be understood by those skilled in the art that various changes, modifications, substitutions and alterations can be made to these embodiments without departing from the principles and spirit of the invention, the scope of which is defined by the appended claims and their equivalents.
Claims
1. A smart template generation method based on dual-document comparison, characterized in that, include: The system receives a baseline document and a comparison document, performs hierarchical parsing, outputs a baseline model tree and a comparison model tree, performs matching calculations, and outputs the features of the differing documents, spatial coordinate identifiers, and offset matrices. Lexical boundary attributes of differential document features are extracted and injected into associated nodes within the offset matrix to perform topological mapping calculations, outputting a text topological dependency graph and topological edge features; Text concatenation is extracted based on text topological dependency graph, offset matrix and baseline model tree, and a multidimensional joint tensor is output; The multidimensional joint tensor is input into the semantic recognition network to perform weight allocation calculation, outputting a set of semantic labels. Then, reverse boundary calibration calculation is performed through topological edge features to output a set of verification semantic labels. The set of verification semantic labels, differential document features, spatial coordinate labels and text topological dependency graph are fused to output a mapping data structure. Perform parsing processing on the mapped data structure and output a set of logical placeholders; locate the differential load nodes in the baseline model tree according to the spatial coordinates, replace the differential load nodes with the associated placeholders in the set of logical placeholders, and output the constraint model tree; Perform serialization processing on the constraint model tree and output a structured document template.
2. The intelligent template generation method based on dual-document comparison according to claim 1, characterized in that, The specific process of outputting the difference document features, spatial coordinate identifiers, and offset matrix includes: importing the benchmark document and the comparison document into a preset document parsing engine to perform document structure tree stripping processing, generating a benchmark model tree and a comparison model tree containing node depth parameters, absolute offsets, and row and column nesting attributes; performing same-level breadth traversal and cross-level depth traversal node comparison calculations on the benchmark model tree and the comparison model tree, extracting nodes with different attributes to form a difference node sequence; performing plain text stripping processing on the internal loads of the difference node sequence to form difference document features; retrieving the absolute offsets and row and column nesting attributes recorded in the benchmark model tree, combining them with the difference node sequence to perform spatial dimension encoding calculations, and constructing spatial coordinate identifiers; retrieving the node depth parameters recorded in the benchmark model tree, measuring the level depth difference and same-level displacement deviation between adjacent nodes in the difference node sequence, and performing matrix initialization operations based on the measurement results to establish an offset matrix.
3. The intelligent template generation method based on dual-document comparison according to claim 1, characterized in that, The specific process of outputting the text topological dependency graph and topological edge features includes: performing word segmentation and slicing calculations on the differential document features to generate a lexical boundary attribute set carrying boundary length attributes and part-of-speech dependency tags; retrieving the node grid parameters recorded in the offset matrix, locating the associated nodes within the offset matrix, injecting the boundary length attributes and part-of-speech dependency tags from the lexical boundary attribute set into the located associated nodes to perform feature overwrite operations, generating a fused node attribute matrix; performing graph theory node connection relationship construction processing on the fused node attribute matrix, selecting node pairs with master-slave dependency relationships to establish directed connection links, and constructing the text topological dependency graph; analyzing the association parameters of the directed connection links within the text topological dependency graph to generate the topological edge features.
4. The intelligent template generation method based on dual-document comparison according to claim 1, characterized in that, The specific process of outputting the multidimensional joint tensor includes: locating the difference center node in the baseline model tree according to the node relationship recorded in the text topology dependency graph; searching for the static context nodes adjacent to the difference center node and extracting static text parameters; assembling and generating a context feature slice set; inputting the offset matrix into the multilayer perceptron network for nonlinear dimensionality reduction mapping calculation to obtain spatial feature vectors; performing word embedding mapping calculation on the context feature slice set to generate slice word vectors; and performing feature channel dimension stacking and concatenated vector splicing operations on the spatial feature vectors and the slice word vectors to synthesize a multi-channel tensor data structure as the multidimensional joint tensor.
5. The intelligent template generation method based on dual-document comparison according to claim 1, characterized in that, The specific process of outputting the verification semantic label set includes: importing the multidimensional joint tensor into the self-attention mechanism layer inside the semantic recognition network to perform self-projection feature matrix multiplication calculation, and extracting the hidden state context tensor; importing the hidden state context tensor into a preset fully connected classification layer to perform feature dimension mapping and sampling activation calculation, and obtaining the semantic label set; parsing the topological edge features and extracting the structural nesting constraint parameters between the master node and the subordinate nodes; for the initial labels belonging to the subordinate nodes in the semantic label set, if it is determined that the natural language coverage value exceeds the spatial threshold set by the structural nesting constraint parameters, the lexical sequence of the initial labels is forcibly truncated and reclassified according to the structural nesting constraint parameters, and the final verification label is output; summarizing the original labels and the final verification labels in the semantic label set that have not undergone truncation calculation, and generating the verification semantic label set.
6. The intelligent template generation method based on dual-document comparison according to claim 1, characterized in that, The specific process of outputting the mapping data structure includes: performing hash calculation on the spatial coordinate identifier to generate a unique hash value for the node; retrieving the unique hash value of the node, the final verification label and the original label recorded inside the verification semantic label set, and performing a tuple binding operation in combination with the differential document features to concatenate them into a basic multidimensional tuple; extracting the pointing parameters of the directed connection links from inside the text topological dependency graph to establish topological constraint feature terms; performing a tensor encapsulation operation on the basic multidimensional tuple and the topological constraint feature terms to generate a multimodal combination carrier as the mapping data structure, and recording the final verification label, the original label and the topological constraint feature terms within the mapping data structure.
7. The intelligent template generation method based on dual-document comparison according to claim 1, characterized in that, The specific process of outputting the constraint model tree includes: disassembling the mapping data structure and performing field unpacking; retrieving the final verification label, original label, and topological constraint feature item of the internal record and performing string formatting concatenation calculation to generate the associated placeholders; and assembling all the generated associated placeholders into the logical placeholder set; extracting the absolute offset and row / column nesting attributes contained in the spatial coordinate identifier, performing a search and addressing operation within the baseline model tree, locking and extracting the differential load nodes; for the differential load nodes, retrieving the corresponding associated placeholders within the logical placeholder set and performing a memory address overwrite operation, clearing the differential text within the differential load nodes and loading the placeholder data, and reconstructing to generate the constraint model tree.
8. The intelligent template generation method based on dual-document comparison according to claim 1, characterized in that, The specific generation process of the structured document template includes: receiving the constraint model tree and performing a node-level traversal operation to separate and extract the static text payload and document layout features carried by the internal nodes; searching and extracting the data type restriction attributes and hierarchical nesting association parameters carried by the associated placeholders from within the constraint model tree; retrieving the static text payload, the document layout features, the data type restriction attributes, and the hierarchical nesting association parameters to perform markup language syntax encoding and concatenation calculations, and converting them into a low-level format byte stream; performing file header protocol encapsulation and memory persistence writing operations on the low-level format byte stream, compiling to generate and outputting the structured document template.