A digital textbook editing method that uses Word parsing and one-click import.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2026-04-30
- Publication Date
- 2026-08-11
AI Technical Summary
相关技术不能直接输出符合数字教材编辑系统高合规性要求的结构化数据,导致数据导入后仍需大量人工介入
Smart Images

Figure CN122112152B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of digital education technology, and in particular to a method for editing digital textbooks that parses Word documents and imports them with one click. Background Technology
[0002] With the acceleration of digital transformation in education, digital textbooks have become a core carrier of educational informatization due to their advantages such as strong interactivity, high resource integration, and cross-terminal accessibility. Currently, the vast majority of teachers and publishers still rely on Microsoft Word for the initial creation of textbook content. However, existing technical solutions for migrating these unstructured Word documents to structured digital textbook editing systems generally have limitations: With the development of deep learning, OCR technology has become a common structured method for recognizing and extracting data from document screenshots or PDFs. However, in the specific scenario of digital textbook editing, OCR technology has inherent limitations, such as the conflict between processing efficiency and computing power, insufficient accuracy in style restoration, and poor editability of formulas and complex elements. Existing technologies, whether relying on high-performance OCR recognition or simple format conversion, cannot achieve a balance between parsing efficiency, logical restoration of complex elements, and secondary editability of data. Therefore, there is an urgent need for a method that can delve into the underlying DOM structure of Word and accurately recognize, calculate, and standardize the mapping of text styles, multiple versions of formulas, image parameters, and field objects through specific logical rules, in order to achieve lossless and efficient transfer of textbook resources. Summary of the Invention
[0003] The technical problem addressed by this invention is that related technologies struggle to balance high computational costs with high-precision reconstruction, resulting in low processing efficiency for formula-intensive textbook documents and formulas that are similar in form but not in essence. Related technologies also struggle to achieve deep compatibility with the coexisting old and new formula standards and complex dynamic attributes in Word documents, leading to semantic loss or garbled content in the parsing results. Furthermore, related technologies cannot directly output structured data that meets the high compliance requirements of digital textbook editing systems, necessitating significant manual intervention after data import.
[0004] To solve the above-mentioned technical problems, the present invention provides the following technical solution: A method for editing digital textbooks using Word parsing and one-click import includes the following steps: Step S1: Decompress the uploaded Word document, extract the core XML file group, and build an in-memory DOM tree; Step S2: Traverse the memory DOM tree nodes, trigger different parsing algorithms according to the node type to obtain discrete data, and store the discrete data into structured JSON data; The discrete data includes LaTeX expressions, standard Web image binary streams, integer pixel values, domain cache snapshots, and standard sparse matrix structures; Step S3: Reconstruct and clean the structured JSON data to obtain cleaned structured JSON data; Step S4: By recursively traversing the renderer, the cleaned structured JSON data is rendered into the native components of the digital textbook editing system.
[0005] Preferably, step S1 specifically includes: Step S11: Receive the Word document uploaded by the user, decompress the Word document as a ZIP archive, and extract the core XML file group. The core XML file group includes associated style files, sequence numbering rule files, and core XML content files; Step S12: Read the associated style file to obtain the style definition table. Using the style definition table, perform a recursive backtracking algorithm on the basedOn attribute of the Word style to obtain the flat style lookup table. Step S13: Read the sequence number rule file to obtain the list index library. Using the list index library, parse the abstract numbering definition to obtain the format rules of each level of the list, parse the numbering instances, and associate the numbering instances with the abstract numbering definition. Step S14: Read the core XML content file and load it as an in-memory DOM tree.
[0006] Preferably, step S2 specifically includes: Step S21: Based on the flat style lookup table, traverse the nodes of the memory DOM tree and trigger different parsing algorithms according to the node type; The node types include formula nodes, image nodes, document nodes, and table nodes; Step S22: When the node type is a formula node, construct the dual-engine parsing logic to convert the formula into a LaTeX expression and store it in the text field of the structured JSON data; Step S23: When the node type is an image node, extract the key attribute data of the blipFill and spPr attributes of the image data, perform standardization and normalization on the key attribute data to obtain standard view metadata, verify the format of the image data according to the standard view metadata, obtain the standard Web image binary stream, perform unit alignment and container adaptation by introducing target reference mapping coefficients to calculate integer pixel values, and store the standard Web image binary stream and integer pixel values into structured JSON data. Step S24: When the node type is a document node, perform regular expression parsing on the domain code in the document, obtain the cache node through the valid domain instruction rules, and extract the domain cache snapshot as the structured JSON data content. Step S25: When the node type is a table node, the table structure is transformed into a standard sparse matrix structure using a dynamic programming algorithm based on reverse backtracking and stored in the table field of the structured JSON data.
[0007] Preferably, when the node type is a formula node, the construction of the dual-engine parsing logic specifically includes: If the formula node is identified as a native formula tag, the OMML structure is converted into a MathML description using the preset OMML conversion rules. The native formula tag is then converted into a LaTeX expression using the MathML description and stored in the text field of the structured JSON data. Native formula tags include <m:omath>and <m:omathpara>; If the formula node is identified as <w:object>When the tag has the ProgID prefix "Equation", the corresponding binary file is located and MTEF logic transformation is performed to generate a LaTeX expression, which is then stored in the text field of the structured JSON data.
[0008] Preferably, the corresponding binary file is located and MTEF logical conversion is performed, specifically including: The process involves: stripping OLE container data to locate the start bit of the MTEF data block; reading the MTEF header to locate the MTEF rule version number; initializing the corresponding byte stream reading strategy context based on the MTEF rule version number; and performing bitwise operations based on the current byte stream reading strategy context when reading the options after the record identifier byte. Specifically, this includes: For MTEF rule versions 3.0 and below, extract the high four bits of the current record identifier byte to obtain the options; For MTEF rule versions 3.0 and above, read the next record identifier byte to obtain the options; Read the corresponding parameters based on the option's flag and record type; The record types include LINE nodes, CHAR nodes, TMPL nodes, and EMBELL nodes; The MTEF byte stream is deserialized into a memory multi-way tree structure using a recursive approach, forming an intermediate object tree, specifically including: When a CHAR node is detected, the character encoding and font information in the MTEF byte stream are read and a leaf node is constructed. When a TMPL node is identified, a container node is created based on the template identifier, and the list of child nodes of the template identifier is recursively populated according to the number of child objects defined by the template identifier. When an EMBELL node is detected, the EMBELL node is mounted as a decorator node to the nearest predecessor node; The intermediate object tree is formed until the END node is encountered; The intermediate object tree is traversed using the MTEF-LaTeX mapping table, specifically including: When traversing to a TMPL node, the TMPL node is converted into a LaTeX macro instruction structure, and the parsing results of the TMPL child nodes are filled into the LaTeX macro instruction slots; When traversing to the CHAR node, LaTeX sensitive characters are converted into escape characters that conform to the LaTeX syntax specification, and non-standard encodings defined in the MTEF byte stream are mapped to standard instructions, including Unicode instructions and LaTeX instructions; After the traversal is complete, the LaTeX expression is output and stored in the text field of the structured JSON data.
[0009] Preferably, step S23 specifically includes: Step S231: Obtain image data of the Word document, parse the underlying structure of the Word document, extract key attribute data, and perform standardization and normalization processing on the key attribute data to obtain standard view metadata. The standardization and normalization process includes high-precision display size processing, relative clipping constraint processing, and spatial transformation matrix processing. The standard view metadata includes geometric metrics, clipping boundary parameters, original rotation angle, and mirror flip state; Step S232, verify the format of the image data, specifically including: If the image data is in a non-standard format, it is converted into a standard compatible format to generate bitmap data to be processed. Based on the cropping boundary parameters, the physical pixel coordinates of the bitmap data to be processed are calculated to cut out the image content of the effective viewport area. Based on the original rotation angle and mirror flip state, perform rotation and mirror transformation on the image content of the effective viewport area; If the rotation operation produces a non-rectangular boundary, the non-rectangular boundary is solidified into static pixel data by expanding the canvas and filling the background. The static pixel data is then re-encoded into a standard Web image binary stream and stored in structured JSON data. Step S233: Parse the page setup parameters of the Word document, and obtain the physical width of the text area by subtracting the left and right margins from the total page width, in Twips; Extract the display width from the geometric indicators, use the display width as the numerator and the physical width of the page center as the denominator to form a cross-unit proportional relationship; By introducing a target baseline mapping coefficient to perform unit alignment and container adaptation calculations for cross-unit scale relationships, the CSS pixel width of the image data on the web is generated. The calculation expression is as follows: ; in, The CSS pixel width of the image data on the web. For the target baseline mapping coefficient, For cross-unit proportional relationships, For the physical width of the page core, To display width; The image data is rounded to the nearest integer in CSS pixels on the web, and then stored in structured JSON data.
[0010] Preferably, the calculation expression for the target baseline mapping coefficient is as follows: ; in, The target baseline mapping coefficients.
[0011] Preferably, step S23 specifically includes: Traverse the XML node stream of the Word document. When the start tag node is detected, initialize the state machine and enter the domain resolution context: If the domain is not within the resolution scope, skip the current domain object and its context; If the domain is within the resolution range, the complex instruction domain code is captured and matched against the valid domain instruction rules. If the complex instruction field code conforms to the valid field instruction rules, the current field object is determined to be a compliant field object, and the cache node between the delimiter marker node and the end marker node is located. The field cache snapshot in the cache node is read and stored in the corresponding structured JSON data.
[0012] Preferably, the transformation of the table structure into a standard sparse matrix structure using a dynamic programming algorithm based on reverse backtracking specifically includes: Map the table content in the Word document to a virtual two-dimensional array, and initialize the state transition table corresponding to the dimensions of the virtual two-dimensional array; The state transition table includes a list array and a storage tuple; The initialization includes column pointer maintenance and deletion counters; Starting from the last row of the state transition table, traverse upwards to the first row and perform classification processing based on the merged attribute of the cells; After the traversal is complete, the classified virtual two-dimensional array is stored as a standard sparse matrix structure in the table field of the structured JSON data.
[0013] Preferably, the classification process includes a first classification, a second classification, a third classification, and a fourth classification: First category: If the current row cell is the last row of the table and the merge attribute is continue, then store (1, col) in the state transition table to indicate the starting position of the merge chain; otherwise, store (0, col) in the state transition table. Second category: If the merge attribute of the current row cell is the merge head node, then read the cumulative merged row count of the corresponding position in the next row of the state transition table, calculate the final cross-row value of the current row cell, take the current row cell as the new merge head node, reset the state to (0, col) in the state transition table, and perform pruning operation to delete the redundant cells that have been merged in the next row. Third category: If the merge attribute of the current row cell is merge intermediate node, then read the cumulative merged row number of the next row and perform an increment operation, pass the updated value up to the current position of the state transition table, and perform a pruning operation to delete the redundant cells that have been merged in the next row. Fourth category: If the merge attribute of the current row cell is a normal cell, then the state is reset to (0, col) in the state transition table.
[0014] The beneficial effects of this invention are as follows: By constructing a dual-engine formula parsing logic, combined with a dynamic reading strategy context of MTEF rule version numbers and an MTEF-LaTeX mapping table, mathematical formulas from different versions and sources can be accurately restored to editable standard LaTeX expressions, solving the problems of formula garbled characters and semantic loss in the process of textbook digitization. This invention introduces a cross-metric system adaptive width mapping algorithm. By extracting geometric indicators, cropping boundary parameters, and spatial transformation matrices of the image, and using target baseline mapping coefficients to accurately map EMU and Twips units to CSS integer pixel values on the web, it ensures that the visual proportion, rotation angle, and cropping area of the image on different resolution terminals are completely consistent with the original document. By generating a flattened style lookup table through a recursive backtracking algorithm based on the basedOn attribute, combined with the logical capture of dynamic serial numbers by a list counter state machine, it achieves explicit restoration of complex document layout styles and multi-level nested numbering, avoiding format collapse after import. For complex tables, a dynamic programming algorithm based on reverse backtracking is used for physical pruning and span calculation, generating a standard sparse matrix structure in one step, effectively eliminating redundant space occupation and topological misalignment caused by merging cells. This invention significantly improves the structuring level and restoration accuracy of digital teaching materials, and reduces the cost of manual cleaning and secondary typesetting. Attached Figure Description
[0015] Figure 1 A flowchart illustrating the steps of a digital textbook editing method for Word parsing and one-click import, as provided in one embodiment of the present invention; Figure 2 A flowchart illustrating the steps involved in performing MTEF logical conversion on a binary file; Figure 3 Here is a flowchart of step S24; Figure 4 This is a flowchart of the classification and processing steps. Detailed Implementation
[0016] To make the above-mentioned objects, features and advantages of the present invention more apparent and understandable, the specific embodiments of the present invention will be described in detail below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments.
[0017] Example, refer to Figure 1 This provides a method for editing digital textbooks using Word parsing and one-click import, including the following steps: Step S1: Decompress the uploaded Word document, extract the core XML file group, and build an in-memory DOM tree; Step S2: Traverse the memory DOM tree nodes, trigger different parsing algorithms according to the node type to obtain discrete data, and store the discrete data into structured JSON data; Discrete data includes LaTeX expressions, standard Web image binary streams, integer pixel values, domain cache snapshots, and standard sparse matrix structures; Step S3: Reconstruct and clean the structured JSON data to obtain cleaned structured JSON data; Step S4: By recursively traversing the renderer, the cleaned structured JSON data is rendered into the native components of the digital textbook editing system.
[0018] This invention decompresses the user-uploaded Word document and extracts the core XML file group to build an in-memory DOM tree in step S1, enabling the system to directly obtain complete semantic information and object relationships based on the underlying OpenXML structure of Word, avoiding content loss and structural disorder caused by intermediate format conversion. In step S2, the in-memory DOM tree is traversed and different parsing algorithms are triggered according to node type to convert complex objects into discrete data and write them into structured JSON data, achieving high-fidelity structured extraction of Word's multimodal content. In step S3, the structured JSON data is reconstructed and cleaned to unify field specifications, eliminate redundant data, and correct inconsistent structures. In step S4, the cleaned structured JSON data is rendered into native components of the digital textbook editing system, which can directly map the parsing results to the target system component model and editing capabilities, reducing manual splitting and typesetting costs and secondary production costs, and improving the overall import efficiency and consistency of the final presentation effect.
[0019] It should be noted that the cleaning operation includes empty paragraph filtering, list hierarchy merging, and format redundancy removal; Empty paragraph filtering physically removes redundant blank lines commonly found in Word documents. List hierarchy merging is a method of combining discrete list items into a unified list block structure based on their logical IDs; Format redundancy removal removes duplicate and overlapping style tags, ensuring the simplicity of the JSON structure.
[0020] A recursive renderer is a front-end rendering mechanism. Because JSON data has a tree-like hierarchical structure, the renderer starts from the root node and visits each child node in a depth-first manner. When encountering nested structures, the renderer recursively calls itself to process the internal elements until all leaf nodes have been processed.
[0021] Native components include text components, image components, table editor components, and formula components.
[0022] In a specific embodiment, step S1 specifically includes: Step S11: Receive the Word document uploaded by the user, decompress the Word document as a ZIP archive, and extract the core XML file group. The core XML file group includes associated style files, sequence numbering rule files, and core XML content files; Step S12: Read the associated style file to obtain the style definition table. Using the style definition table, perform a recursive backtracking algorithm on the basedOn attribute of the Word style to obtain the flat style lookup table. Specifically, performing a recursive backtracking algorithm on the basedOn property of Word styles includes: When parsing a StyleID referenced in the core XML content file, the system automatically traces its parent styles upwards to the root node. The system performs a combined calculation of child attributes overriding parent attributes along the entire inheritance chain, such as font, font size, and paragraph spacing, generating a flat style lookup table. This ensures that when parsing the body text, the final calculated style can be directly obtained using only the ID index, resolving issues of lost styles or cascading conflicts.
[0023] Step S13: Read the sequence number rule file to obtain the list index library. Using the list index library, parse the abstract numbering definition to obtain the format rules of each level of the list, parse the numbering instances, and associate the numbering instances with the abstract numbering definition. Step S14: Read the core XML content file and load it as an in-memory DOM tree.
[0024] Specifically, the list counter state machine is initialized in the in-memory DOM tree. When parsing the core XML content file, if a paragraph with a number attribute is detected, the list counter state machine automatically reads the current count value based on the paragraph's ID and indentation level, and performs an increment operation, resetting the counters of all child levels. This dynamic memory mechanism can perfectly restore consecutive numbering across pages, after breaks, and complex multi-level nested sequence numbers like "1.1.2", converting implicit logical numbering into explicit text data.
[0025] In a specific embodiment, step S2 specifically includes: Step S21: Based on the flat style lookup table, traverse the nodes of the memory DOM tree and trigger different parsing algorithms according to the node type; Node types include formula nodes, image nodes, document nodes, and table nodes; Step S22: When the node type is a formula node, construct the dual-engine parsing logic to convert the formula into a LaTeX expression and store it in the text field of the structured JSON data; Step S23: When the node type is an image node, extract the key attribute data of the blipFill and spPr attributes of the image data, perform standardization and normalization on the key attribute data to obtain standard view metadata, verify the format of the image data according to the standard view metadata, obtain the standard Web image binary stream, perform unit alignment and container adaptation by introducing target reference mapping coefficients to calculate integer pixel values, and store the standard Web image binary stream and integer pixel values into structured JSON data. Specifically, the blipFill and spPr properties are used in Word document formatting to describe graphic objects. The blipFill property defines the fill method of a graphic object, while the spPr property describes the style and properties of a graphic object.
[0026] Step S24: When the node type is a document node, perform regular expression parsing on the domain code in the document, obtain the cache node through the valid domain instruction rules, and extract the domain cache snapshot as the structured JSON data content. Step S25: When the node type is a table node, the table structure is transformed into a standard sparse matrix structure using a dynamic programming algorithm based on reverse backtracking and stored in the table field of the structured JSON data.
[0027] In a specific embodiment, when the node type is a formula node, the construction of the dual-engine parsing logic specifically includes: If the formula node is identified as a native formula tag, the OMML structure is converted into a MathML description using the preset OMML conversion rules. The native formula tag is then converted into a LaTeX expression using the MathML description and stored in the text field of the structured JSON data. Native formula tags include <m:omath>and <m:omathpara>; If the formula node is identified as <w:object>When the tag has the ProgID prefix "Equation", the corresponding binary file is located and MTEF logic transformation is performed to generate a LaTeX expression, which is then stored in the text field of the structured JSON data.
[0028] Specifically, the pre-defined OMML conversion rules are a set of logical algorithms built into the system that map Word-specific formats to general mathematical formats. These include tag mapping, special character escaping, and structure reorganization. Tag mapping is used to map fractions in the OMML structure. <m:f>Superscript <m:sup>The tags are converted to LaTeX's \frac syntax or ^ syntax.
[0029] Special character escaping converts specific mathematical symbols in the OMML structure into their corresponding LaTeX escape characters.
[0030] The structure is reorganized by recursively combining the complex nesting in the OMML structure into strings that conform to the MathJax or KaTeX rendering specifications.
[0031] In a specific embodiment, locating the corresponding binary file and performing MTEF logical conversion specifically includes: The process involves: stripping OLE container data to locate the start bit of the MTEF data block; reading the MTEF header to locate the MTEF rule version number; initializing the corresponding byte stream reading strategy context based on the MTEF rule version number; and performing bitwise operations based on the current byte stream reading strategy context when reading the options after the record identifier byte. Specifically, this includes: For MTEF rule versions 3.0 and below, extract the high four bits of the current record identifier byte to obtain the options; For MTEF rule versions 3.0 and above, read the next record identifier byte to obtain the options; Read the corresponding parameters based on the option's flag and record type; Record types include LINE nodes, CHAR nodes, TMPL nodes, and EMBELL nodes; Specifically, when the formula is created by a third-party plugin, such as MathType, Word cannot read it directly in XML form, but instead encapsulates it as a binary OLE object.
[0032] Data stripping from an OLE container involves parsing the OLE storage structure, removing the outer encapsulation information, and accurately locating and extracting the hidden MTEF byte stream.
[0033] The MTEF byte stream is deserialized into a memory multi-way tree structure using a recursive approach, forming an intermediate object tree, specifically including: When a CHAR node is detected, the character encoding and font information in the MTEF byte stream are read and a leaf node is constructed. When a TMPL node is identified, a container node is created based on the template identifier, and the list of child nodes of the template identifier is recursively populated according to the number of child objects defined by the template identifier. When an EMBELL node is detected, the EMBELL node is mounted as a decorator node to the nearest predecessor node; The intermediate object tree is formed until the END node is encountered; Specifically, in the MTEF byte stream, the character encoding is the original byte representing the specific mathematical symbol in the MTEF byte stream, and the font information is the font library index associated with the character in MathType.
[0034] Template identifiers are container type tags used to define the structural skeleton of mathematical formulas. For example, the fraction template identifier tells the parser that it is followed by two sub-objects (numerator and denominator), and the square root template identifier defines the range of the radicand.
[0035] The predecessor node is the object node that was the previous non-EMBELL node.
[0036] The intermediate object tree is traversed using the MTEF-LaTeX mapping table, specifically including: When traversing to a TMPL node, the TMPL node is converted into a LaTeX macro instruction structure, and the parsing results of the TMPL child nodes are filled into the LaTeX macro instruction slots; When traversing to the CHAR node, LaTeX sensitive characters are converted into escape characters that conform to the LaTeX syntax specification, and non-standard encodings defined in the MTEF byte stream are mapped to standard instructions, including Unicode instructions and LaTeX instructions; After the traversal is complete, the LaTeX expression is output and stored in the text field of the structured JSON data.
[0037] Specifically, refer to Figure 2 These are the specific steps for performing MTEF logical conversion on binary files.
[0038] In a specific embodiment, step S23 specifically includes: Step S231: Obtain image data of the Word document, parse the underlying structure of the Word document, extract key attribute data, and perform standardization and normalization processing on the key attribute data to obtain standard view metadata. Standardization and normalization processing includes high-precision display size processing, relative clipping constraint processing, and spatial transformation matrix processing; Specifically, high-precision display size processing includes extracting the geometric dimensions of the image data within the Word document layout. The original unit of measurement for these geometric dimensions is EMU, which is the base unit used in Word documents for high-precision graphics operations. The system retains this high-precision value as the basis for subsequent scaling calculations.
[0039] Relative cropping constraint processing involves extracting cropping boundary parameters from the image data relative to its original base image. These cropping boundary parameters are stored in OpenXML as integers that are multiples of 100,000 percentages. The system converts the large integer format stored within the document into a standard floating-point percentage format to precisely define the effective viewport area.
[0040] Spatial transformation matrix processing includes extracting the rotation angle and mirror flip state of the image. The rotation angle is in units of 1 / 60000 degrees, and the internal angle units are normalized to standard degrees for subsequent geometric correction.
[0041] Standard view metadata includes geometric metrics, clipping boundary parameters, original rotation angle, and mirror flip status; Specifically, geometric metrics include display width and display height; The cropping boundary parameters include the left cropping ratio, right cropping ratio, top cropping ratio, and bottom cropping ratio; Mirror flip states include horizontal flip and vertical flip.
[0042] Step S232, verify the format of the image data, specifically including: If the image data is in a non-standard format, it is converted into a standard compatible format to generate bitmap data to be processed. Based on the cropping boundary parameters, the physical pixel coordinates of the bitmap data to be processed are calculated to cut out the image content of the effective viewport area. Based on the original rotation angle and mirror flip state, perform rotation and mirror transformation on the image content of the effective viewport area; If the rotation operation produces a non-rectangular boundary, the non-rectangular boundary is solidified into static pixel data by expanding the canvas and filling the background. The static pixel data is then re-encoded into a standard Web image binary stream and stored in structured JSON data. Step S233: Parse the page setup parameters of the Word document, and obtain the physical width of the text area by subtracting the left and right margins from the total page width, in Twips; Specifically, Twips is one-twentieth of a pound and is the standard unit in the field of typography.
[0043] Extract the display width from the geometric indicators, use the display width as the numerator and the physical width of the page center as the denominator to form a cross-unit proportional relationship; By introducing a target baseline mapping coefficient to perform unit alignment and container adaptation calculations for cross-unit scale relationships, the CSS pixel width of the image data on the web is generated. The calculation expression is as follows: ; in, The CSS pixel width of the image data on the web. For the target baseline mapping coefficient, For cross-unit proportional relationships, For the physical width of the page core, To display width; The image data is rounded to the nearest integer in CSS pixels on the web, and then stored in structured JSON data.
[0044] It should be noted that, in order to ensure that images maintain the same text-image layout ratio as the original document on terminals with different resolutions (especially mainstream mobile devices) after being imported into the target web product, the system must calculate a precise CSS pixel width value. This calculation process needs to cross the complex hybrid measurement system of Word and the single pixel system of the web. This invention proposes and adopts a method of introducing target benchmark mapping coefficients for unit alignment and container adaptation calculations.
[0045] In a specific embodiment, the calculation expression for the target baseline mapping coefficient is as follows: ; in, The target baseline mapping coefficients.
[0046] It should be noted that molecules The image uses a high-precision display width, measured in EMUs; the denominator uses the page margin width, measured in Twips. Because the numerator and denominator use different units of measurement (the objective conversion standard is 1 Twip = 635 EMUs), the ratio obtained by directly dividing them is physically misaligned and cannot be used directly as a percentage. A target reference mapping coefficient is introduced to simultaneously achieve unit alignment and target container adaptation.
[0047] The target baseline mapping coefficient is not an arbitrary empirical value, but a composite factor derived from explicit physical and engineering goals. Mathematically, it is the ratio of the target web product's baseline width (set at 750px) to the unit conversion factor (635 EMU / Twip): ; In engineering terms, it is rounded to 1.2; For complex text and image objects in Word documents, a complete processing workflow was designed, from view metadata extraction and binary physical reconstruction to adaptive adaptation across measurement systems. This workflow aims to solve the problem of image distortion and misalignment caused by differences in rendering mechanisms and measurement units between Word documents and the web environment, achieving high-fidelity restoration.
[0048] In a specific embodiment, step S23 specifically includes: Traverse the XML node stream of the Word document. When the start tag node is detected, initialize the state machine and enter the domain resolution context: If the domain is not within the resolution scope, skip the current domain object and its context; If the domain is within the resolution range, the complex instruction domain code is captured and matched against the valid domain instruction rules. If the complex instruction field code conforms to the valid field instruction rules, the current field object is determined to be a compliant field object, and the cache node between the delimiter marker node and the end marker node is located. The field cache snapshot in the cache node is read and stored in the corresponding structured JSON data.
[0049] Specifically, when the XML node stream parses the core XML content file, it is a series of structured data sequences that are read in real time by the parser according to the order of the document elements.
[0050] The starting marker node is <w:fldchar fldchartype="begin">Complex instruction domain code is <w:instrtext>The separator marks the node as <w:fldchar fldchartype="separate">The end marker node is <w:fldchar fldchartype="end"> If complex instruction domain code <w:instrtext>If the rules of valid domain directives are met, the current domain object is determined to be a compliant domain object, and the system locates the delimiter marker node. <w:fldchar fldchartype="separate">With end marker node <w:fldchar fldchartype="end">Between cache nodes, read the domain cache snapshot in the cache node.
[0051] The resolution scope refers to the range of domain objects that the system allows to be resolved based on the instruction whitelist policy. The system does not resolve all Word fields, but only those domain objects that fall within the whitelist policy's coverage are processed further, such as SEQ auto-serial numbers and REF references; when the state machine detects... <w:fldchar fldchartype="begin">Upon entering the domain resolution context, it first determines whether the domain is within the resolution scope. If it is not within the resolution scope, the domain and its entire context are skipped, and no more commands are captured or cached results are retrieved.
[0052] The valid field instruction rules are built into the system and are used for whitelisted fields. <w:instrtext>This is a set of rules for matching and validating instruction content. Its purpose is to determine whether an instruction in this field is a compliant instruction recognized by the system. For example, "SEQ \* \s1" means that the system will capture... <w:instrtext>The instruction content is matched with the built-in rules. Only when the match is successful will the snapshot extraction of the "delimiter to cached results" range proceed. This is to utilize the pre-calculated field results in Word and avoid the inconsistency risk caused by recalculation.
[0053] In a specific embodiment, the transformation of the table structure into a standard sparse matrix structure using a dynamic programming algorithm based on reverse backtracking specifically includes: Map the table content in the Word document to a virtual two-dimensional array, and initialize the state transition table corresponding to the dimensions of the virtual two-dimensional array; The state transition table consists of a list array and a storage tuple; Initialization includes column pointer maintenance and deletion counters; Specifically, the state transition table stores the cumulative number of merged rows and the index of the column to be deleted for each logical coordinate, and includes a list array List. <Map<int, Tuple> >, memo[row][colInx] and store tuples (accuRow, removeCol).
[0054] The column pointer is maintained by using the curInx pointer to track the current logical column index, taking into account the offset caused by colspan; the deletion counter is maintained by removingColCnts, which is used to correct the index offset when physically deleting array elements, so curInx=0 and removeColCnts=0; Starting from the last row of the state transition table, traverse upwards to the first row and perform classification processing based on the merged attribute of the cells; After the traversal is complete, the classified virtual two-dimensional array is stored as a standard sparse matrix structure in the table field of the structured JSON data.
[0055] Specifically, traditional forward (top-down) parsing cannot predict how many rows the cell with vMerge=restart spans, often requiring a second scan. This solution uses reverse (bottom-up) traversal, leveraging dynamic programming to allow each row to inherit the merged state of the next row, thus completing span calculation and redundancy removal simultaneously in a single traversal.
[0056] Reference Figure 3 The diagram below shows the specific steps of step S24.
[0057] In a specific embodiment, the classification process includes a first classification, a second classification, a third classification, and a fourth classification: First category: If the current row cell is the last row of the table and the merge attribute is continue, then store (1, col) in the state transition table to indicate the starting position of the merge chain; otherwise, store (0, col) in the state transition table. Second category: If the merge attribute of the current row cell is the merge head node, then read the cumulative merged row count of the corresponding position in the next row of the state transition table, calculate the final cross-row value of the current row cell, take the current row cell as the new merge head node, reset the state to (0, col) in the state transition table, and perform pruning operation to delete the redundant cells that have been merged in the next row. Third category: If the merge attribute of the current row cell is merge intermediate node, then read the cumulative merged row number of the next row and perform an increment operation, pass the updated value up to the current position of the state transition table, and perform a pruning operation to delete the redundant cells that have been merged in the next row. Fourth category: If the merge attribute of the current row cell is a normal cell, then the state is reset to (0, col) in the state transition table.
[0058] Specifically, refer to Figure 4 This is a diagram showing the specific steps involved in the classification process.
[0059] In this embodiment, (x,col) represents the cumulative count of merged rows, and col is the column identifier. (1,col) and (0,col) represent the specific states of (x,col) when x is 1 and x is 0, respectively, indicating the starting state and clearing state of the merged chain accumulation. The pruning operation finds the cell corresponding to the next row based on `last[removeCol]`. Since this cell has already been merged into the current cell, and to conform to HTML rendering standards (i.e., when `rowspan` exists, the crossed rows should not have placeholder `td` elements), physical deletion is performed. The pruned data structure no longer contains merged ghost cells, directly outputting a sparse matrix structure that conforms to HTML and web editor standards, completely solving the persistent problem of extra blank cells or misalignments after importing complex nested tables.
[0060] CaseA: Bottom boundary (row == rows - 1); If the attribute is continue, mark the state as (1, col), indicating the start of the merge chain; otherwise, mark it as (0, col).
[0061] Case B: Encountered the merge head node (vMerge=="restart"); Read the status of the next row in the same column: last = memo[row+1][curInx].
[0062] Calculate Rowspan: curCell.rowspan = last[accuRow] + 1. The exact number of merged rows is now calculated. The current cell becomes the new header, and the state transition table (memo) records it as (0, col). Find the cell corresponding to the next row based on last[removeCol]. Since this cell has already been merged into the current cell, and to conform to HTML rendering standards, perform a physical deletion: delvirtual2dArr[row+1][targetIndex].
[0063] The HTML rendering standard dictates that when rowspan exists, the rows it spans should not have placeholder text (td) elements.
[0064] Case C: Encountered an intermediate node for merging (vMerge=="continue"); State accumulation: Query the state of the next row, update memo to (last[accuRow]+1,col), and propagate the merge depth upwards. Similarly, physically delete the corresponding cell in the next row, ensuring that each level retains only valid header or non-merged cells, and destroyed intermediate states that have been merged after the count has been propagated upwards. If the next row has no corresponding merged record (data anomaly), it is treated as an independent cell to prevent index out-of-bounds errors.
[0065] CaseD: A regular cell; The state is reset to (0, col), and no further processing is performed.
[0066] Final output: After traversal, the virtual 2D array (virtual2dArr) has been cleaned into a standard sparse matrix structure, which can be directly mapped to HTML.
[0067]
[0068] Figure 1 Figure 1
[0069] No further front-end merging calculations are required. By constructing a dual-engine formula parsing logic, combined with a dynamic reading strategy context for MTEF rule version numbers and an MTEF-LaTeX mapping table, mathematical formulas from different versions and sources can be accurately restored to editable standard LaTeX expressions, solving the problems of formula garbled characters and semantic loss in the process of textbook digitization. This invention introduces a cross-metric system adaptive width mapping algorithm. By extracting geometric indicators, cropping boundary parameters, and spatial transformation matrices of the image, and using target baseline mapping coefficients to accurately map EMU and Twips units to CSS integer pixel values on the web, it ensures that the visual proportion, rotation angle, and cropping area of the image on different resolution terminals are completely consistent with the original document. By generating a flattened style lookup table through a recursive backtracking algorithm based on the basedOn attribute, combined with the logical capture of dynamic serial numbers by a list counter state machine, it achieves explicit restoration of complex document layout styles and multi-level nested numbering, avoiding format collapse after import. For complex tables, a dynamic programming algorithm based on reverse backtracking is used for physical pruning and span calculation, producing a standard sparse matrix structure in one step, effectively eliminating redundant space occupation and topological misalignment caused by merging cells. This invention significantly improves the structuring level and restoration accuracy of digital teaching materials, and greatly reduces the cost of manual cleaning and secondary typesetting. Those skilled in the art will understand that embodiments of this invention can be provided as methods, systems, or computer program products. Therefore, this invention can take the form of a completely hardware embodiment, a completely software embodiment, or an embodiment combining software and hardware aspects. Moreover, this invention can take the form of a computer program product implemented on one or more computer-usable storage media containing computer-usable program code. The storage medium can be implemented by any type of volatile or non-volatile storage device or a combination thereof, such as Static Random Access Memory (SRAM), Electrically Erasable Programmable Read-Only Memory (EEPROM), Erasable Programmable Read Only Memory (EPROM), Programmable Read-Only Memory (PROM), Read-Only Memory (ROM), magnetic storage, flash memory, magnetic disk, or optical disk.These computer program instructions may also be stored in a computer-readable storage medium that can direct a computer or other programmable data processing device to function in a particular manner, such that the instructions stored in the computer-readable storage medium produce an article of manufacture including instruction means that implement the functions specified in one or more steps and / or one or more blocks. It should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention and are not intended to limit it. Although the present invention has been described in detail with reference to preferred embodiments, those skilled in the art should understand that modifications or equivalent substitutions can be made to the technical solutions of the present invention without departing from the spirit and scope of the technical solutions of the present invention, and all such modifications or substitutions should be covered within the protection scope of the present invention. < / w:instrtext> < / w:instrtext> < / w:fldchar> < / w:fldchar> < / w:fldchar> < / w:instrtext> < / w:fldchar> < / w:fldchar> < / w:instrtext> < / w:fldchar> < / m:sup> < / m:f> < / w:object> < / m:omathpara> < / m:omath> < / w:object> < / m:omathpara> < / m:omath>
Claims
1. A method for editing digital textbooks using Word parsing and one-click import, characterized in that, Includes the following steps: Step S1: Decompress the uploaded Word document, extract the core XML file group, and build an in-memory DOM tree and a flattened style lookup table; Step S2: Based on the flat style lookup table, traverse the memory DOM tree nodes, trigger different parsing algorithms according to the node type to obtain discrete data, and store the discrete data into structured JSON data; The node types include formula nodes, image nodes, document nodes, and table nodes; When the node type is a formula node, a dual-engine parsing logic is constructed to convert the formula into a LaTeX expression and store it in the text field of structured JSON data; When the node type is an image node, key attribute data related to the blipFill and spPr attributes of the image data is extracted. This key attribute data is then standardized to obtain standard view metadata. Based on the standard view metadata, the format of the image data is validated to obtain a standard Web image binary stream. Integer pixel values are calculated by introducing target baseline mapping coefficients for unit alignment and container adaptation. The standard Web image binary stream and integer pixel values are then stored in structured JSON data, specifically including: The system acquires image data from Word documents, parses the underlying structure of Word documents, extracts key attribute data, and performs standardization and normalization processing on the key attribute data to obtain standard view metadata. The standardization and normalization process includes high-precision display size processing, relative clipping constraint processing, and spatial transformation matrix processing. The standard view metadata includes geometric metrics, clipping boundary parameters, original rotation angle, and mirror flip state; Verify the format of the image data, specifically including: If the image data is in a non-standard format, it is converted into a standard compatible format to generate bitmap data to be processed. Based on the cropping boundary parameters, the physical pixel coordinates of the bitmap data to be processed are calculated to cut out the image content of the effective viewport area. Based on the original rotation angle and mirror flip state, perform rotation and mirror transformation on the image content of the effective viewport area; If the rotation operation produces a non-rectangular boundary, the non-rectangular boundary is solidified into static pixel data by expanding the canvas and filling the background. The static pixel data is then re-encoded into a standard Web image binary stream and stored in structured JSON data. Parse the page setup parameters of a Word document, subtract the left and right margins from the total page width to obtain the physical width of the text area, in Twips; Extract the display width from the geometric indicators, use the display width as the numerator and the physical width of the page center as the denominator to form a cross-unit proportional relationship; By introducing a target baseline mapping coefficient to perform unit alignment and container adaptation calculations for cross-unit scale relationships, the CSS pixel width of the image data on the web is generated. The calculation expression is as follows: ; in, The CSS pixel width of the image data on the web. For the target baseline mapping coefficient, For cross-unit proportional relationships, For the physical width of the page core, To display width; The CSS pixel width of the image data on the web is rounded to the nearest integer to obtain an integer pixel value, which is then stored in structured JSON data. When the node type is a document node, the domain code in the document is parsed using regular expressions, and the cache node is obtained through valid domain directive rules. The domain cache snapshot is then extracted as the structured JSON data content. When the node type is a table node, a dynamic programming algorithm based on reverse backtracking is used to transform the table structure into a standard sparse matrix structure, which is then stored in the table fields of the structured JSON data, specifically including: Map the table content in the Word document to a virtual two-dimensional array, and initialize the state transition table corresponding to the dimensions of the virtual two-dimensional array; The state transition table includes a list array and a storage tuple; The initialization includes column pointer maintenance and deletion counters; Starting from the last row of the state transition table, traverse upwards to the first row and perform classification processing based on the merged attribute of the cells; After the traversal is complete, the classified virtual two-dimensional array is stored as a standard sparse matrix structure in the table field of the structured JSON data. The classification process includes four categories: Category 1, Category 2, Category 3, and Category 4. First category: If the current row cell is the last row of the table and the merge attribute is continue, then store (1, col) in the state transition table to indicate the starting position of the merge chain; otherwise, store (0, col) in the state transition table. Second category: If the merge attribute of the current row cell is the merge head node, then read the cumulative merged row count of the corresponding position in the next row of the state transition table, calculate the final cross-row value of the current row cell, take the current row cell as the new merge head node, reset the state to (0, col) in the state transition table, and perform pruning operation to delete the redundant cells that have been merged in the next row. Third category: If the merge attribute of the current row cell is merge intermediate node, then read the cumulative merged row number of the next row and perform an increment operation, pass the updated value up to the current position of the state transition table, and perform a pruning operation to delete the redundant cells that have been merged in the next row. Fourth category: If the merged attribute of the current row cell is a normal cell, then the state is reset to (0, col) in the state transition table. The discrete data includes LaTeX expressions, standard Web image binary streams, integer pixel values, domain cache snapshots, and standard sparse matrix structures; Step S3: Reconstruct and clean the structured JSON data to obtain cleaned structured JSON data; Step S4: By recursively traversing the renderer, the cleaned structured JSON data is rendered into the native components of the digital textbook editing system.
2. The digital textbook editing method for Word parsing and one-click import as described in claim 1, characterized in that, Step S1 specifically includes: Step S11: Receive the Word document uploaded by the user, decompress the Word document as a ZIP archive, and extract the core XML file group. The core XML file group includes associated style files, sequence numbering rule files, and core XML content files; Step S12: Read the associated style file to obtain the style definition table. Using the style definition table, perform a recursive backtracking algorithm on the basedOn attribute of the Word style to obtain the flat style lookup table. Step S13: Read the sequence number rule file to obtain the list index library. Using the list index library, parse the abstract numbering definition to obtain the format rules of each level of the list, parse the numbering instances, and associate the numbering instances with the abstract numbering definition. Step S14: Read the core XML content file and load it as an in-memory DOM tree.
3. The digital textbook editing method for Word parsing and one-click import as described in claim 1, characterized in that, When the node type is a formula node, the specific steps for constructing the dual-engine parsing logic include: If the formula node is identified as a native formula tag, the OMML structure is converted into a MathML description using the preset OMML conversion rules. The native formula tag is then converted into a LaTeX expression using the MathML description and stored in the text field of the structured JSON data. Native formula tags include <m:omath>and <m:omathpara> ;< / m:omathpara> < / m:omath> If the formula node is identified as <w:object> When the tag has the ProgID prefix "Equation", the corresponding binary file is located and MTEF logic transformation is performed to generate a LaTeX expression, which is then stored in the text field of the structured JSON data.< / w:object> 4. The digital textbook editing method for Word parsing and one-click import as described in claim 3, characterized in that, Locate the corresponding binary file and perform MTEF logical conversion, specifically including: The process involves: stripping OLE container data to locate the start bit of the MTEF data block; reading the MTEF header to locate the MTEF rule version number; initializing the corresponding byte stream reading strategy context based on the MTEF rule version number; and performing bitwise operations based on the current byte stream reading strategy context when reading the options after the record identifier byte. Specifically, this includes: For MTEF rule versions 3.0 and below, extract the high four bits of the current record identifier byte to obtain the options; For MTEF rule versions 3.0 and above, read the next record identifier byte to obtain the options; Read the corresponding parameters based on the option's flag and record type; The record types include LINE nodes, CHAR nodes, TMPL nodes, and EMBELL nodes; The MTEF byte stream is deserialized into a memory multi-way tree structure using a recursive approach, forming an intermediate object tree, specifically including: When a CHAR node is detected, the character encoding and font information in the MTEF byte stream are read and a leaf node is constructed. When a TMPL node is identified, a container node is created based on the template identifier, and the list of child nodes of the template identifier is recursively populated according to the number of child objects defined by the template identifier. When an EMBELL node is detected, the EMBELL node is mounted as a decorator node to the nearest predecessor node; The intermediate object tree is formed until the END node is encountered; The intermediate object tree is traversed using the MTEF-LaTeX mapping table, specifically including: When traversing to a TMPL node, the TMPL node is converted into a LaTeX macro instruction structure, and the parsing results of the TMPL child nodes are filled into the LaTeX macro instruction slots; When traversing to the CHAR node, LaTeX sensitive characters are converted into escape characters that conform to the LaTeX syntax specification, and non-standard encodings defined in the MTEF byte stream are mapped to standard instructions, including Unicode instructions and LaTeX instructions; After the traversal is complete, the LaTeX expression is output and stored in the text field of the structured JSON data.
5. The digital textbook editing method for Word parsing and one-click import as described in claim 1, characterized in that, The expression for calculating the target baseline mapping coefficient is: ; in, For the target baseline mapping coefficient, (·,1) is a function to take one decimal place.
6. The digital textbook editing method for Word parsing and one-click import as described in claim 1, characterized in that, The processing logic for node types that are document nodes specifically includes: Traverse the XML node stream of the Word document. When the start tag node is detected, initialize the state machine and enter the domain resolution context: If the domain is not within the resolution scope, skip the current domain object and its context; If the domain is within the resolution range, the complex instruction domain code is captured and matched against the valid domain instruction rules. If the complex instruction field code conforms to the valid field instruction rules, the current field object is determined to be a compliant field object, and the cache node between the delimiter marker node and the end marker node is located. The field cache snapshot in the cache node is read and stored in the corresponding structured JSON data.
Citation Information
Patent Citations
Structured analysis method and system for docx format document
CN111062187A
Cross-platform MatchType formula conversion method and device
CN111144071A
Digital textbook editing and transmitting system with multilayer architecture
CN120822493A