Document processing method and device, electronic equipment, computer readable storage medium and computer program product
Patent Information
- Application Number
- CN202510429102.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-04-07
- Publication Date
- 2026-10-16
AI Technical Summary
[0003]相关技术往往仅使用一种固定的解析方式,将文档应用的标记语言进行转换,在文档结构或内容复杂的情况下,解析速率低下
[0027] On the one hand, by determining the target parsing method for the first document of the first type of markup language through at least one feature parameter, the first document is parsed to obtain a second document of the syntax of the second type of markup language. This method can dynamically select a parsing method that matches the complexity of different feature dimensions, thereby improving the intelligence and flexibility of parsing method conversion, increasing parsing efficiency, and shortening document processing time. On the other hand, by converting the first element based on the syntactic structure of the first document, the method ensures that the converted second document is consistent with the first document in terms of semantics and structure, thus improving the quality of document conversion.
Smart Images

Figure CN122927256A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of data processing technology, and in particular to a document processing method, apparatus, electronic device, computer-readable storage medium, and computer program product. Background Technology
[0002] In the field of digital document processing, markup languages are widely used to represent and structure text content. Different types of markup languages have different uses and advantages. For example, Hypertext Markup Language (HTML) is mainly used for web page display, while Markdown, a lightweight markup language, is often used for writing documents and notes due to its simplicity and ease of use. As the diversity and complexity of documents continue to increase, how to efficiently convert one markup language into another to adapt to different application scenarios and needs has become an important issue.
[0003] Related technologies often use only one fixed parsing method to convert the markup language used in the document, resulting in low parsing speed when the document structure or content is complex. Summary of the Invention
[0004] This application provides a document processing method, apparatus, electronic device, computer-readable storage medium, and computer program product that can improve document parsing efficiency.
[0005] The technical solution of this application embodiment is implemented as follows:
[0006] This application provides a document processing method, the method comprising:
[0007] Obtain the first document based on the first type markup language;
[0008] Obtain at least one feature parameter of the first document, wherein one of the feature parameters characterizes the complexity of the first document in one feature dimension;
[0009] From a set of preset document parsing methods, determine the target parsing method that matches the at least one feature parameter;
[0010] The first document is parsed based on the target parsing method to obtain the grammatical structure of the first document;
[0011] The first element in the grammatical structure is converted into a second element that conforms to the grammar of the second type of markup language, and the second element is combined into a second document.
[0012] In the above scheme, converting the first element in the grammatical structure into a second element conforming to the syntax of the second type of markup language, and combining the second element into a second document, includes:
[0013] Based on the element type of the first element, according to the preset mapping rule corresponding to the element type, the first element is mapped to the second element that conforms to the syntax of the second type markup language;
[0014] The second element is combined into a second document according to the grammatical structure described above.
[0015] This application provides a document processing apparatus, the apparatus comprising:
[0016] The document retrieval module is used to retrieve the first document based on the first type markup language;
[0017] A parameter acquisition module is used to acquire at least one feature parameter of the first document, wherein one of the feature parameters characterizes the complexity of the first document in one feature dimension;
[0018] The method determination module is used to determine, from a plurality of preset document parsing methods, a target parsing method that matches the at least one feature parameter;
[0019] The document parsing module is used to parse the first document based on the target parsing method to obtain the grammatical structure of the first document;
[0020] An element conversion module is used to convert the first element in the grammatical structure into a second element that conforms to the syntax of a second type of markup language, and to combine the second element into a second document.
[0021] This application provides an electronic device, the electronic device comprising:
[0022] Memory is used to store executable instructions or computer programs.
[0023] The processor, when executing computer-executable instructions or computer programs stored in the memory, implements the document processing method provided in the embodiments of this application.
[0024] This application provides a computer-readable storage medium storing a computer program or computer-executable instructions, which, when executed by a processor, implements the document processing method provided in this application.
[0025] This application provides a computer program product, including a computer program or computer executable instructions. When the computer program or computer executable instructions are executed by a processor, they implement the document processing method provided in this application.
[0026] The embodiments of this application have the following beneficial effects:
[0027] On the one hand, by determining the target parsing method for the first document of the first type of markup language through at least one feature parameter, the first document is parsed to obtain a second document of the syntax of the second type of markup language. This method can dynamically select a parsing method that matches the complexity of different feature dimensions, thereby improving the intelligence and flexibility of parsing method conversion, increasing parsing efficiency, and shortening document processing time. On the other hand, by converting the first element based on the syntactic structure of the first document, the method ensures that the converted second document is consistent with the first document in terms of semantics and structure, thus improving the quality of document conversion. Attached Figure Description
[0028] Figure 1 This is a schematic diagram of the architecture of the document processing system 100 provided in an embodiment of this application;
[0029] Figure 2 This is a schematic diagram of the structure of terminal 400-1 provided in the embodiments of this application;
[0030] Figure 3A This is a first flowchart illustrating the document processing method provided in this application embodiment;
[0031] Figure 3B This is a schematic diagram of the second process of the document processing method provided in the embodiments of this application;
[0032] Figure 3C This is a schematic diagram of the third process of the document processing method provided in the embodiments of this application;
[0033] Figure 3D This is a schematic diagram of the fourth process of the document processing method provided in the embodiments of this application;
[0034] Figure 3E This is a schematic diagram of the fifth process of the document processing method provided in the embodiments of this application;
[0035] Figure 3F This is a schematic diagram of the sixth process of the document processing method provided in the embodiments of this application;
[0036] Figure 3G This is a schematic diagram of the seventh process of the document processing method provided in the embodiments of this application;
[0037] Figure 3H This is a schematic diagram of the eighth process of the document processing method provided in the embodiments of this application;
[0038] Figure 3I This is a ninth flowchart illustrating the document processing method provided in this application embodiment;
[0039] Figure 3J This is a schematic diagram of the tenth process of the document processing method provided in the embodiments of this application;
[0040] Figure 3K This is a schematic diagram of the eleventh step of the document processing method provided in the embodiments of this application;
[0041] Figure 3L This is a schematic diagram of the twelfth step of the document processing method provided in the embodiments of this application;
[0042] Figure 3M This is a schematic diagram of the thirteenth step of the document processing method provided in the embodiments of this application;
[0043] Figure 4 This is a schematic diagram of the syntax tree structure of the first document provided in the embodiments of this application;
[0044] Figure 5 This is an application illustration of the document parsing and rendering provided in the embodiments of this application;
[0045] Figure 6 This is a schematic diagram of inline syntax and paragraph syntax provided in the embodiments of this application;
[0046] Figure 7 This is a schematic diagram of the nesting depth provided in the embodiments of this application;
[0047] Figure 8 This is a schematic diagram illustrating a symbol density greater than a density threshold provided in an embodiment of this application;
[0048] Figure 9 This is a schematic diagram illustrating the syntax conflict between code blocks and attachment links provided in the embodiments of this application;
[0049] Figure 10 This is a schematic diagram of a partially updated document object model provided in an embodiment of this application;
[0050] Figure 11 This is a schematic diagram illustrating the differences between the text processing method provided in this application and related technologies;
[0051] Figure 12 This is a schematic diagram illustrating the construction of the three conversion functions provided in the embodiments of this application;
[0052] Figure 13 This is a schematic diagram illustrating the timeliness links for different users provided in the embodiments of this application;
[0053] Figure 14 This is a flowchart illustrating the mapping timeliness parameters provided in the embodiments of this application.
[0054] It should be noted that the terms "first" and "second" mentioned above are only used to distinguish between different options and do not represent the degree of superiority or inferiority of the options or their priority in the implementation process. Detailed Implementation
[0055] To make the objectives, technical solutions, and advantages of this application clearer, the application will be further described in detail below with reference to the accompanying drawings. The described embodiments should not be regarded as limitations on this application. All other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.
[0056] In the following description, references are made to “some embodiments,” which describe a subset of all possible embodiments. However, it is understood that “some embodiments” may be the same subset or different subsets of all possible embodiments and may be combined with each other without conflict.
[0057] In the following description, the terms "first / second / third" are used merely to distinguish similar objects and do not represent a specific ordering of objects. It is understood that "first / second / third" may be interchanged in a specific order or sequence where permitted, so that the embodiments of this application described herein can be implemented in an order other than that illustrated or described herein.
[0058] In this application embodiment, the terms "module" or "unit" refer to a computer program or part of a computer program that has a predetermined function and works with other related parts to achieve a predetermined goal, and can be implemented wholly or partially using software, hardware (such as processing circuitry or memory), or a combination thereof. Similarly, a processor (or multiple processors or memory) can be used to implement one or more modules or units. Furthermore, each module or unit can be part of an overall module or unit that includes the functionality of that module or unit.
[0059] Unless otherwise specified, "at least one" as used below refers to one or more cases, and "multiple" can refer to two or more cases.
[0060] Unless otherwise defined, all technical and scientific terms used in the embodiments of this application have the same meaning as commonly understood by one of ordinary skill in the art. The terminology used in the embodiments of this application is for the purpose of describing the embodiments of this application only and is not intended to limit this application.
[0061] In the implementation of this application, the collection and processing of relevant data should strictly comply with the requirements of relevant laws and regulations, obtain the informed consent or separate consent of the personal information subject, and carry out subsequent data use and processing within the scope of laws and regulations and the authorization of the personal information subject.
[0062] Before providing a further detailed description of the embodiments of this application, the nouns and terms involved in the embodiments of this application will be explained, and the nouns and terms involved in the embodiments of this application shall be interpreted as follows.
[0063] 1) Responding to: used to indicate the conditions or states on which the operation is performed depends. When the conditions or states on which it depends are met, one or more operations can be performed in real time or with a set delay. Unless otherwise specified, there is no restriction on the order in which the multiple operations are performed.
[0064] 2) Human-computer interaction interface, which is an interface used to provide human-computer interaction functions / display documents.
[0065] For example, graphical user interfaces (GUIs) include augmented reality (AR) interfaces, virtual reality (VR) interfaces, voice user interfaces (VUIs), interactive projection interfaces (using projection technology to display information on a flat surface), eye-tracking interfaces (interfaces controlled by detecting the user's gaze), holographic interfaces (three-dimensional holograms formed by projecting images using holographic projection technology, allowing users to see stereoscopic images without wearing special glasses), multimodal interfaces (interfaces that combine multiple interaction methods, such as tactile, visual, and auditory interaction), and brain-machine interfaces (BMIs).
[0066] 3) Electronic Document: A document is a document that relies on a computer system for access and editing, and has a certain editable format. Examples include text documents represented by Word or TXT word processor applications, spreadsheet documents represented by Excel, presentation documents represented by PowerPoint presentations, and portable document formats (PDF).
[0067] 4) Markup languages are computer languages that use tags or symbols to structurally describe document content. Their core purpose is to define the semantics, format, and relationships of data. Types of markup languages include any of the following: Lightweight Markup Language (Markdown), Hypertext Markup Language (HTML), Extensible Markup Language (XML), LaTeX, Standard Generalized Markup Language (SGML), XML-based Markup Language (DocBook), and ReStructured Text (RST). The first type of markup language is used to describe the first document, and the second type is used to describe the second document.
[0068] 5) Feature parameters are quantitative indicators extracted from documents to describe the complexity of documents in a specific dimension. Feature parameters include at least one of the following: the depth of the syntax tree corresponding to the first document, the ratio of the number of occurrences of preset symbols to the total number of characters in the first document, the number of syntax types included in the first document, and the relationship between syntax types. Among them, the depth of the syntax tree represents the structural complexity of the first document, the ratio represents the content complexity of the first document, and the number of syntax types and the relationship represent the grammatical complexity of the first document.
[0069] 6) Parsing methods are used to analyze and understand document content, thereby converting the document from one markup language to another. Parsing methods include regular expression parsing and lexical parsing. Regular expression parsing is a method that uses regular expressions to match patterns and extract information from documents, suitable for documents with relatively regular structures and simple syntax. Lexical parsing is a method that performs detailed analysis of the lexical structure of a document, suitable for handling documents with more complex syntax and those containing anomalies or irregularities.
[0070] 7) The Document Object Model (DOM) is a platform- and language-independent programming interface used to represent documents as a tree-like object structure, allowing programs to dynamically access and modify the document's content, structure, and style. Its core is to abstractly describe the various components of a document through nodes and establish hierarchical relationships, thereby making the document machine-readable and operable.
[0071] 8) The minimum edit sequence refers to the sequence of minimal operation steps required to convert from the first tag to the second tag when comparing tags at each level of the virtual document object model before and after document content updates. Operation steps include inserting, deleting, or modifying tags.
[0072] 9) An operation object is the smallest unit of operation that makes atomic changes to a document. It is a specific unit of operation transformed from an update operation (such as insertion, deletion, or modification) based on its operation data (including the target content and the operation's position in the document). An operation object includes specific information corresponding to the update operation, such as the update content, the target content, and the operation's position in the document. By combining this operation data into operation objects, the specific update operation on the document can be described and executed more clearly. For example, Insert, Delete, and Modify are three different types of operation objects, each corresponding to a different document update operation.
[0073] 10) Timeliness parameters are parameters used to describe the time validity or related time characteristics of the content linked by the first link. Timeliness parameters affect the display or validity of the content linked to. For example, timeliness parameters can indicate the valid time range of the linked content, the publication time, the update time, and other time-related information.
[0074] Related technologies often use only one fixed parsing method to convert the markup language used in the document, resulting in low parsing speed when the document structure or content is complex.
[0075] Based on the above analysis, the applicant found that the document processing methods of related technologies cannot select the appropriate parsing method according to different document content. In order to address the above problems, this application provides a document processing method that can improve the document parsing efficiency.
[0076] The following describes exemplary applications of the electronic devices provided in the embodiments of this application. These electronic devices can be implemented as various types of terminals such as laptops, tablets, desktop computers, set-top boxes, smartphones, smart speakers, smartwatches, smart TVs, and in-vehicle terminals, or as servers. The following will describe exemplary applications when the electronic device is implemented as a terminal.
[0077] See Figure 1 , Figure 1 This is a schematic diagram of the architecture of the document processing system 100 provided in the embodiments of this application. In order to support a document processing application, the terminal (terminal 400-1 and terminal 400-2 are shown as examples) connects to the server 200 through the network 300. The network 300 can be a wide area network or a local area network, or a combination of the two.
[0078] Terminal 400-1 is used to select a matching target parsing method based on at least one feature parameter of the first document in the first type of markup language, parse the first document to obtain a second document in the second type of markup language, display it on the human-computer interaction interface 410-1, and synchronize it to terminal 400-2 through network 300 and server 200 so that it can be displayed on the human-computer interaction interface 410-2 of terminal 400-2.
[0079] In some embodiments, terminal 400-1 is used to send a first document based on a first type of markup language to a server. The server parses the first document into a second document based on a second type of markup language, converts the elements in the second document into pixels, and sends the pixels to terminal 400-1 so that terminal 400-1 renders the second document in the document interface and displays it on human-computer interaction interface 410-1.
[0080] Taking an online document scenario as an example, terminals 400-1 and 400-2 each parse the first document based on the first type of markup language into a second document based on the second type of markup language. In response, terminal 400-1 (the first terminal) updates the second document into a third document and synchronizes the third document to terminal 400-2 through network 300 and server 200, so as to display it on the human-computer interaction interface 410-2 of terminal 400-2.
[0081] In some embodiments, server 200 may be a standalone physical server, a server cluster or distributed system composed of multiple physical servers, or a cloud server providing basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communication, middleware services, domain name services, security services, content delivery networks (CDNs), and big data and artificial intelligence platforms. Terminals and servers can be connected directly or indirectly via wired or wireless communication, which is not limited in this embodiment.
[0082] See Figure 2 , Figure 2 This is a schematic diagram of the structure of terminal 400-1 provided in an embodiment of this application. Figure 2 The terminal 400-1 shown includes at least one processor 410, a memory 450, at least one network interface 420, and a user interface 430. The various components in the terminal 400 are coupled together via a bus system 440. It is understood that the bus system 440 is used to implement communication between these components. In addition to a data bus, the bus system 440 also includes a power bus, a control bus, and a status signal bus. However, for clarity, ... Figure 2 The general labeled all buses as Bus System 440.
[0083] The processor 410 can be an integrated circuit chip with signal processing capabilities, such as a general-purpose processor, a digital signal processor (DSP), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. The general-purpose processor can be a microprocessor or any conventional processor, etc.
[0084] User interface 430 includes one or more output devices 431 that enable the presentation of media content, including one or more speakers and / or one or more visual displays. User interface 430 also includes one or more input devices 432, including user interface components that facilitate user input, such as a keyboard, mouse, microphone, touch screen display, camera, other input buttons and controls.
[0085] The memory 450 may be removable, non-removable, or a combination thereof. Exemplary hardware devices include solid-state storage, hard disk drives, optical disk drives, etc. The memory 450 may optionally include one or more storage devices physically located away from the processor 410.
[0086] The memory 450 may include volatile memory or non-volatile memory, or both. The non-volatile memory may be read-only memory (ROM), and the volatile memory may be random access memory (RAM). The memory 450 described in this application embodiment is intended to include any suitable type of memory.
[0087] In some embodiments, memory 450 is capable of storing data to support various operations, examples of which include programs, modules, and data structures or subsets or supersets thereof, as illustrated below.
[0088] Operating system 451 includes system programs for handling various basic system services and performing hardware-related tasks, such as the framework layer, core library layer, driver layer, etc., for implementing various basic business functions and handling hardware-based tasks;
[0089] The network communication module 452 is used to reach other electronic devices via one or more (wired or wireless) network interfaces 420, exemplary network interfaces 420 including: Bluetooth, WiFi, and Universal Serial Bus (USB), etc.
[0090] Presentation module 453 is configured to enable the presentation of information (e.g., a user interface for operating peripheral devices and displaying content and information) via one or more output devices 431 (e.g., a display screen, a speaker, etc.) associated with user interface 430;
[0091] The input processing module 454 is used to detect and translate one or more user inputs or interactions from one or more input devices 432.
[0092] In some embodiments, the apparatus provided in this application can be implemented in software. Figure 2 A document processing apparatus 455 stored in memory 450 is shown. This apparatus can be software in the form of programs and plug-ins, and includes the following software modules: a document acquisition module 4551, a parameter acquisition module 4552, a method determination module 4553, a document parsing module 4554, and an element conversion module 4555. These modules are logically connected and can therefore be arbitrarily combined or further divided according to their implemented functions. The functions of each module will be described below.
[0093] In some embodiments, the terminal or server can implement the document processing method provided in this application by running various computer-executable instructions or computer programs. For example, computer-executable instructions can be microprogram-level commands, machine instructions, or software instructions. Computer programs can be native programs or software modules in an operating system; they can be native applications (APPs), i.e., programs that need to be installed in the operating system to run, such as document APPs or instant messaging APPs; or they can be applets that can be embedded in any APP, i.e., programs that only need to be downloaded to a browser environment to run. In summary, the aforementioned computer-executable instructions can be any form of instruction, and the aforementioned computer programs can be any form of application, module, or plugin.
[0094] The document processing method provided in this application will be described in conjunction with exemplary applications and implementations of the terminals provided in the embodiments of this application.
[0095] See Figure 3A , Figure 3A This is a first flowchart illustrating the document processing method provided in this application embodiment, with the terminal as the main component, and combining... Figure 3A The steps shown are explained.
[0096] In step 101, a first document based on a first type of markup language is obtained.
[0097] In some embodiments, the first document can be a local document or an online document. The first type of markup language of the first document can be determined by looking at the file extension (such as .html, .xml, .md, etc.) or specific tags in the document content.
[0098] For example, the first type of markup language includes any of the following: HTML, a standard markup language for creating web pages that displays the structure and layout of web page content; XML, a markup language for marking up electronic documents to give them structure, which can be understood by different applications; Markdown, a lightweight markup language commonly used for writing documents in plain text format that is easy to read and write; LaTeX, a TeX-based typesetting system widely used for typesetting scientific literature and books; SGML, a language for defining document structure, of which XML is a subset; DocBook, an XML-based markup language used for writing technical documents and books; and RST, a lightweight markup language used for writing documents in plain text format that is easy to read and write. The file extension .html corresponds to HTML markup language, the file extension .xml corresponds to XML markup language, and the file extension .md corresponds to Markdown markup language.
[0099] Here, the following explanation uses Markdown as an example of the first type of markup language, and will not be repeated hereafter.
[0100] In step 102, at least one feature parameter of the first document is obtained, wherein a feature parameter characterizes the complexity of the first document in one feature dimension.
[0101] In some embodiments, see Figure 3B , Figure 3B This is a schematic diagram of the second process of the document processing method provided in the embodiments of this application. Figure 3A Step 102, "obtaining at least one feature parameter of the first document," can be achieved through... Figure 3B Steps 1021A to 1023A are implemented, and the details are explained below.
[0102] In step 1021A, a syntax tree for the first document is generated, wherein the syntax tree includes multiple nodes, including a root node and leaf nodes directly or indirectly connected to the root node. The root node represents the document identifier of the first document, and the leaf nodes represent the smallest semantic unit of the first document.
[0103] In some embodiments, the root node is the top node of the syntax tree, the starting point of the syntax tree, and each non-empty syntax tree has one and only one root node. A leaf node is a node in the syntax tree that has no child nodes. The syntax tree also includes internal nodes, which are nodes in the syntax tree other than the root node and leaf nodes. An internal node includes one parent node and at least one child node.
[0104] For example, the smallest semantic unit can be any of the following: letters, numbers, punctuation marks, etc. See also Figure 4 , Figure 4 This is a schematic diagram of the syntax tree structure of the first document provided in the embodiments of this application. Figure 4 In the first document, if the document identifier of the first document is document A, and document A corresponds to node 401, then node 401 is taken as the root node, the internal nodes include node 402, node 403 and node 404, and the leaf nodes include node 405, node 406, node 407, node 408 and node 409.
[0105] In some embodiments, see Figure 3C , Figure 3C This is a schematic diagram of the third process of the document processing method provided in the embodiments of this application. Figure 3B Step 1021A, "Generate the syntax tree of the first document," can be achieved through... Figure 3C Steps 10211A to 10214A are implemented, and the details are explained below.
[0106] In step 10211A, multiple syntax identifiers in the first document are identified.
[0107] In some embodiments, a Markdown parser is used to read the content of the first document line by line, and all syntax identifiers are identified according to the Markdown syntax rules. Specifically, when a preset character is identified, the syntax identifier corresponding to the preset character is searched.
[0108] For example, syntax identifiers include at least one of the following: headings, lists, paragraphs, code blocks, links, images, etc. For instance, lines starting with "#" are identified as headings, lines starting with "-" or "*" as list items, lines indented with backticks or four spaces as code blocks, and lines enclosed in square brackets or parentheses as links. For example, a Markdown-based first document could be:
[0109] #Title1
[0110] -List item 1
[0111] -List item 2
[0112] Python
[0113] Print("Hello, World!")
[0114] The first document contains several syntax markers, including headings (#heading1), list items (-list item1 and -list item2), and code blocks (```python Print("Hello, World!")).
[0115] In step 10212A, nodes corresponding to each syntax identifier are created.
[0116] In some embodiments, a corresponding node is created for each identified grammatical identifier, and each node represents a different part of the first document.
[0117] For example, the different parts of the first document represented by a node include: headings, lists, list items, paragraphs, code blocks, links, images, etc.
[0118] In step 10213A, based on the nesting rules of the first document, the hierarchical relationship of the nodes corresponding to each syntax identifier is established.
[0119] In some embodiments, a stack is created to detect the current node hierarchy, with the top element always being the current parent node; the root node, typically a Document node, is initialized and pushed onto the stack; the document content is scanned line by line or character by character to identify syntax markers, and for each identified syntax marker, its type and attributes are determined; different nodes are created for different syntax markers and pushed onto the stack; when a syntax marker is encountered, its relationship with the current top node is checked; if the new syntax marker should be a child node of the current top node, a new node is created and pushed onto the stack; if the new syntax marker indicates the end of the current node (e.g., a higher-level heading ends the current chapter), the node needs to be popped from the stack until a suitable parent node is found, maintaining the correct state of the stack and ensuring that the nesting relationship of nodes conforms to the document's syntax rules; when the document content has been parsed, only the root node remains in the stack.
[0120] For example, for the syntax identifier of heading type, identify the heading level, create a Heading node whose level attribute corresponds to the heading level, and if the current top node of the stack is not a Document or a list item, make the Heading node a child node of the current top node of the stack and push the Heading node onto the stack; for the syntax identifier of list item type, identify the list type (ordered or unordered), create a List node (if it has not yet been created) and a ListItem node. Make the ListItem node a child node of the List node and push the ListItem node onto the stack; for the syntax identifier of paragraph type, create a Paragraph node, make it a child node of the current top node of the stack, and push the Paragraph node onto the stack; for the syntax identifier of code block type, create a CodeBlock node, make it a child node of the current top node of the stack, and push the CodeBlock node onto the stack; for the syntax identifier of link and image type, identify the attributes of the link or image, create the corresponding node, and make it a child node of the current text node. See also Figure 4 For the grammatical identifier "heading", there is one layer of nesting, that is, the first-level heading includes the heading text. The first-level heading corresponds to node 402, and the heading text corresponds to node 405. The hierarchical relationship between node 402 and node 405 is: node 402 is the parent node of node 405, that is, node 405 is the child node of node 402.
[0121] In step 10214A, multiple nodes are combined into a syntax tree based on the hierarchical relationship and the attributes of each node.
[0122] In some embodiments, for each node, the parser assigns the attribute of the syntax identifier corresponding to the node to the node, and combines the assigned nodes according to the hierarchical relationship to obtain a syntax tree.
[0123] For example, the attributes of a heading node include the heading level, such as Heading 1, Heading 2, etc., while the attributes of a link node include the link address and the text in the link.
[0124] This application's embodiments convert the first document into a syntax tree, representing the first document in a structured manner. The tree structure clearly reflects the document's semantics and hierarchical relationships. Based on the syntax tree, operations such as inserting, deleting, and modifying document content can be easily performed.
[0125] Automated processing: The syntax tree enables automated processing of Markdown documents, such as automatic summarization, content extraction, and format conversion.
[0126] Cross-platform compatibility: A syntax tree is a universal data structure that can be understood and used by different platforms and applications.
[0127] Continue to participate Figure 3B In step 1022A, the distance between the root node of the syntax tree and the leaf node of the syntax tree is determined.
[0128] In some embodiments, the line connecting any two connected nodes in the syntax tree is an edge, and the distance between the root node and the leaf node can be the number of edges in the complete path from the root node to the leaf node, or the total number of nodes in the complete path from the root node to the leaf node.
[0129] Following the example of step 1021A above, see [link to example]. Figure 4 From the root node (node 401) to the leaf node (e.g., node 408), taking the distance between the root node and the leaf node as the number of edges in the complete path from the root node to the leaf node as an example, the complete path between node 401 and node 408 includes the edge between node 401 and node 404 and the edge between node 404 and node 408, with a total of 2 edges, which means the distance between the root node and the leaf node is 2. Taking the distance between the root node and the leaf node as the total number of nodes in the complete path from the root node to the leaf node as an example, the complete path between node 401 and node 408 includes node 401, node 404, and node 408, with a total of 3 nodes, which means the distance between the root node and the leaf node is 3.
[0130] In step 1023A, the maximum distance is taken as the depth of the syntax tree, and the depth is taken as the feature parameter.
[0131] Following the example of step 1022A above, taking the distance between the root node and the leaf node as the number of edges in the complete path from the root node to the leaf node as an example, the distance between node 401 and node 405 is 2, the distance between node 401 and node 406 is 2, the distance between node 401 and node 407 is 2, the distance between node 401 and node 408 is 2, the distance between node 401 and node 409 is 2, and the maximum distance is 2. Therefore, the depth of the syntax tree is 2, and the depth is used as a feature parameter.
[0132] This application's embodiments quantify the structural complexity of a document by calculating the depth of the syntax tree, facilitating comparisons of the structural complexity of different documents. Automating the determination of the syntax tree depth eliminates the need for manual intervention, improving analysis efficiency. Using the syntax tree depth as a feature parameter is applicable to documents using various types of markup languages, demonstrating broad applicability.
[0133] In some embodiments, see Figure 3D , Figure 3D This is a schematic diagram of the fourth process of the document processing method provided in the embodiments of this application. Figure 3A Step 102, "obtaining at least one feature parameter of the first document," can be achieved through... Figure 3D Steps 1021B to 1022B are implemented, and the details are explained below.
[0134] In step 1021B, the total number of characters in the first document and the number of times the preset symbols appear are counted.
[0135] In some embodiments, each character of the first document is traversed, and a first counter is used to record the total number of characters. A preset symbol set is defined, and each character of the document is traversed. It is checked whether the character belongs to the preset symbol set, and a second counter is used to record the occurrence count of the preset symbols. If the character belongs to the preset symbol set, the counter is incremented.
[0136] For example, characters include, but are not limited to: letters, numbers, punctuation marks, and whitespace characters (such as spaces, tabs, newlines, etc.). Preset symbols include, but are not limited to: #, *, _, [, ], (, ), and `. For the document "#(Hello, World!)", the number of letters is 10, the number of punctuation marks (#, (, ), , !) is 5, the total number of characters is 15, and the number of times the preset symbols appear is 3.
[0137] In step 1022B, the ratio of the number of occurrences to the total number of characters is determined, and the ratio is used as a feature parameter.
[0138] Following the example of step 1021B above, the ratio of the number of occurrences of the preset symbol (3) to the total number of characters (15) is 3 / 15 = 1 / 5, and this ratio is used as a feature parameter.
[0139] This application's embodiments characterize the symbol density of preset symbols by statistically analyzing the total number of characters and the frequency of occurrence of preset symbols. This quantifies the complexity of the first document in terms of content dimension, facilitating quantitative analysis. The ratio provides a standardized metric, making different documents comparable in terms of symbol usage density. The entire process can be automated without manual intervention, improving processing efficiency.
[0140] In some embodiments, see Figure 3E , Figure 3E This is a schematic diagram of the fifth process of the document processing method provided in the embodiments of this application. Figure 3A Step 102, "obtaining at least one feature parameter of the first document," can be achieved through... Figure 3E Steps 1021C to 1023C are implemented, and the details are explained below.
[0141] In step 1021C, at least one syntax type in the first document is identified, wherein the at least one syntax type is the type of syntax used when describing the first element in the first document based on the first type markup language.
[0142] In some embodiments, a Markdown parser is used to read the content of the first document line by line and identify all syntax types according to the markup language rules of the first document. Specifically, when the start mark corresponding to different syntax types is read, the Markdown parser determines the corresponding syntax type based on the start mark.
[0143] For example, syntax types include, but are not limited to, code blocks, attachment links, lists, headings, etc. For code blocks in the first document based on Markdown, when a start tag with three consecutive backticks (ˋˋˋ) or four spaces indentation is detected, the content after the start tag is recognized as a code block, and the Markdown parser will recognize this as a code block syntax type.
[0144] In step 1022C, if there are multiple syntax types, the association between the multiple syntax types is determined, wherein the association indicates whether there is a syntax conflict or not.
[0145] In some embodiments, the relationships between multiple syntax types can be determined in any of the following ways: analyzing the nesting and combination of the identified syntax types, or detecting the syntax types preceding or following the current syntax type, and determining whether there are syntax conflicts between different syntax types based on a preset relationship table; comparing the rules of each syntax type to see if there are any contradictions or incompatibilities between the rules of any two syntax types; and judging the rationality and compatibility of different syntax types in the structure based on the structural requirements of the entire document.
[0146] For example, in a pre-defined association table, text within a code block is typically not parsed into other syntax types, creating a syntax conflict between code blocks and attachment links. Similarly, headings in a list should be treated as plain text, not displayed as separate headings, creating a syntax conflict between lists and headings. There is also a conflict between heading syntax and plain text syntax; for example, using plain text in a heading position or using too many heading-like formats within a plain text paragraph can lead to a cluttered document structure. A conflict exists between list syntax and paragraph syntax; for instance, using paragraph formatting within a list item or inserting list formatting abruptly within a paragraph can impair readability. Finally, there is a conflict between code block syntax and other emphasis formats (such as bold, italics, etc.); using emphasis formats within a code block can lead to misunderstandings of the code's semantics.
[0147] In step 1023C, the number and association of at least one syntax type are used as feature parameters.
[0148] Following the example of step 1022C above, if the first document includes two syntax types, such as headings and lists, that is, the number of at least one syntax type is 2, the relationship between the two syntax types indicates that there is a syntax conflict, and the number of syntax types and the relationship are used as feature parameters.
[0149] This application's embodiments improve document parsing accuracy and avoid display anomalies by identifying syntax types and determining relationships. Using syntax types and their relationships as feature parameters can be applied to machine learning tasks, improving model prediction accuracy. Ensuring the correct nesting and combination of different syntax types within a document enhances document consistency and readability.
[0150] Continue to participate Figure 3A In step 103, a target parsing method that matches at least one feature parameter is determined from a plurality of preset document parsing methods.
[0151] In some embodiments, the preset document parsing methods include regular expression parsing and lexical parsing. Different feature parameters are matched with different parsing methods or the same parsing method.
[0152] For example, regular expression parsing uses regular expressions to match and extract specific patterns in a document. Lexical parsing, on the other hand, breaks down the document content into a series of lexical tokens through lexical analysis. A lexical token is the smallest unit in a document that has independent meaning, such as heading symbols, list symbols, and code block symbols.
[0153] In some embodiments, step 103, "determining the target parsing method that matches at least one feature parameter from a plurality of preset document parsing methods", can be implemented by performing the following processing: if at least one feature parameter indicates that the first document has an anomaly, then the lexical parsing method is used as the target parsing method; if at least one feature parameter indicates that the first document does not have an anomaly, then the regular expression parsing method is used as the target parsing method.
[0154] For example, the abnormal conditions include at least one of the following: the depth of the syntax tree built based on the first document is greater than a preset depth value; the ratio of the number of occurrences of preset symbols to the total number of characters in the first document is greater than a ratio threshold; the number of syntax types included in the first document is greater than a preset number value; and the association between multiple syntax types indicates that there is a conflict relationship between multiple syntax types.
[0155] For example, if the depth of the syntax tree built based on the first document is 2, the preset depth value is 1, and the depth of the syntax tree is greater than the preset depth value, then lexical analysis is used as the target parsing method; or, if the ratio of the number of occurrences of a preset symbol to the total number of characters in the first document is 1 / 5, the ratio threshold is 1 / 10, and the ratio of the number of occurrences to the total number of characters is greater than the ratio threshold, then lexical analysis is used as the target parsing method; or, if the number of syntax types included in the first document is 2, the preset number value is 1, the number of syntax types included in the first document is greater than the preset number value, the syntax types included in the first document are headings and lists, and the relationship between the two syntax types indicates that there is a conflict relationship between multiple syntax types, then lexical analysis is used as the target parsing method. If the depth of the syntax tree built based on the first document is 1, the preset depth value is 1, and the depth of the syntax tree is equal to the preset depth value, then the regular expression parsing method is used as the target parsing method; or, if the ratio of the occurrence count of the preset symbol to the total number of characters in the first document is 1 / 20, the ratio threshold is 1 / 10, and the ratio of the occurrence count to the total number of characters is less than the ratio threshold, then the regular expression parsing method is used as the target parsing method; or, if the number of syntax types included in the first document is 1, the preset number value is 1, and the number of syntax types included in the first document is equal to the preset number value, then the lexical parsing method is used as the target parsing method; or, if the number of syntax types included in the first document is 2, the preset number value is 1, and the number of syntax types included in the first document is greater than the preset number value, but the syntax types included in the first document are headings and paragraphs, and the relationship between the two syntax types indicates that there is no conflict between the multiple syntax types, then the regular expression parsing method is used as the target parsing method.
[0156] In this application's embodiments, when documents contain anomalies, such as excessive syntax tree depth, excessive use of preset symbols, or conflicts between syntax types, lexical parsing can more accurately handle these complex situations and avoid parsing errors. For documents without anomalies, regular expression parsing can quickly and accurately parse the document content, improving parsing efficiency. Intelligent selection of the parsing method based on the document's feature parameters can adapt to different document types, improving parsing flexibility. By identifying document anomalies and selecting appropriate parsing methods, parsing errors can be reduced, and the reliability of parsing results improved.
[0157] For documents with anomalies, lexical analysis can handle complex grammatical structures more accurately, avoiding display anomalies or functional failures caused by parsing errors.
[0158] Continue to participate Figure 3A In step 104, the first document is parsed based on the target parsing method to obtain the syntax structure of the first document.
[0159] In some embodiments, the syntactic structure of the first document includes syntactic elements conforming to the syntactic rules of a first type of markup language. When the target parsing method is regular expression parsing, regular expressions are defined to cover various syntactic types in the Markdown document, such as headings, lists, code blocks, links, etc.; regular expressions are used to scan the document to match corresponding syntactic structures; the matched text content is extracted, and its syntactic type and position are recorded; a data structure representing the syntactic structure of the first document is constructed, such as a tree structure or a list. When the target parsing method is lexical parsing, lexical rules are defined to identify lexical units in the Markdown document, such as symbols, text, links, etc.; the content of the first document is scanned using lexical rules to generate a lexical unit stream; the lexical unit stream is passed to the parser, which constructs the syntactic structure according to the Markdown syntactic rules; the parser identifies the syntactic structure, such as headings, lists, code blocks, etc., based on the type and order of the lexical units, and constructs the corresponding syntax tree.
[0160] For example, regular expression parsing or lexical parsing will generate a data structure representing the syntactic structure of the first document. This data structure can be a tree structure, where each node represents a syntactic element, such as a heading, list item, or code block. Nodes have parent-child relationships, reflecting the nested structure of the first document. For a Markdown-based first document:
[0161] #Title1
[0162] -List item 1
[0163] -List item 2
[0164] Python
[0165] Print("Hello, World!")
[0166] When the target parsing method is regular expression parsing, define regular expressions. For example, the regular expression A corresponding to the title is: `^#(.+)$`, the regular expression B corresponding to the list item is: `^-(.+)$`, and the regular expression C corresponding to the code block is: ````````(.+)````````; scan the content of the first document and match the regular expressions corresponding to the document content. For example, the title "Heading 1" corresponds to regular expression A, the list items "List Item 1" and "List Item 2" correspond to regular expression B, and the code block "print("Hello, World!")" corresponds to regular expression C; construct the syntax structure: title node - list node - code block node. When the target parsing method is lexical parsing, lexical rules are defined to identify `#` as a title marker, `-` as a list item marker, and `` ...
[0167] The embodiments of this application utilize lexical parsing, which can more accurately handle complex document structures and conflicting syntax types. Regular expression parsing is faster for simple, conflict-free documents. Selecting an appropriate parsing method based on document complexity and the presence of anomalies improves the flexibility and applicability of the parsing process.
[0168] In step 105, the first element in the grammatical structure is converted into a second element that conforms to the grammar of the second type of markup language, and the second element is combined into a second document.
[0169] Here, the second type of markup language differs from the first type of markup language. The second type of markup language can be any of the following: HTML, Markdown, LaTeX, SGML, DocBook, and RST. Taking Markdown as an example where the first type of markup language is Markdown, the second type of markup language can be HTML. The following explanation will use HTML as an example for the second type of markup language, and will not be repeated hereafter.
[0170] In some embodiments, see Figure 3F , Figure 3F This is a schematic diagram of the sixth process of the document processing method provided in the embodiments of this application. Figure 3A Step 105 can be achieved through Figure 3F Steps 1051 to 1052 are implemented, and the details are explained below.
[0171] In step 1051, based on the element type of the first element, the first element is mapped to a second element that conforms to the syntax of the second type markup language according to the preset mapping rule corresponding to the element type.
[0172] In some embodiments, the syntax structure is traversed to obtain each first element in the syntax structure and the type of each first element is determined; mapping rules are defined to define a corresponding second element that conforms to the syntax of the second type markup language for each type of first element; according to the type of the first element, the preset mapping rules are applied to convert the first element into the corresponding second element that conforms to the syntax of the second type markup language.
[0173] Following the example from step 104 above, the mapping rule can be that the first element is the heading "#" in the syntax structure of the first document, and the corresponding second element is... <h1>Tags; the first element is a list item "-", and the corresponding second element is... The tag; the first element is the code block "```````", and the corresponding second element is... <pre>or <code>Tags. The first element can be of various types, including headings, list items, code blocks, links, paragraphs, etc. For example, converting a Markdown heading #Title to... <h1> Title< / h1> Convert the first element `#heading` to the second element. <h1> title< / h1> The first element, "This is a paragraph," is converted to the second element. This is a paragraph. `, convert the first element `-list item 1` to the second element` List item 1 `, convert the first element `-list item 2` to the second element` List item 2 The first element ```python print("Hello, World!")` ... <pre> <code class="python"> print("Hello, World!")< / code> < / pre> `.
[0174] In step 1052, the second element is combined into a second document according to the syntactic structure.
[0175] In some embodiments, the order of the converted second elements is maintained according to the order of the first elements in the syntactic structure of the first document. The converted second elements are then combined in order. All the combined HTML elements are inserted into the structure of the HTML document to form a complete HTML document.
[0176] Following the example of step 1051 above, after each first element in the syntactic structure of the first document is mapped to a second element conforming to the syntax of the second type of markup language, the second elements are combined according to the syntactic structure to form the following second document, for example:
[0177]
[0178]
[0179] This application embodiment, through preset mapping rules and an automated process, can quickly convert a first document based on a first type of markup language into a second document based on the same first type of markup language, saving time and effort compared to manual processing. The mapping rules ensure consistency when different first elements are converted into second elements, avoiding inconsistencies and errors that may arise from manual conversion. The mapping rules can be extended and adjusted as needed to support more types of first and second elements.
[0180] In some embodiments, the first document is displayed in the document interface, see [link / reference]. Figure 3G , Figure 3G This is a schematic diagram of the seventh flow of the document processing method provided in this application embodiment. After step 105, the following steps are executed: Figure 3G Steps 106 to 108 are explained in detail below.
[0181] In step 106, a real document object model is constructed based on the second element, wherein a node in the real text object model is used to store a second element, and the real document object model is a structured representation of the second document.
[0182] In some embodiments, the application programming interface (API) of the document object model (DOM) provided by the browser is used to create a corresponding node for each second element; the created nodes are added to the real DOM tree of the second document according to the order and hierarchy of the second elements.
[0183] For example, for the second element <h1> title< / h1> ", create <h1>Create a node and set its text content to "title".
[0184] In step 107, the style of the second element is determined and applied to the node corresponding to the second element.
[0185] In some embodiments, a corresponding Cascading Style Sheets (CSS) style rule is defined for each second element, including font, color, margin, padding, etc.; the style rule is applied to the corresponding real DOM node using CSS selectors or JavaScript operations.
[0186] For example, styles can be applied by setting the `style` attribute or adding a CSS class. For instance, based on the second element...< / h1> <h1> title< / h1> The font size and color of "" are for <h1>The nodes are set to have the same font size and color, based on the second element. paragraph The font size of “” is Set the same font size for all nodes.
[0187] In step 108, the position of the second element is determined, and the node after applying the style is converted into pixels based on the position. The pixels are used to draw in the document interface to cover the first document.
[0188] In some embodiments, the position of each second element in the document interface is determined, wherein the position includes the margin, padding, border, and size of the content area of the second element; CSS styles are applied to each element, wherein the styles include font size, color, background color, text alignment, etc.; the size and style of the second element are converted into pixel coordinates; the pixel coordinates are converted into a rasterized image, that is, the shape, color, and text content of each second element are converted into pixels on the screen; the rasterized images corresponding to multiple second elements are combined into a complete page image according to the coordinate position of the second elements; the complete page image is converted into a light signal and displayed in the document interface to cover the first document.
[0189] For example, the browser's rendering engine performs layout calculations to determine the position of each second element within the document interface. The element has a 10-pixel top margin, a 5-pixel inner margin, and a 1-pixel border. The second element with applied CSS styles. <h1>It can be set to a font size of 24 pixels and a red text color. It converts the size and style of the second element to pixel coordinates; for example, it converts relative units in CSS (such as em, rem, %) to absolute pixel values. If an element's width is 50% and its parent element's width is 800 pixels, then the element's width will be converted to 400 pixels. It converts pixel coordinates to a rasterized image; for example, a rectangular background color... The element will be converted into a series of pixels filled with that color, and a text element will be overlaid on its background element.
[0190] This application's embodiments, by constructing a realistic document object model, can dynamically render and update document content to adapt to different display needs. Different styles can be defined and applied to each element to achieve rich visual effects. Through precise calculation and positioning, it can be ensured that the content of the second document is accurately displayed in the interface, covering the original first document.
[0191] In some embodiments, the real document object model corresponds to a virtual document object model, which is an abstract representation of the real document object model. See [link to documentation]. Figure 3H , Figure 3H This is a schematic diagram of the eighth process of the document processing method provided in this application embodiment. After step 108, if the content of the second document is updated, the following steps are executed: Figure 3H Steps 109 to 112 are explained in detail below.
[0192] In step 109, based on the updated content in the second document, the part to be updated in the virtual document object model is determined, wherein the part to be updated includes at least one of the following: nodes in the virtual document object model, and the association relationship between multiple nodes in the virtual document object model.
[0193] Here, before step 109, a virtual document object model can be constructed. Specifically, a component tree is constructed, where each component corresponds to a part of the second document. These components can be simple elements (such as buttons or input boxes) or complex structures (such as tables or forms). Each component includes a rendering function that defines the appearance of the component in different states. In the rendering function, virtual nodes are created by calling an interface. Each virtual node is a lightweight JavaScript object that includes information such as the type, attributes, and child nodes of the second element. The virtual nodes are assembled into a virtual document object model according to the structure of the component tree.
[0194] In some embodiments, prior to step 109, the following process may be performed: for each level of the virtual document object model, determine the first signature of the tag.
[0195] For example, in the Virtual Document Object Model, the root element is a `` tag, and the child elements of the root element are also `` tags. 、 、 Tags are defined as follows. For each tag, the tag type is identified (e.g., div, span, p, etc.); all tag attributes are collected, including class name, ID, style, event handlers, etc.; all child nodes of the tag are traversed; and the tag type, attributes, and child node information are combined into a first signature, where the first signature can be a string, a hash value, or other form of identifier that uniquely represents the tag's state. For example, for the tag... <div id="main"> Content1 For each tag, calculate the hash value A of div, the hash value B of id="main" and the hash value C of Content, and use the hash value A + hash value B + hash value C as the first signature.
[0196] In some embodiments, see Figure 3I , Figure 3I This is a schematic diagram of the ninth process of the document processing method provided in the embodiments of this application. Figure 3H Step 109, "Identify the parts to be updated in the Virtual Document Object Model," can be done through... Figure 3I Steps 1091 to 1093 are implemented, and the details are explained below.
[0197] In step 1091, for each level of the virtual document object model, a second signature of the tag is determined.
[0198] In some embodiments, when updating the content of the second document, for each tag, the tag type is identified, such as div, span, p, etc.; all attributes of the tag are collected, including class name, ID, style, event handler, etc.; all child nodes of the tag are traversed; and the tag type, attributes, text content and child node information are combined into a first signature, wherein the first signature can be a string, a hash value or other form of identifier that can uniquely represent the state of the tag.
[0199] Following the example above regarding determining the first signature, the label is modified to... <div id="main"> Content2 The tag is calculated by hashing the Content's hash value D, and the hash value A + hash value D + hash value C is used as the second tag.
[0200] In step 1092, a difference operation is performed on the first signature and the second signature to obtain the minimum edit sequence between the first signature and the second signature.
[0201] In some embodiments, see Figure 3J , Figure 3J This is a schematic diagram of the tenth process of the document processing method provided in the embodiments of this application. Figure 3I Step 1092 can be achieved through Figure 3J Steps 10921 to 10922 are implemented, and the details are explained below.
[0202] In step 10921, for each first character in the first signature, a second character in the second signature that is in the same order as the first character is determined.
[0203] In some embodiments, the first signature and the second signature are aligned in character order, and the characters at each position are compared one by one. The two characters at the same position are the first character and the second character in the same order.
[0204] For example, if the first signature is "ABCDE" and the second signature is "ABFGH", then the first character "A" in the first signature and the second character "A" in the second signature are in the same order; the first character "B" in the first signature and the second character "B" in the second signature are in the same order; the first character "C" in the first signature and the second character "F" in the second signature are in the same order; the first character "D" in the first signature and the second character "G" in the second signature are in the same order; and the first character "E" in the first signature and the second character "H" in the second signature are in the same order.
[0205] In step 10922, the first and last first characters that are different from the second characters in the same order in the first signature are determined, and multiple first characters from the first first character to the last first character are combined into the minimum edit sequence.
[0206] Following the example of step 10921 above, the first character "C" in the first signature is the first first character that is in the same order as the second character "F" in the second signature but is different from it. The first character "E" in the first signature is the last first character that is in the same order as the second character "H" in the second signature but is different from it. The multiple first characters from the first first character to the last first character include the first character "C", the first character "D" and the first character "E". The first characters "C", the first character "D" and the first character "E" are combined into the minimum edit sequence.
[0207] This application's embodiments reduce the cost of updating the entire real document object model by updating only the parts of the virtual document object model that differ from each other. The minimal edit sequence ensures that update operations are minimized, thereby improving rendering efficiency. The explicit edit sequence simplifies the update logic, making the code easier for developers to understand and maintain.
[0208] See also Figure 3I In step 1093, the minimum edit sequence is taken as the part to be updated.
[0209] Following step 10922 above, the part to be updated is the first character "C" + the first character "D" + the first character "E".
[0210] See also Figure 3H In step 110, the status of each paragraph tag in the section to be updated is queried.
[0211] In some embodiments, the state change of each paragraph tag is determined by comparing the current state of the virtual document object model with the previous state. This includes checking whether the tag has been added, deleted, modified, or remains unchanged.
[0212] For example, if a new paragraph tag is added to the section to be updated in the current state of the virtual document object model, and the tag did not exist in the previous state, then the state of the tag is "added".
[0213] In step 111, based on the part to be updated and the state, the target part in the real document object model corresponding to the part to be updated is updated.
[0214] In some embodiments, the method of updating the target portion differs depending on the state. Step 111 can be implemented in the following ways:
[0215] Method 1: If the status is "new", determine the location to be updated and add the part to be updated to the location in the actual document object model.
[0216] In some embodiments, when a new paragraph tag is detected, the insertion position of the new paragraph tag in the virtual document object model is determined; the new paragraph tag is then inserted into the corresponding position in the real document object model.
[0217] For example, if the virtual document object model inserts paragraph node C between paragraph node A and paragraph node B, and paragraph node C is the part to be updated, then the paragraph label of paragraph node C will be located between paragraph node A and paragraph node B in the virtual document object model, and paragraph node C will also be inserted between paragraph node A and paragraph node B in the real document object model.
[0218] Method 2: If the status is deleted, find the target part corresponding to the part to be updated in the real document object model and delete the target part.
[0219] For example, part A is deleted from the virtual document object model, part A is set as the part to be updated, and the corresponding part A' is found in the real document object model. A' is set as the target part, and part A' is deleted from the real document object model.
[0220] Method 3: If the status is modified, replace the target part based on the part to be updated.
[0221] For example, in the virtual document object model, part A is modified to part B, part A is taken as the part to be updated, and the corresponding part A' in the real document object model is found, A' is taken as the target part, and part B is used to replace part A' in the real document object model.
[0222] In step 112, the updated second document is rendered based on the updated real document object model.
[0223] Here, the browser's rendering engine is responsible for converting the updated real document object model into pixels on the screen. The rendering process includes building the render tree, layout calculation, drawing, and compositing. The rendering process is similar to the embodiments described in steps 106 to 108 above, and will not be repeated here.
[0224] This application's embodiments generate a minimal edit sequence through differential operations, updating only a portion of the nodes in the real text object model instead of replacing them entirely, thus reducing the computational overhead of browser reflow and repaint. Pixel compositing is performed only on the changed parts, avoiding full-screen repaint and saving computational resources.
[0225] In some embodiments, see Figure 3K , Figure 3K This is a flowchart illustrating step eleven of the document processing method provided in this application embodiment. After step 105, if the second document is an online document processed collaboratively by multiple terminals, the following steps are executed: Figure 3K Steps 113 to 116 are explained in detail below.
[0226] In step 113, in response to the operation request of the first terminal for the first update operation of the second document, the operation data of the first update operation is obtained, and the first update operation is converted into multiple operation objects based on the operation data. The operation data includes the target content corresponding to the first update operation and the operation position in the second document.
[0227] In some embodiments, when the first terminal initiates an operation request for a first update operation on the second document, the content of the operation request is parsed, the operation type (insert, delete, modify) is determined according to the content, and operation data for each operation type is obtained. The operation data includes the target content corresponding to the first update operation and the operation position in the second document. The operation position includes the start position and end position of the first update operation.
[0228] For example, the operation types include insert, delete, and modify, and the operation data includes the target content corresponding to the first update operation, such as inserted text, deleted text fragments, or modified content. Assume that the first terminal performs a delete operation in the third paragraph of the second document, starting from the 10th character position and ending at the 20th character position. The operation type is delete, the starting coordinates are (3, 10), the ending coordinates are (3, 20), and the deleted text content is the portion of the paragraph from the 10th character to the 20th character.
[0229] In step 114, multiple operation objects are combined into an operation sequence.
[0230] In some embodiments, based on the acquired operation data, the first update operation is converted into a corresponding operation object (Mutation). Depending on the operation type, three operation objects are constructed: Insert, Delete, and Modify. Specifically: for an insert operation, an Insert operation object is constructed based on the starting position and the inserted text content; for a delete operation, a Delete operation object is constructed based on the starting and ending positions and the deleted text content; for a modify operation, a Modify operation object is first constructed based on the starting and ending positions and the modified text content.
[0231] Following the example of step 113 above, based on the coordinates of the start of the operation (3, 10) and the end of the operation (3, 20), as well as the text content to be deleted, construct a Delete operation object to represent the deletion operation from the 10th character to the 20th character of the 3rd paragraph of the document.
[0232] In step 115, the second document is updated based on the operation sequence to obtain the third document.
[0233] In some embodiments, multiple generated operation objects are combined into an operation sequence according to their execution order in the update operation, and the operation sequence represents the detailed steps of the entire update operation.
[0234] Following the example from step 114 above, if, in the same update operation, in addition to the deletion operation described above, the text "newly inserted content" is also inserted at the 5th character position of the 5th paragraph, then an Insert operation object is constructed to represent the insertion operation. Then, the Delete operation object and the Insert operation object are combined into an operation sequence according to their execution order in the update operation.
[0235] In some embodiments, the way the second document is updated differs depending on the first update operation. Step 115, "Update the second document based on the operation sequence to obtain the third document," can be achieved by performing the following processing under different first update operations:
[0236] Case 1: If the first update operation is an insert operation, insert the target content at the starting position of the operation position to obtain the third document.
[0237] For example, the content of the second document is: "This is a piece of text". The insertion operation request of the first terminal is to insert "new content" at the 8th character position (i.e. after the word "segment"). The starting position of the insertion operation is the 8th character. Then, "new content" is inserted at that position, and the content of the third document is: "This is a piece of new content text".
[0238] Case 2: If the first update operation is a deletion operation, take the content between the start position and the end position in the operation position as the target content, delete the target content from the second document, and obtain the third document.
[0239] For example, the content of the second document is: "This is a sample document". The deletion request of the first terminal is to delete the content from the 4th character to the 6th character (i.e., "a"). The starting position of the deletion operation is the 4th character, and the ending position is the 6th character. "A" is taken as the target content and deleted from the document, resulting in the content of the third document: "This is a sample document".
[0240] Case 3: If the first update operation is a modification operation, query the candidate content between the start and end positions, replace the candidate content with the target content, and obtain the third document.
[0241] For example, if the content of the second document is "The weather is fine today", the modification request of the first terminal is to change "weather" to "climate". The starting position of the modification operation is the 3rd character ("sky") and the ending position is the 5th character ("climate"). The candidate content is "weather", and then the candidate content is replaced with "climate" to get the content of the third document as "The climate is fine today".
[0242] This application's embodiments employ corresponding processing methods based on different first update operations (insertion, deletion, modification), offering high flexibility and meeting various document editing needs. Through clear operation definitions and processing flows, the accuracy of document updates is guaranteed, reducing the possibility of errors. It is suitable for scenarios where multiple terminals collaboratively process online documents, enabling timely synchronization of updated documents to other terminals, ensuring consistency of document content across terminals, and improving team collaboration efficiency.
[0243] See also Figure 3K In step 116, the third document is synchronized to a second terminal other than the first terminal among multiple terminals.
[0244] In some embodiments, an operation sequence is used to update the second document. According to each operation object in the operation sequence, the second document is modified accordingly to obtain the updated third document.
[0245] Following the example of step 115 above, according to the operation sequence, first perform the deletion operation to delete the content from the 10th to the 20th character of the 3rd paragraph in the second document, and then perform the insertion operation to insert "newly inserted content" at the 5th character position of the 5th paragraph in the second document, thus completing the document update and obtaining the third document.
[0246] This application's embodiments, by collecting detailed operational data, can accurately perform operations such as insertion, deletion, and modification, ensuring accurate document updates. It supports combinations of multiple operation types to meet complex document editing needs. Updated documents are promptly synchronized to multiple terminals, ensuring all users can see the latest document content in real time, improving collaborative work efficiency.
[0247] In some embodiments, the target content includes a first link, and the first link displayed on the first terminal includes a timeliness parameter, see [link to previous document]. Figure 3L , Figure 3L This is a schematic diagram of the twelfth step of the document processing method provided in the embodiments of this application. Figure 3K Step 116 can be achieved through Figure 3L Steps 1161 to 1162 are implemented, and the details are explained below.
[0248] In step 1161, if the first update operation includes a modification operation for the timeliness parameter, the validity of the modification operation is detected, wherein the validity characterizes whether the modification operation changes the content directed by the first link.
[0249] In some embodiments, when the first terminal performs an update operation on the target content including the first link, and the operation involves modifying the timeliness parameter, the modification operation is analyzed, and the resource pointed to by the link is interacted with to check whether the modified timeliness parameter causes the content (such as images, web pages, videos, etc.) directed by the first link to change.
[0250] For example, suppose the first link displayed on the first terminal is a link to an image, and the timeliness parameter included in the link controls the displayed version of the image. The first terminal changes the timeliness parameter from "20230801" to "20230802" and checks whether the images corresponding to these two parameters are the same. If the two parameters correspond to the same image, then the modification operation is considered not to have changed the content linked by the first link, i.e., the modification operation is invalid; if the two parameters correspond to different images, then the modification operation is considered to have changed the content linked by the first link, i.e., the modification operation is valid.
[0251] In step 1162, in response to the validity characterization modification operation not changing the content led to by the first link, the content of the third document, except for the updated timeliness parameter, is synchronized to the second terminal.
[0252] For example, if the modified timeliness parameter does not change the image content, then the entire third document, including the updated timeliness parameter (from "20230801" to "20230802"), will be synchronized to the second terminal.
[0253] In some embodiments, step 116, "synchronizing the third document to a second terminal other than the first terminal among multiple terminals," can also be achieved by performing the following process: in response to a validity representation modification operation changing the content directed to the first link, synchronizing the third document to the second terminal.
[0254] For example, if the modified timeliness parameter changes the image content, then all other content in the third document except for the updated timeliness parameter (from "20230801" to "20230802") will be synchronized to the second terminal.
[0255] This application embodiment detects the validity of modification operations and transmits the complete document content only when necessary, avoiding unnecessary data transmission, improving document synchronization efficiency, reducing network bandwidth consumption and server processing burden, and saving system resources. It ensures that the second terminal can obtain accurate document content; regardless of changes to other parts of the document or the content linked to, corresponding synchronization processing can be performed, guaranteeing document consistency and accuracy across multiple terminals.
[0256] In some embodiments, see Figure 3M , Figure 3M This is a schematic diagram of the thirteenth step of the document processing method provided in this application embodiment. When the above-mentioned "responding to the validity characterization modification operation changing the content led to by the first link, the third document is synchronized to the second terminal" is executed. Figure 3M Steps 201 to 202 are explained in detail below.
[0257] In step 201, the first link, which includes the updated timeliness parameter, is mapped to the second link, wherein the length of the second link is less than the length of the first link.
[0258] In some embodiments, a unique identifier generation rule is designed, for example, using a hash algorithm, taking the updated timeliness parameters and other relevant information (such as the body of the link or a specific document identifier) as input, to generate a unique hash value as the identifier; a mapping table or database is established to store the mapping relationship between the first link and the corresponding second link (i.e., the generated identifier); the timeliness parameters and other relevant information are extracted from the first link; this information is taken as input and a unique identifier is generated using the hash algorithm; the mapping table is checked to see if the mapping relationship for the first link already exists; if it exists, the corresponding second link is directly obtained; if it does not exist, the newly generated identifier is used as the second link, and its mapping relationship with the first link is stored in the mapping table.
[0259] For example, the first link is xx.com / document?param1 = value1 × tamp = 20230802. Extract the timeliness parameter 20230802 and other relevant information (xx.com / document?param1 = value1). Generate an identifier using a hash algorithm, let's say abc123. Check the mapping table to see if a mapping for this first link already exists. If not, use yy.com / abc123 as the second link, and store the mapping relationship between xx.com / document?param1 = value1 × tamp = 20230802 and yy.com / abc123 in the mapping table.
[0260] In step 202, the third document is updated based on the second link, and the updated third document is synchronized to the second terminal.
[0261] Here, after mapping the first link to the second link, the original first link in the third document is replaced with the second link, resulting in an updated third document. This updated third document is then synchronized to the second terminal, enabling it to access the latest document content and optimized links.
[0262] This application's embodiments reduce data transmission volume and improve document transmission efficiency over the network by mapping long links to short links. Short links occupy less storage space, helping to reduce storage pressure. Faster document synchronization speed and simpler link format enhance the user experience when using online documents, reducing waiting time and operational complexity.
[0263] The following will describe an exemplary application of the embodiments of this application in an online document application scenario.
[0264] The embodiments of this application are not limited to document processing in file-based apps, but are also applicable in other scenarios, such as document mini-programs in instant messaging apps or browsers that can display and process documents.
[0265] When parsing and rendering documents using lightweight markup languages (such as Markdown, also known as Type I markup languages), the relevant technologies typically only use regular expression analysis or only lexical analysis to convert Markdown documents into HTML (also known as Type II markup languages) or other formats. When dealing with complex Markdown syntax, the parsing speed is slow, which affects the user experience, the rendering effect is poor, and it is impossible to accurately present complex Markdown syntax. Furthermore, the ability to handle large documents is limited, which can easily lead to lag or crashes.
[0266] See Figure 5 , Figure 5 This is an application illustration of the document parsing and rendering provided in the embodiments of this application. By integrating Markdown parsing and rendering functions into the document APP, users can directly write Markdown text in the document APP, and through real-time parsing and rendering, provide a WYSIWYG editing experience.
[0267] See Figure 6 , Figure 6 This is a schematic diagram illustrating the inline and paragraph syntax provided in the embodiments of this application. Markdown supports two basic text writing methods: paragraph syntax and inline syntax. For simple Markdown syntax, due to the simplicity of the syntax rules, regular expression parsing can be used (i.e., regular expression parsing method); for complex Markdown syntax, due to the poor performance and difficulty in maintenance of regular expression parsing, when paragraph syntax and inline syntax are combined, such as when code blocks and attachment links are combined, or when tables and lists are combined, the performance problem of regular expression parsing will be amplified, and lexical parsing (i.e., lexical parsing method) can be used.
[0268] Complex Markdown syntax, if parsed using only regular expression matching, requires the implementation of various exclusion logics, leading to performance bottlenecks and maintenance difficulties. This application's embodiments determine the complexity level of Markdown syntax using parameters such as syntax nesting depth (i.e., the depth of the syntax tree) and symbol density (i.e., the ratio of the frequency of preset symbols to the total number of characters), i.e., feature parameters. Simple Markdown syntax uses regular expression parsing, while complex Markdown syntax uses lexical parsing to improve parsing speed. See Table 1, which shows various complexity metrics and their corresponding parsing mode selections.
[0269] Table 1. Various complexity indices and corresponding parsing mode selections
[0270]
[0271] For cases with a nesting depth of ≥2, participate Figure 7 , Figure 7 This is a schematic diagram of the nesting depth provided in the embodiments of this application. First, the Markdown syntax is converted into a syntax tree. The syntax tree is constructed using the Last In First Out (LIFO) property of a stack. For inline syntax, whenever a start marker is encountered (such as the # symbol for a heading to start a heading block, or [ for a link), the corresponding node type is pushed onto the stack. When an end marker is encountered (such as a newline in a heading line indicating the end of a heading block, or [ for the end of a link), the most recently pushed node type is popped from the stack, and the node is constructed. For paragraph syntax, when a heading start marker (e.g., #) is parsed, a temporary structure (containing only level information, such as one # indicating a level 1 heading) is created and pushed onto the stack. When a non-empty line is encountered and is not the start marker of another block-level element, a paragraph structure is constructed and pushed onto the stack. When a newline is encountered and the heading end condition is met (such as consecutive empty lines or the start of the next block-level element), the node is popped from the stack, and the node is completed based on the previously collected heading content. Secondly, the maximum nesting level (i.e., depth) of the syntax tree is calculated using a syntax tree traversal algorithm. When the maximum nesting level is greater than or equal to 2 (i.e., the preset value), the parsing mode is selected as lexical analysis. Through lexical analysis, the document is decomposed into tags (e.g., links, code blocks), and these tags are organized into a tree structure (i.e., the syntax tree). Each node represents a component of the text, such as a code block, link, or heading. The abstract syntax tree (AST) is then filtered, modified, or transformed to generate an HTML string / call the intelligent document Docs Component. Specifically, filtering includes removing specific types of nodes, such as removing all nodes. <script>标签或<style>标签,以确保生成的HTML是安全的,或者,保留特定类型的节点,例如,只保留标题、段落和列表,移除所有其他类型的节点;修改包括修改节点属性,例如,将所有链接的目标属性设置为_blank,以在新标签页中打开链接,或者修改节点内容,例如,将所有粗体文本转换为斜体文本;转换包括转换节点类型,例如,将Markdown的代码块转换为<pre><code>标签,或者,添加自定义节点,例如,添加一个自定义的组件标签,如<DocsComponent>,用于调用智能文档组件。
[0272] 针对符号密度≥0.4的情况,参见图8,图8是本申请实施例提供的符号密度大于密度阈值的示意图。如某一区域出现的Markdown特定符号(#、*、_、[、]、(、)、`等)的数量,可以按每100个字符的大小将文档内容分割成多个分析单元,针对每个分析单元,计算特定符号出现的次数(也即预设符号的出现次数),从而计算出符号密度(也即预设符号的出现次数与字符总数的比值),符号密度的计算公式参见下述公式(1):
[0273] 符号密度=Markdown语法的符号数 / 段落总字符数*100% (1)
[0274] 以换行符为边界划分各个区域,通过公式计算每个区域的Markdown符号密度,当密度大于0.4,则表明该范围文本中使用了大量的Markdown语法,此时解析模式选择词法分析。
[0275] 针对语法类型冲突的情况,代码块和附件链接两个语法类型冲突为例,参见图9,图9是本申请实施例提供的代码块和附件链接语法冲突的示意图,当代码块语法嵌套了附件链接语法,如果都按各自的语法规则来展现,则会显示异常,可以提前检测文本中前向或后向语法关联性,当识别到两个或以上语法类型冲突时候,解析模式选择词法分析。语法冲突的情况还包括以下几种:列表和标题,列表中的标题应该是普通文本,不会放大突出显示;Markdown语法和HTML语法混用。
[0276] 在文档内容更新时,基于视窗位置进行DOM局部更新,优先处理可视区域变更,采用增量渲染技术,减少渲染延迟。参见图10,图10是本申请实施例提供的局部更新文档对象模型的示意图。首先,在文档内容发生更新时,针对每级标签,在文档更新前后均通过信息-摘要算法5(Message-Digest Algorithm 5,MD5)计算标签对应的签名,生成两个签名对象,一个用于表征旧的文档状态(也即第一签名),一个用于表征新的文档状态(也即第二签名)。其次,将这两个对象作为输入,使用差分算法计算出两个对象之间的最小编辑序列。接着,根据差分结果,确定每个段落标签的状态(例如新增、删除、更改、保持不变)。最后,根据差分结果,使用虚拟DOM技术来更新实际的DOM,仅对有变更的部分进行操作,从而减少不必要的DOM重绘。其中,通过虚拟DOM技术更新实际DOM的原理是:首先创建一个轻量级的JavaScript对象树,这个对象树是实际DOM的一个抽象表示,当数据发生变化时,虚拟DOM会重新渲染成一个新的对象树,然后,通过比较新旧两个虚拟DOM树,计算出最小的修改操作序列,最后,将这些修改操作应用到实际的DOM上,从而高效地更新页面。
[0277] 参见图11,图11是本申请实施例提供的文本处理方法与相关技术的区别示意图。相关技术的操作模型:对每一对操作都要设计转换函数,如果有m个不同的操作,那需要m*m个转换函数。Markdown为通用操作模型:基于插入、删除、更新三种基本操作设计转换函数,将用户操作抽象映射为三种基本的操作,由于Markdown是一维数据,只需要设计增删改的转换函数就可以实现协同编辑的能力。
[0278] 参见图12,图12是本申请实施例提供的三种转换函数的构建示意图。收集多个数据,例如,开始与结束的坐标,增和删的文本,然后把这些数据进行组合运算,就可以构造出插入(Insert)、(Delete)和(Modify),即增删改三个变异(Mutation)组合(也即操作对象),该步骤的本质是建设协同能力。
[0279] 可以对Mutation进行优化,在附件里面为了防止图床滥用,可以设置时效性,参见图13,图13是本申请实施例提供的不同用户的时效性链接的示意图。例如用户A的链接中携带时效性参数,相同的文本下用户B的时效性参数与A不同,但是在A和B用户对应的终端中显示相同的协同智能文档的内容,由于Markdown是一个一维的线性数据,如果每一次不同的协作人针对文档做更改时,都把内容同步到别的协作人,会导致协同跟渲染过程会产生不必要的消耗,时效性参数关联不同的用户,在每一次某个用户的链接的时效性参数发生更新时,其他用户不会同步进行更新,所以需要过滤无意义的一些Mutation。具体地:当A用户编辑文档时,只同步A用户的更改部分到B用户,而不是整个文档;同样当B用户编辑文档时,只同步B用户的更改部分到A用户,如果A用户的时效性参数更新,检查这个更改是否影响到B用户的视图;如果不影响,过滤掉这个更改,不同步给B用户,B用户仍然看到自己的时效性链接,而不会受到A用户链接更新的影响。
[0280] 参见图14,图14是本申请实施例提供的映射时效性参数的流程示意图。把链接对应的一维数据在后端存入的时候,去解析时效性参数的映射,通过网页直出和网页请求将映射后的数据传递给前端(例如上述的终端400-2),前端通过映射后的数据进行数据更新,然后在协同时过滤这种时效性Mutation,从而完成协同的优化。例如网页请求携带的一维数据可以是:
[0281] {image:drive.docs.qq.com / 42d31641c7ec40e1bf5289b919b5c72d?sign=6fc8286eb1053d0b6c15ebad53549f48&ts=1742281566&response-content-disposition=attachment%3Bfilename%3D%22image.png%22%3Bfilename%2A%3DUTF-8%27%27image.png},但后端(例如上述的服务器200)解析过滤后给一个类参数的映射:{image:drive.docs.qq.com / 42d31641c7ec40e1bf5289b919b5c72d?sign=6fc8286eb1053d0b6c15ebad53549f48},以便于前端使用。
[0282] 本申请实施例提高了Markdown解析和渲染的速度,提升用户体验。增强了语法隔离效果,能够准确呈现复杂的Markdown语法。提升了大文档的处理能力,避免卡顿和崩溃。
[0283] 下面继续说明本申请实施例提供的文档处理装置455的实施为软件模块的示例性结构,在一些实施例中,如图2所示,存储在存储器450的文档处理装置455中的软件模块可以包括:
[0284] 文档获取模块4551,用于获取基于第一类型标记语言的第一文档。
[0285] 参数获取模块4552,用于获取第一文档的至少一个特征参数,其中,一个特征参数表征第一文档在一个特征维度的复杂度。
[0286] 方式确定模块4553,用于从预设的多个文档解析方式中,确定与至少一个特征参数匹配的目标解析方式。
[0287] 文档解析模块4554,用于基于目标解析方式解析第一文档,得到第一文档的语法结构。
[0288] 元素转换模块4555,用于将语法结构中的第一元素转换为符合第二类型标记语言的语法的第二元素,将第二元素组合为第二文档。
[0289] 在一些实施例中,参数获取模块4552,还用于生成第一文档的语法树,其中,语法树包括多个节点,多个节点包括根节点以及与根节点直接或间接连接的叶子节点,根节点表征第一文档的文档标识,叶子节点表征第一文档的最小语义单元;确定语法树的根节点与语法树的叶子节点的距离;将最大的距离作为语法树的深度,将深度作为特征参数。
[0290] 在一些实施例中,参数获取模块4552,还用于识别第一文档中的多个语法标识;创建与每个语法标识分别对应的节点;基于第一文档的嵌套规则,建立每个语法标识分别对应的节点的层级关系;基于层级关系和每个节点的属性,将多个节点组合为语法树。
[0291] 在一些实施例中,参数获取模块4552,还用于统计第一文档的字符总数和预设符号的出现次数;确定出现次数与字符总数的比值,将比值作为特征参数。
[0292] 在一些实施例中,参数获取模块4552,还用于识别第一文档中的至少一个语法类型,其中,至少一个语法类型是,基于第一类型标记语言描述第一文档中的第一元素时所采用的语法的类型;若语法类型的数量有多个,则确定多个语法类型之间的关联关系,其中,关联关系表征多个语法类型之间存在语法冲突或不存在语法冲突;将至少一个语法类型的数量和关联关系,作为特征参数。
[0293] 在一些实施例中,预设的多个文档解析方式包括正则解析方式和词法解析方式,方式确定模块4553,还用于若至少一个特征参数表征第一文档存在异常,则将词法解析方式作为目标解析方式;若至少一个特征参数表征第一文档不存在异常,则将正则解析方式作为目标解析方式。
[0294] 在一些实施例中,异常的条件包括以下至少一种:基于第一文档构建的语法树的深度大于预设深度值,第一文档中预设符号的出现次数与字符总数的比值大于比值阈值,第一文档包括的语法类型的数量大于预设数量值,多个语法类型之间的关联关系表征多个语法类型之间存在冲突关系。
[0295] 在一些实施例中,元素转换模块4555,还用于基于第一元素的元素类型,按照与元素类型对应的预设映射规则,将第一元素映射为符合第二类型标记语言的语法的第二元素;将第二元素按照语法结构组合为第二文档。
[0296] 在一些实施例中,第一文档显示在文档界面中,元素转换模块4555,还用于基于第二元素构建真实文档对象模型,其中,真实文本对象模型中的一个节点用于存储一个第二元素,真实文档对象模型是第二文档的结构化表示;确定第二元素的样式,将样式应用于第二元素对应的节点;确定第二元素的位置,根据位置将应用样式后的节点转换为像素,其中,像素用于在文档界面中绘制,以覆盖第一文档。
[0297] 在一些实施例中,真实文档对象模型对应虚拟文档对象模型,虚拟文档对象模型是对真实文档对象模型的抽象表示,元素转换模块4555,还用于在对第二文档的内容进行更新的情况下,基于第二文档中更新的内容,确定虚拟文档对象模型中的待更新部分,其中,待更新部分包括以下至少一种:虚拟文档对象模型中的节点,虚拟文档对象模型中的多个节点之间的关联关系;查询待更新部分中每个段落标签的状态;基于待更新部分和状态,更新真实文档对象模型中与待更新部分对应的目标部分;基于更新后的真实文档对象模型渲染更新后的第二文档。
[0298] 在一些实施例中,元素转换模块4555,还用于针对虚拟文档对象模型的每一层级的标签,确定标签的第一签名;针对虚拟文档对象模型的每一层级的标签,确定标签的第二签名;对第一签名和第二签名进行差分运算,得到第一签名和第二签名之间的最小编辑序列;将最小编辑序列作为待更新部分。
[0299] 在一些实施例中,元素转换模块4555,还用于针对第一签名中的每个第一字符,确定第二签名中与第一字符位于同一次序的第二字符;确定第一签名中与同一次序的第二字符不相同的第一个第一字符和最后一个第一字符,将从第一个第一字符至最后一个第一字符的多个第一字符组合为最小编辑序列。
[0300] 在一些实施例中,元素转换模块4555,还用于若状态是新增状态,确定更新的位置,在真实文档对象模型的位置增加待更新部分;若状态是删除状态,在真实文档对象模型中查找待更新部分对应的目标部分,删除目标部分;若状态是修改状态,基于待更新部分替换目标部分。
[0301] 在一些实施例中,元素转换模块4555,还用于在第二文档是多个终端协同处理的在线文档的情况下,响应于第一终端针对第二文档的第一更新操作的操作请求,获取第一更新操作的操作数据,基于操作数据将第一更新操作转换为多个操作对象,其中,操作数据包括第一更新操作对应的目标内容以及在第二文档中的操作位置;将多个操作对象组合为操作序列;基于操作序列更新第二文档,得到第三文档;将第三文档同步至多个终端中除第一终端之外的第二终端。
[0302] 在一些实施例中,元素转换模块4555,还用于若第一更新操作是插入操作,在操作位置中的起始位置插入目标内容,得到第三文档;若第一更新操作是删除操作,将起始位置和操作位置中的结束位置之间的内容作为目标内容,从第二文档中删除目标内容,得到第三文档;若第一更新操作是修改操作,查询起始位置和结束位置之间的候选内容,基于目标内容替换候选内容,得到第三文档。
[0303] 在一些实施例中,目标内容包括第一链接,第一终端显示的第一链接包括时效性参数,元素转换模块4555,还用于若第一更新操作包括针对时效性参数的修改操作,检测修改操作的有效性,其中,有效性表征修改操作是否更改第一链接所导向的内容;响应于有效性表征修改操作未更改第一链接所导向的内容,将第三文档中除了更新后的时效性参数之外的内容同步给第二终端;响应于有效性表征修改操作更改了第一链接所导向的内容,将第三文档同步给第二终端。
[0304] 在一些实施例中,元素转换模块4555,还用于将包括更新后的时效性参数的第一链接映射为第二链接,其中,第二链接的长度小于第一链接的长度;基于第二链接更新第三文档,将更新后的第三文档同步给第二终端。
[0305] 本申请实施例提供了一种计算机程序产品,该计算机程序产品包括计算机程序或计算机可执行指令,该计算机程序或计算机可执行指令存储在计算机可读存储介质中。电子设备的处理器从计算机可读存储介质读取该计算机可执行指令,处理器执行该计算机可执行指令,使得该电子设备执行本申请实施例上述的文档处理方法。
[0306] 本申请实施例提供一种存储有计算机可执行指令的计算机可读存储介质,其中存储有计算机可执行指令或者计算机程序,当计算机可执行指令或者计算机程序被处理器执行时,将引起处理器执行本申请实施例提供的文档处理方法,例如,如图3A示出的文档处理方法。
[0307] 在一些实施例中,计算机可读存储介质可以是RAM、ROM、闪存、磁表面存储器、光盘、或CD-ROM等存储器;也可以是包括上述存储器之一或任意组合的各种设备。
[0308] 在一些实施例中,计算机可执行指令可以采用程序、软件、软件模块、脚本或代码的形式,按任意形式的编程语言(包括编译或解释语言,或者声明性或过程性语言)来编写,并且其可按任意形式部署,包括被部署为独立的程序或者被部署为模块、组件、子例程或者适合在计算环境中使用的其它单元。
[0309] 作为示例,计算机可执行指令可以但不一定对应于文件系统中的文件,可以可被存储在保存其它程序或数据的文件的一部分,例如,存储在超文本标记语言(Hyper TextMarkup Language,HTML)文档中的一个或多个脚本中,存储在专用于所讨论的程序的单个文件中,或者,存储在多个协同文件(例如,存储一个或多个模块、子程序或代码部分的文件)中。
[0310] 作为示例,计算机可执行指令可被部署为在一个电子设备上执行,或者在位于一个地点的多个电子设备上执行,又或者,在分布在多个地点且通过通信网络互连的多个电子设备上执行。
[0311] 综上所述,通过本申请实施例,一方面,通过至少一个特征参数确定针对第一类型标记语言的第一文档的目标解析方式,对第一文档进行解析,以得到第二类型标记语言的语法的第二文档,能够动态选择与不同的特征维度的复杂度相匹配的解析方式,提高了解析方式转换的智能化和灵活性,提高了解析的效率,缩短文档处理的时间;另一方面,基于第一文档的语法结构对第一元素进行转换,确保了转换后的第二文档在语义和结构上与第一文档的一致性,提高了文档转换的质量。
[0312] 以上所述,仅为本申请的实施例而已,并非用于限定本申请的保护范围。凡在本申请的精神和范围之内所作的任何修改、等同替换和改进等,均包含在本申请的保护范围之内。< / script> < / h1> < / h1> < / code> < / pre> < / h1>
Claims
1. A document processing method, characterized in that, The method includes: Obtain the first document based on the first type markup language; Obtain at least one feature parameter of the first document, wherein one of the feature parameters characterizes the complexity of the first document in one feature dimension; From a set of preset document parsing methods, determine the target parsing method that matches the at least one feature parameter; The first document is parsed based on the target parsing method to obtain the grammatical structure of the first document; The first element in the grammatical structure is converted into a second element that conforms to the grammar of the second type of markup language, and the second element is combined into a second document.
2. The method according to claim 1, characterized in that, The preset document parsing methods include regular expression parsing and lexical parsing. The step of determining the target parsing method that matches the at least one feature parameter from a set of preset document parsing methods includes: If at least one feature parameter indicates that the first document has an anomaly, then the lexical parsing method is used as the target parsing method; If the at least one feature parameter indicates that the first document does not contain any anomalies, then the regular expression parsing method is used as the target parsing method.
3. The method according to claim 2, characterized in that, The abnormal conditions include at least one of the following: the depth of the syntax tree constructed based on the first document is greater than a preset depth value; the ratio of the number of occurrences of preset symbols to the total number of characters in the first document is greater than a ratio threshold; the number of syntax types included in the first document is greater than the preset number value; and the association relationship between multiple syntax types indicates that there is a conflict relationship between multiple syntax types.
4. The method according to claim 1, characterized in that, The step of obtaining at least one feature parameter of the first document includes: Generate a syntax tree for the first document, wherein the syntax tree includes multiple nodes, the multiple nodes include a root node and leaf nodes directly or indirectly connected to the root node, the root node represents the document identifier of the first document, and the leaf nodes represent the smallest semantic unit of the first document. Determine the distance between the root node and the leaf node of the syntax tree; The maximum distance is taken as the depth of the syntax tree, and the depth is taken as the feature parameter.
5. The method according to claim 4, characterized in that, The generation of the syntax tree for the first document includes: Identify multiple syntax markers in the first document; Create a node corresponding to each of the aforementioned syntax identifiers; Based on the nesting rules of the first document, establish the hierarchical relationship of the nodes corresponding to each of the syntax identifiers; Based on the hierarchical relationship and the attributes of each node, multiple nodes are combined into the syntax tree.
6. The method according to claim 1, characterized in that, The step of obtaining at least one feature parameter of the first document includes: Count the total number of characters and the number of times the preset symbols appear in the first document; Determine the ratio of the occurrence frequency to the total number of characters, and use the ratio as the feature parameter.
7. The method according to claim 1, characterized in that, The step of obtaining at least one feature parameter of the first document includes: Identify at least one syntax type in the first document, wherein the at least one syntax type is the type of syntax used when describing the first element in the first document based on the first type markup language; If there are multiple syntax types, then the association between the multiple syntax types is determined, wherein the association indicates whether there is a syntax conflict or no syntax conflict among the multiple syntax types; The number of the at least one syntax type and the association relationship are used as the feature parameters.
8. The method according to any one of claims 1 to 7, characterized in that, The first document is displayed in the document interface; After combining the second element into a second document, the method further includes: A real document object model is constructed based on the second element, wherein a node in the real document object model is used to store a second element, and the real document object model is a structured representation of the second document; Determine the style of the second element, and apply the style to the node corresponding to the second element; The position of the second element is determined, and the node after applying the style is converted into pixels based on the position, wherein the pixels are used to draw in the document interface to cover the first document.
9. The method according to claim 8, characterized in that, The real document object model corresponds to the virtual document object model, and the virtual document object model is an abstract representation of the real document object model; When updating the content of the second document, after converting the node after applying the style to pixels according to the location, the method further includes: Based on the updated content in the second document, the part to be updated in the virtual document object model is determined, wherein the part to be updated includes at least one of the following: nodes in the virtual document object model, and the association relationship between multiple nodes in the virtual document object model; Query the status of each paragraph tag in the section to be updated; Based on the part to be updated and the state, update the target part in the real document object model that corresponds to the part to be updated; The updated second document is rendered based on the updated real document object model.
10. The method according to claim 9, characterized in that, Before determining the portion of the virtual document object model to be updated based on the updated content in the second document, the method further includes: For each level of the virtual document object model, determine the first signature of the tag; The step of determining the portion of the virtual document object model to be updated includes: For each level of the virtual document object model, determine the second signature of the tag; Perform a difference operation on the first signature and the second signature to obtain the minimum edit sequence between the first signature and the second signature; The minimum edit sequence is taken as the part to be updated.
11. The method according to claim 10, characterized in that, The step of performing a difference operation on the first signature and the second signature to obtain the minimum edit sequence between the first signature and the second signature includes: For each first character in the first signature, determine the second character in the second signature that is in the same order as the first character; Identify the first and last first characters in the first signature that are different from the second characters in the same order, and combine multiple first characters from the first first character to the last first character into a minimum edit sequence.
12. The method according to claim 9, characterized in that, The step of updating the target portion in the real document object model corresponding to the portion to be updated based on the portion to be updated and the state includes: If the state is a new state, determine the location of the update and add the part to be updated at the location in the real document object model; If the state is a deletion state, find the target part corresponding to the part to be updated in the real document object model and delete the target part; If the state is a modified state, replace the target part with the part to be updated.
13. The method according to any one of claims 1 to 7, characterized in that, In the case that the second document is an online document processed collaboratively by multiple terminals, after combining the second elements into a second document, the method further includes: In response to an operation request from a first terminal for a first update operation on the second document, operation data for the first update operation is obtained, and the first update operation is converted into multiple operation objects based on the operation data. The operation data includes the target content corresponding to the first update operation and the operation position in the second document. The plurality of operation objects are combined into an operation sequence; The second document is updated based on the operation sequence to obtain the third document; The third document is synchronized to a second terminal among the plurality of terminals, excluding the first terminal.
14. The method according to claim 13, characterized in that, The step of updating the second document based on the operation sequence to obtain the third document includes: If the first update operation is an insertion operation, the target content is inserted at the starting position of the operation position to obtain a third document; If the first update operation is a deletion operation, the content between the start position and the end position in the operation position is taken as the target content, and the target content is deleted from the second document to obtain the third document; If the first update operation is a modification operation, query the candidate content between the start position and the end position, replace the candidate content with the target content, and obtain the third document.
15. The method according to claim 13, characterized in that, The target content includes a first link, and the first link displayed on the first terminal includes a timeliness parameter; The step of synchronizing the third document to a second terminal among the plurality of terminals, excluding the first terminal, includes: If the first update operation includes a modification operation for the timeliness parameter, the validity of the modification operation is detected, wherein the validity characterizes whether the modification operation changes the content led to by the first link; In response to the validity characterization that the modification operation has not changed the content led by the first link, the content of the third document, except for the updated timeliness parameter, is synchronized to the second terminal. The method further includes: In response to the validity indication that the modification operation has changed the content led to by the first link, the third document is synchronized to the second terminal.
16. The method according to claim 15, characterized in that, When the method synchronizes the third document to the second terminal in response to the validity characterization indicating that the modification operation has changed the content led by the first link, the method further includes: Map the first link, including the updated timeliness parameter, to a second link, wherein the length of the second link is less than the length of the first link; The third document is updated based on the second link, and the updated third document is synchronized to the second terminal.
17. A document processing apparatus, characterized in that, The device includes: The document retrieval module is used to retrieve the first document based on the first type markup language; A parameter acquisition module is used to acquire at least one feature parameter of the first document, wherein one of the feature parameters characterizes the complexity of the first document in one feature dimension; The method determination module is used to determine, from a plurality of preset document parsing methods, a target parsing method that matches the at least one feature parameter; The document parsing module is used to parse the first document based on the target parsing method to obtain the grammatical structure of the first document; An element conversion module is used to convert the first element in the grammatical structure into a second element that conforms to the syntax of a second type of markup language, and to combine the second element into a second document.
18. An electronic device, characterized in that, The electronic device includes: Memory is used to store executable instructions or computer programs. A processor, when executing computer-executable instructions or computer programs stored in the memory, implements the document processing method according to any one of claims 1 to 16.
19. A computer-readable storage medium storing computer-executable instructions or a computer program, characterized in that, When the computer-executable instructions or computer program are executed by a processor, they implement the document processing method according to any one of claims 1 to 16.
20. A computer program product comprising computer-executable instructions or a computer program, characterized in that, When the computer-executable instructions or computer program are executed by a processor, they implement the document processing method according to any one of claims 1 to 16.