A large language model local content rewriting method and system based on document structure analysis and instruction mapping

CN122595984APending Publication Date: 2026-08-18CHINA ELECTRONICS CLOUD DIGITAL INTELLIGENCE TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202611042393.1
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-07-14
Publication Date
2026-08-18

AI Technical Summary

Technical Problem

更确切地,本发明提出了一种利用大语言模型对结构化文档进行局部内容改写的方法与系统,本方案能够精确识别结构化文档中的特定局部内容,并利用大语言模型对其进行高效、准确、上下文感知的改写,从而解决现有技术中LLM局部内容定位不准、改写范围溢出、上下文不连贯等问题

Benefits of technology

[0081] (1) Significantly improved rewriting accuracy: By performing structured parsing of the document and assigning a unique identifier to each element, the present invention can accurately locate the target content according to the user's instructions, avoiding the fuzzy recognition and range overflow of LLM.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122595984A_ABST
    Figure CN122595984A_ABST
Patent Text Reader

Abstract

This invention discloses a method for rewriting local content in a large language model based on document structure parsing and instruction mapping. The method includes: performing structured parsing on the document to be rewritten to generate a structured document block index; mapping user natural language rewriting instructions to structured query instructions; accurately matching target document blocks in the index based on target document block constraints; determining structural boundaries based on the type and relationship of the target document blocks; selecting relevant context document blocks and generating a controlled context according to a preset strategy; inputting the target content, controlled context, and rewriting constraints into a large language model to obtain the rewriting result; and after structural consistency verification, accurately backfilling the rewriting result to the corresponding position in the original document based on position offset information. This invention, through structured parsing and instruction mapping, achieves precise location and rewriting of local document content, effectively solving the problems of inaccurate local content recognition, overflow of rewriting scope, incoherent context, and high computational cost in existing technologies.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the fields of natural language processing (NLP), artificial intelligence, and document automation, specifically to a method, system, computer-readable storage medium, and electronic device for rewriting local content of a large language model based on document structure parsing and instruction mapping. Background Technology

[0002] With the rapid development of Large Language Models (LLMs), their capabilities in tasks such as text generation, summarization, translation, and rewriting have significantly improved. However, in real-world applications, users often need to precisely rewrite specific parts of a document, rather than the entire document. For example, users might request the rewriting of specific structural units such as the "first paragraph," the "concluding sentence of the background section," or the "second point list item."

[0003] Currently, users typically input entire documents or long text fragments into an LLM, along with natural language instructions such as "Please rewrite the first paragraph of this article." LLMs face the following technical challenges when processing such instructions:

[0004] 1. Inaccurate Local Content Recognition: LLM typically treats input text as a flat sequence of characters. While it can roughly infer structural concepts such as paragraphs and chapters based on language patterns, this inference lacks explicit document structure information, resulting in unstable recognition results. Especially when processing documents with structured markup, such as Markdown and HTML, LLM may mistakenly identify long sentences or incomplete paragraphs as targets for positional instructions like "first paragraph," or merge multiple short paragraphs. For semantic instructions like "background content," cross-boundary recognition errors are even more likely to occur.

[0005] 2. Overwrite range: Due to inaccurate recognition, the actual rewrite range of LLM may exceed the user-specified boundary or fail to fully cover the target content, resulting in a deviation between the rewrite result and the user's expectations.

[0006] 3. Context utilization versus computational cost conflict: If only partial content is provided to the LLM for rewriting, the model lacks full document context information, which can easily lead to inconsistencies between the rewritten result and the original text style or logical breaks; if the full document is provided as context, the computational load of the model and the cost of API calls will be significantly increased.

[0007] 4. Limited effectiveness of prompt words: Although well-designed prompt words can alleviate the localization problem to some extent, their robustness and generalization ability are insufficient when faced with complex document structures and diverse user commands, making it difficult to fundamentally solve the structured recognition problem.

[0008] 5. Poor document format compatibility: Different document formats (such as Markdown, HTML, LaTeX, and plain text) have different definitions and representations of structural units such as paragraphs and chapters. Existing LLM lacks a unified structured processing capability.

[0009] In summary, existing technologies have significant shortcomings in using LLM to achieve precise, localized, and structured document rewriting, and there is an urgent need for a solution that can effectively overcome these deficiencies. Summary of the Invention

[0010] To overcome the aforementioned deficiencies in existing technologies, this application proposes a novel method and system for local content rewriting based on a large language model (LLM) of document structure parsing and instruction mapping. More specifically, this invention proposes a method and system for local content rewriting of structured documents using a large language model. This solution can accurately identify specific local content in structured documents and rewrite it efficiently, accurately, and context-awarely using a large language model, thereby solving problems such as inaccurate local content location, overflow of rewriting scope, and incoherent context in existing technologies.

[0011] To achieve the above objectives, the present invention employs the following technical strategies:

[0012] 1. Modular and Scalable Design: This invention introduces a document structure parsing module and an instruction mapping module to transform the original structured document into machine-readable structured data. User natural language rewriting instructions are then mapped onto this structured data, enabling accurate recognition of the target content. Subsequently, rewriting is performed using a context generation module and a large language model. Finally, the original document content is seamlessly replaced by a document reconstruction module. Each component module in the system has a clear responsibility and is easy to replace and upgrade. For example, the Markdown parser can be replaced to support other formats, the instruction parser can be upgraded to support more complex semantic instructions, or the underlying LLM model can be changed.

[0013] 2. Hierarchical structured processing: Elevates documents from flat text to structured objects that can be manipulated programmatically, laying the foundation for precise operations in LLM, rather than directly feeding text into LLM.

[0014] 3. Instruction-to-Structure Mapping: Innovatively introducing instruction parsing and structured query engine, it transforms ambiguous natural language instructions into precise queries of structured document data, effectively solving the core pain point of LLM's inaccurate local content location.

[0015] 4. Intelligent Context Selection Mechanism: Not only does it provide the target content, but it also intelligently selects and provides relevant context based on its position in the document structure, ensuring the coherence and high quality of the rewritten content, while avoiding unnecessary token consumption.

[0016] 5. Complete closed-loop mechanism: It provides a complete closed loop from document input, instruction understanding, content rewriting to document output, which is suitable for engineering applications.

[0017] Specifically, this application provides the following technical solutions:

[0018] The first aspect of this application provides a method for rewriting local content of a large language model based on document structure parsing and instruction mapping, such as... Figure 1 As shown, the method includes:

[0019] S1. Obtain the document to be rewritten and the natural language rewriting instructions for the document to be rewritten;

[0020] S2. Perform structured parsing on the document to be rewritten, divide the document to be rewritten into multiple document blocks, and establish a structured document block index for each document block;

[0021] S3. Parse the natural language rewriting instructions and map them into structured query instructions; the structured query instructions include rewriting operation type, target document block constraints, and rewriting constraints.

[0022] S4. Based on the target document block constraints, perform rule matching in the structured document block index to determine the target document block to be rewritten;

[0023] S5. Determine the structural boundary corresponding to the target document block based on the document block type, hierarchy information, parent-child relationship information, adjacency relationship information and position offset information of the target document block;

[0024] S6. Based on the target document block and its structural boundaries, select a context document block related to the target document block from the document to be rewritten, and generate a controlled context according to a preset context control strategy; the controlled context includes a target content area that is allowed to be rewritten and a context content area that is for reference only and is prohibited from being rewritten;

[0025] S7. Input the content of the target document block, the controlled context, and the rewriting constraints into the large language model to obtain the rewriting result for the target document block;

[0026] S8. Perform a structural consistency check on the rewriting result to determine whether the rewriting result satisfies the structural constraints corresponding to the target document block.

[0027] S9. If the rewriting result passes the structural consistency check, the rewriting result is backfilled into the corresponding position in the document to be rewritten according to the position offset information of the target document block, and the rewritten document is generated.

[0028] Furthermore, in the method of this application, step S2, which involves performing structured parsing on the document to be rewritten, includes:

[0029] (1) Identify the document format of the document to be rewritten, and call the corresponding document parser according to the document format;

[0030] (2) Parse the document to be rewritten into an abstract syntax tree, a document object model tree, or an ordered sequence of document blocks;

[0031] (3) Generate the hierarchical relationship, parent-child relationship and adjacency relationship between document blocks based on the abstract syntax tree, document object model tree or ordered document block sequence;

[0032] (4) Assign a document block identifier to each document block and record the starting offset and ending offset of the document block in the document to be rewritten.

[0033] Furthermore, in the method of this application, in step S2, the structured document block index includes a document block identifier, a document block type, hierarchical information, parent-child relationship information, adjacency relationship information, original content, plain text content, and the position offset information of the document block in the document to be rewritten;

[0034] The structured document block index also includes at least one of the following: title path information, chapter affiliation information, sibling order information, format constraint information, protected segment information, or semantic tag information;

[0035] The document block type includes at least one of the following: title block, chapter block, paragraph block, list block, list item block, table block, table row block, table cell block, code block, formula block, reference block, image block, link block, footnote block, or metadata block.

[0036] Furthermore, in the method of this application, step S3 involves parsing the natural language rewriting instruction and mapping it to a structured query instruction, including:

[0037] (1) Identify the rewriting operation intent in the natural language rewriting instruction and map it to the rewriting operation type;

[0038] (2) Identify the target location description in the natural language rewriting instruction and map it to the target document block constraints;

[0039] (3) Identify the rewriting requirements in the natural language rewriting instructions and map them into rewriting constraints;

[0040] The target document block constraints include at least one of the following: document block type, chapter title, title path, chapter affiliation, sequential position, keywords, semantic tags, hierarchical information, or relative positional relationship.

[0041] Furthermore, in the method of this application, step S4 specifically includes:

[0042] (1) Based on at least one of the following constraints in the target document block: document block type, title path, chapter affiliation, sequential position, keywords, hierarchical information, or relative positional relationship, candidate document blocks are filtered in the structured document block index;

[0043] (2) If a unique candidate document block is obtained through screening, the unique candidate document block shall be determined as the target document block;

[0044] (3) If multiple candidate document blocks are obtained through filtering, continue filtering according to the additional limiting conditions until the target document block is determined, or output the candidate document block confirmation information;

[0045] The candidate document block confirmation information includes at least one of the following: document block identifier, title path, document block type, local content summary, or location description.

[0046] Furthermore, in the method of this application, step S5 specifically includes:

[0047] (1) When the target document block is a title block or a chapter block, the area from the starting position of the target document block to the starting position of the next same-level title block or higher-level title block is determined as the chapter structure boundary;

[0048] (2) When the target document block is a list item block, the list block to which it belongs is determined according to its parent-child relationship information, and the list structure boundary is determined according to the start position and end position of the list block to which it belongs;

[0049] (3) When the target document block is a table row block or a table cell block, the table block to which it belongs is determined according to its parent-child relationship information, and the table structure boundary is determined according to the table header, row structure or column structure of the table block to which it belongs.

[0050] (4) When the target document block is a code block, formula block, reference block or metadata block, its complete block start position and complete block end position are determined as the structural boundary.

[0051] Furthermore, in the method of this application, step S6, which involves generating a controlled context according to a preset context control strategy, specifically includes:

[0052] (1) Select the title block in the title path to which the target document block belongs;

[0053] (2) Select a document block that has a parent-child relationship, sibling relationship, or adjacent relationship with the target document block;

[0054] (3) Select a document block that has a format dependency relationship with the target document block;

[0055] (4) Based on the preset token budget, the selected document blocks are cropped, compressed, or summarized;

[0056] (5) Add target content tags to the target document block and add context content tags to the context document block; wherein, the target content tags are used to identify target content regions that are allowed to be rewritten by the large language model, and the context content tags are used to identify context content regions that are only for reference by the large language model and are prohibited from being rewritten.

[0057] Furthermore, in the method of this application, step S8 involves performing a structural consistency check on the rewritten result, including at least one of the following:

[0058] Verify whether the rewriting result retains the document block type of the target document block;

[0059] Verify whether the rewritten result retains the heading level, list level, table row and column structure, code block boundaries, formula boundaries, link addresses, image reference addresses, or footnote reference relationships of the target document block;

[0060] Verify whether the rewriting result does not modify the content marked as prohibited from rewriting in the controlled context;

[0061] Verify whether the rewriting result retains the protected segments, terms, variables, numbers, placeholders, or format marks specified in the rewriting constraints.

[0062] Furthermore, in the method of this application, step S9 specifically includes:

[0063] (1) Determine the local replacement interval based on the start and end offsets of the target document block;

[0064] (2) Replace the original content within the local replacement interval with the rewriting result, while keeping the document content outside the local replacement interval in the document to be rewritten unchanged;

[0065] (3) Update the structured document block index corresponding to the target document block according to the rewriting result, and generate the rewritten document.

[0066] The second aspect of this application provides a system for rewriting partial content of a large language model based on document structure parsing and instruction mapping. The system, when running, implements the steps of the aforementioned method for rewriting partial content of a large language model based on document structure parsing and instruction mapping, such as... Figure 2 As shown, the system includes:

[0067] The document acquisition module is used to acquire the document to be rewritten and the natural language rewriting instructions for the document to be rewritten.

[0068] The document structure parsing module is used to perform structured parsing on the document to be rewritten, divide the document to be rewritten into multiple document blocks, and establish a structured document block index for each document block.

[0069] The instruction mapping module is used to parse the natural language rewriting instructions and map them into structured query instructions;

[0070] The target location module is used to perform rule matching in the structured document block index according to the target document block constraints in the structured query instruction to determine the target document block to be rewritten.

[0071] The structural boundary determination module is used to determine the structural boundary corresponding to the target document block based on the document block type, hierarchy information, parent-child relationship information, adjacency relationship information and position offset information of the target document block;

[0072] A controlled context generation module is used to generate a controlled context based on the target document block and its structural boundaries; the controlled context includes a target content area that is allowed to be rewritten and a context content area that is for reference only and is prohibited from being rewritten;

[0073] The large language model rewriting module is used to input the content of the target document block, the controlled context, and the rewriting constraints into the large language model to obtain the rewriting result for the target document block;

[0074] The structural consistency verification module is used to perform structural consistency verification on the rewritten result.

[0075] The document backfilling module is used to backfill the rewriting result to the corresponding position in the document to be rewritten, based on the position offset information of the target document block, when the rewriting result passes the structural consistency check, thereby generating the rewritten document.

[0076] A third aspect of this application provides an electronic device, including: a memory and a processor;

[0077] Memory: Used to store computer programs;

[0078] Processor: Used to execute the computer program to implement the steps of the aforementioned method for rewriting local content of a large language model based on document structure parsing and instruction mapping.

[0079] A fourth aspect of this application provides a computer-readable storage medium having a computer program stored thereon, wherein when the computer program is executed by a processor, it implements the steps of the aforementioned method for rewriting local content of a large language model based on document structure parsing and instruction mapping.

[0080] In summary, compared with the prior art, the solution of the present invention has the following advantages:

[0081] (1) Significantly improved rewriting accuracy: By performing structured parsing of the document and assigning a unique identifier to each element, the present invention can accurately locate the target content according to the user's instructions, avoiding the fuzzy recognition and range overflow of LLM.

[0082] (2) Better rewriting quality: When submitting a rewriting request to LLM, in addition to the target content, the relevant context information is also provided to ensure that the rewritten content is consistent with the style and logic of the original text, thus improving the overall coherence.

[0083] (3) Efficient utilization of computing resources: The large language model only needs to process the precise target content and its limited context, rather than the entire document, which greatly reduces token consumption and API call costs and improves processing efficiency.

[0084] (4) User experience optimization: Users can issue more natural and flexible commands to specify the rewriting scope without the need for complex prompt word engineering or manual marking, thus lowering the threshold for use.

[0085] (5) Cross-format compatibility: This invention allows for the support of various structured document formats (such as Markdown, HTML, LaTeX, XML, etc.) by changing different document parsers, and has good versatility and scalability.

[0086] (6) Traceability and controllability: Since each document block has a unique ID, the system can easily track the rewrite history and version, and achieve more refined document management.

[0087] Other features and advantages of this application will be set forth in detail in the following description, or will become apparent through the implementation of the relevant technical solutions of this application. The objectives and other advantages of this application can be achieved through the technical features and means explicitly pointed out in the description, claims, and drawings, and will be obtained through the implementation of these technical contents. Attached Figure Description

[0088] To more clearly illustrate the technical solution of this application, the accompanying drawings involved in the description of this invention will be briefly introduced below. It should be noted that the drawings only show some embodiments of the invention. For those skilled in the art, other related drawings can be derived from these drawings without creative effort.

[0089] Figure 1 This diagram illustrates the operational steps of the method for rewriting local content of a large language model based on document structure parsing and instruction mapping, as described in this invention.

[0090] Figure 2 This is a structural diagram of the local content rewriting system of a large language model based on document structure parsing and instruction mapping, as presented in this invention.

[0091] Figure 3 This is a schematic diagram of the overall architecture of the system of the present invention.

[0092] Figure 4 This is a schematic diagram of the document structure parsing module processing in the system of the present invention.

[0093] Figure 5 This is a schematic diagram of the workflow of the instruction parsing and target localization module in the system of the present invention.

[0094] Figure 6 This is a schematic diagram of the structure of an electronic device provided in an embodiment of the present invention.

[0095] Caption: Processor-310, Communication Interface-320, Memory-330, Communication Bus-340. Detailed Implementation

[0096] To make the objectives, technical solutions, and advantages of the embodiments of this application clearer, the technical solutions in the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. It should be understood that the described embodiments are only some embodiments of this application, and not all embodiments. All other embodiments obtained by those skilled in the art based on the embodiments of this application without creative effort are within the protection scope of this application.

[0097] In this document, the term "comprising" and any variations thereof (such as "including," "including," etc.) are open-ended expressions and should be understood as "including but not limited to," meaning that the listed content is not exhaustive and may include other content not explicitly mentioned. The term "based on" should be understood as "at least partially based on," meaning that the basis or condition referred to may not be the only factor and may involve other relevant factors. The term "one embodiment" should be understood as "at least one embodiment," meaning that the described embodiment is not the only possible implementation, and other similar embodiments may exist.

[0098] In this application, the terms "a" and "a plurality of" are used to modify related elements or features, and their expression is illustrative rather than restrictive. Unless otherwise expressly stated in the context, "a" should be understood as "at least one," and "a plurality of" should be understood as "at least two." Those skilled in the art should reasonably interpret these terms based on the semantic and logical relationships of the context to ensure that they cover the possibility of "one or more."

[0099] This invention provides the following technical solution:

[0100] A method and system for rewriting local content of a large language model based on document structure parsing and instruction mapping

[0101] Figure 3 This is a schematic diagram of the overall architecture of the system of the present invention, which mainly includes the following modules:

[0102] 1. Document Structure Parser Module

[0103] Figure 4 This is a schematic diagram of the document structure parsing module processing in the system of the present invention.

[0104] Function: Receives raw structured documents (such as Markdown format) and parses them into an internal data structure that can be programmed.

[0105] accomplish:

[0106] (1) Use existing Markdown parsing libraries (such as markdown-it, commonmark.py, etc.) to convert Markdown text into an abstract syntax tree (AST) or a series of structured document blocks.

[0107] (2) Each parsed document block (e.g., title, paragraph, list, code block, image, etc.) is encapsulated to form a document block object.

[0108] Document block object properties:

[0109] id (String): A globally unique identifier (e.g., p-1, h2-3, li-item-4-2).

[0110] type (Enum): The type of block (HEADING, PARAGRAPH, LIST_ITEM, CODE_BLOCK, IMAGE, TABLE, etc.).

[0111] level (Integer): For headings, it indicates their level (H1-H6); for list items, it indicates the nesting depth.

[0112] raw_content(String): The Markdown substring of this block in the original document.

[0113] text_content(String): The plain text content of this block (with Markdown syntax removed).

[0114] start_offset(Integer): The starting character index of this block in the original docstring.

[0115] end_offset(Integer): The index of the end character of this block in the original docstring.

[0116] parent_id (String): (Optional) An ID pointing to its parent document block, used to build the hierarchical relationship of the document.

[0117] children_ids(List <string>): (Optional) Points to the ID of its child document block.

[0118] semantic_tags(List) <string>): (Optional) Semantic tags (such as "Introduction", "Background", "Conclusion") automatically identified by keyword matching or small machine learning models.

[0119] Output: An ordered list containing all document block objects or an iterable AST structure.

[0120] 2. Instruction Interpreter & Target Locator Module

[0121] Figure 5 This is a schematic diagram of the workflow of the instruction parsing and target localization module in the system of the present invention.

[0122] Function: Receives the user's natural language rewriting instructions and the output of the document structure parsing module, parses the instructions and accurately identifies the ID of the document block that needs to be rewritten.

[0123] accomplish:

[0124] (1) Natural Language Parser:

[0125] A rule-based pattern matching system can be used to identify common structured instruction keywords, such as "paragraph X", "list item Y", "chapter with title Z", "first paragraph of the background section", etc.

[0126] Alternatively, deploy a small, pre-trained or fine-tuned LLM specifically designed to parse user commands into structured queries, such as: { "action": "rewrite", "target_type": "paragraph", "order": 1, "section_title_contains": "background"}.

[0127] (2) Structured query engine:

[0128] Based on the parsed structured query, perform an efficient search in the list of document block objects.

[0129] For example, regarding the "first background section":

[0130] Find all blocks where type == HEADING and text_content contains "background" or semantic_tags contain "Background".

[0131] If found, use it as the starting point for the background section and collect all subsequent document blocks up to the next sibling or higher-level heading.

[0132] From these blocks that belong to the "background section", filter out the blocks with type == PARAGRAPH and select the first one.

[0133] Output: A precise list of target document block IDs.

[0134] 3. Context Generator module

[0135] Function: Extract several surrounding document blocks as context based on the target document block, so as to provide necessary semantic and style references for large language models.

[0136] accomplish:

[0137] (1) Contextual strategy:

[0138] Neighboring block strategy: Extract the first N and last N neighboring blocks of the target block ID in the document block list.

[0139] Parent / Sibling Strategy: If the target block has a parent (such as a list item), extract the content of its parent block or its sibling blocks. If the target block is a paragraph, extract the title of its chapter and the immediately adjacent paragraphs within that chapter.

[0140] Hybrid strategy: Combining the two strategies mentioned above.

[0141] (2) Context formatting: Combine the raw_content of the context block and use specific delimiters or tags (such as...)<CONTEXT_BEFORE> ,<CONTEXT_AFTER> This wraps around the larger model to clearly inform it which elements constitute the context and which are the targets that need to be rewritten.

[0142] Output: Structured data containing the original Markdown content of the target block, the preceding context Markdown content, and the following context Markdown content.

[0143] 4. Large Language Model Interaction Module (LLM Orchestration)

[0144] Function: Constructs a Prompt containing the target content, context, and rewriting instructions, and interacts with the Large Language Model (LLM) to obtain the rewriting result.

[0145] accomplish:

[0146] (1) Prompt construction:

[0147] You are a professional document rewriting assistant. Please rewrite the document based on the following instructions and the provided context.<TARGET_TO_REWRITE> The content within the tags. Ensure that the rewritten content remains consistent with the context in terms of semantics, style, and coherence.

[0148] User instruction: [The user's original rewrite instruction, such as "Please use more concise and professional language."]

[0149] <CONTEXT_BEFORE>

[0150] [Markdown content of the preceding context]

[0151] < / CONTEXT_BEFORE>

[0152] <TARGET_TO_REWRITE>

[0153] [The original Markdown content of the target document block]

[0154] < / TARGET_TO_REWRITE>

[0155] <CONTEXT_AFTER>

[0156] [Markdown content following the context]

[0157] < / CONTEXT_AFTER>

[0158] Please output the rewritten version.<TARGET_TO_REWRITE> Content, and ensure the format is Markdown.

[0159] (2) API call: Send the constructed Prompt through the API of the LLM provider (such as OpenAI GPT series, Anthropic Claude series, etc.) and receive the LLM response.

[0160] Output: Rewritten Markdown content generated by the large language model.

[0161] 5. Document Reconstructor Module

[0162] Function: Replace the rewritten content generated by the large language model back to the corresponding position in the original document, and output the updated complete document.

[0163] accomplish:

[0164] (1) Locate the range to be replaced in the original document string based on the start_offset and end_offset attributes of the target document block.

[0165] (2) Replace the original content in the range with the rewritten Markdown content generated by LLM.

[0166] (3) Formatting consistency check: If the rewritten content does not match the Markdown type of the original block (for example, rewriting list items as regular paragraphs), the user can be prompted or an automatic adjustment can be attempted. Normally, LLM will maintain the original formatting output after receiving Markdown formatting instructions.

[0167] Output: A complete Markdown document containing the rewritten content.

[0168] The flowcharts and block diagrams in the accompanying drawings illustrate possible implementations of systems, methods, and computer program products according to various embodiments of this application, including architecture, functionality, and operation. In these figures, each block may represent a module, program segment, or portion of code containing one or more executable instructions for implementing a specified logical function. It should be noted that each block in the block diagrams and / or flowcharts, and combinations thereof, can be implemented using either a dedicated hardware-based system or a combination of dedicated hardware and computer instructions to achieve the specified function or operation.

[0169] like Figure 6 As shown, embodiments of this application also disclose an electronic device, including: a processor 310, a communication interface 320, a memory 330 for storing processor-executable computer programs, and a communication bus 340. The processor 310, communication interface 320, and memory 330 communicate with each other via the communication bus 340. The processor 310 executes the executable computer program to implement the steps of the aforementioned method for rewriting local content of a large language model based on document structure parsing and instruction mapping.

[0170] It is understood that, in addition to memory and a processor, this electronic device may also include input devices (such as a keyboard), output devices (such as a display), and other communication modules. These input devices, output devices, and other communication modules all communicate with the processor through I / O interfaces (i.e., input / output interfaces).

[0171] The operations described in this application can be implemented by writing computer program code using one or more programming languages ​​or a combination thereof. The programming languages ​​include, but are not limited to, the following types:

[0172] Object-oriented programming languages, such as Java, Smalltalk, C++, etc.

[0173] Conventional procedural programming languages, such as "C" or similar programming languages.

[0174] The execution methods of program code include, but are not limited to:

[0175] It runs entirely on the user's computer;

[0176] Part of it executes on the user's computer, and part of it executes on a remote computer;

[0177] Execute as a standalone software package;

[0178] It is executed entirely on a remote computer or server.

[0179] In scenarios involving remote computers, the remote computer can connect to the user's computer via any type of network, including but not limited to local area networks (LANs) or wide area networks (WANs). Furthermore, the remote computer can also connect to external computers through an internet service provider, for example, by utilizing the internet for connection.

[0180] Furthermore, this application also discloses a computer-readable storage medium, which, when the instructions in the computer-readable storage medium are executed by the processor of an electronic device, enables the electronic device to perform the various steps of the large language model local content rewriting method based on document structure parsing and instruction mapping disclosed in this application.

[0181] In the context of this application, a computer-readable storage medium refers to a tangible medium capable of storing computer program code and related data. Specific examples include, but are not limited to, the following:

[0182] (1) Portable computer disk: such as floppy disks and other removable magnetic storage media.

[0183] (2) Hard disk: including mechanical hard disks and solid-state hard disks and other fixed storage devices.

[0184] (3) Random Access Memory (RAM): A volatile storage medium used for temporary storage of data and program code.

[0185] (4) Read-only memory (ROM): a non-volatile storage medium used to store fixed programs and data.

[0186] (5) Erasable programmable read-only memory (EPROM) or flash memory: non-volatile storage media that supports multiple erasures and reprogrammings.

[0187] (6) Fiber optic storage devices: storage media based on fiber optic technology.

[0188] (7) Portable compact disc read-only memory (CD-ROM): a read-only medium that stores data in the form of an optical disc.

[0189] (8) Optical storage devices: such as DVDs, Blu-ray discs and other storage media based on optical principles.

[0190] (9) Magnetic storage devices: such as magnetic tapes, disks and other storage media based on magnetic principles.

[0191] (10) Any suitable combination of the above: for example, combining multiple storage media to meet different storage needs.

[0192] These computer-readable storage media can be used to store the program code and related data described in this application to support program execution and persistent data storage.

[0193] Specifically, according to embodiments of this application, the processes described in the flowcharts can be implemented as computer software programs. For example, embodiments of this application relate to a computer program product comprising a computer program carried on a non-transitory computer-readable medium. This computer program includes program code for executing the large language model partial content rewriting method based on document structure parsing and instruction mapping disclosed in this application. When this computer program is executed by a processing system, it can achieve the functions defined in the embodiments of this application.

[0194] While the foregoing discussion contains several specific implementation details, these details should not be construed as limiting the scope of this application. The above description is merely a preferred embodiment of this application and an explanation of the technical principles employed. Those skilled in the art should understand that the scope of this application is not limited to technical solutions formed by specific combinations of the above-described technical features. Furthermore, this application should also cover other technical solutions formed by any combination of the above-described technical features or their equivalents without departing from the foregoing disclosed concept.

[0195] Those skilled in the art should also understand that modifications can be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features, without departing from the spirit and scope of the technical solutions of the embodiments of this application. These modifications or substitutions will not cause the essence of the corresponding technical solutions to deviate from the core spirit and scope of the technical solutions of the embodiments of this application.< / string> < / string>

Claims

1. A method for rewriting local content of a large language model based on document structure parsing and instruction mapping, characterized in that, Includes the following steps: S1. Obtain the document to be rewritten and the natural language rewriting instructions for the document to be rewritten; S2. Perform structured parsing on the document to be rewritten, divide the document to be rewritten into multiple document blocks, and establish a structured document block index for each document block; S3. Parse the natural language rewriting instructions and map them into structured query instructions; the structured query instructions include rewriting operation type, target document block constraints, and rewriting constraints. S4. Based on the target document block constraints, perform rule matching in the structured document block index to determine the target document block to be rewritten; S5. Determine the structural boundary corresponding to the target document block based on the document block type, hierarchy information, parent-child relationship information, adjacency relationship information and position offset information of the target document block; S6. Based on the target document block and its structural boundaries, select a context document block related to the target document block from the document to be rewritten, and generate a controlled context according to a preset context control strategy. The controlled context includes target content areas that are allowed to be rewritten and context content areas that are for reference only and are prohibited from being rewritten. S7. Input the content of the target document block, the controlled context, and the rewriting constraints into the large language model to obtain the rewriting result for the target document block; S8. Perform a structural consistency check on the rewriting result to determine whether the rewriting result satisfies the structural constraints corresponding to the target document block. S9. If the rewriting result passes the structural consistency check, the rewriting result is backfilled into the corresponding position in the document to be rewritten according to the position offset information of the target document block, and the rewritten document is generated.

2. The method according to claim 1, characterized in that, In step S2, the document to be rewritten is subjected to structured parsing, including: (1) Identify the document format of the document to be rewritten, and call the corresponding document parser according to the document format; (2) Parse the document to be rewritten into an abstract syntax tree, a document object model tree, or an ordered sequence of document blocks; (3) Generate the hierarchical relationship, parent-child relationship and adjacency relationship between document blocks based on the abstract syntax tree, document object model tree or ordered document block sequence; (4) Assign a document block identifier to each document block and record the starting offset and ending offset of the document block in the document to be rewritten.

3. The method according to claim 1, characterized in that, In step S2, the structured document block index includes document block identifier, document block type, hierarchy information, parent-child relationship information, adjacency relationship information, original content, plain text content, and the position offset information of the document block in the document to be rewritten; The document block type includes at least one of the following: title block, chapter block, paragraph block, list block, list item block, table block, table row block, table cell block, code block, formula block, reference block, image block, link block, footnote block, or metadata block.

4. The method according to claim 1, characterized in that, In step S3, the natural language rewriting instructions are parsed and mapped into structured query instructions, including: (1) Identify the rewriting operation intent in the natural language rewriting instruction and map it to the rewriting operation type; (2) Identify the target location description in the natural language rewriting instruction and map it to the target document block constraints; (3) Identify the rewriting requirements in the natural language rewriting instructions and map them into rewriting constraints; The target document block constraints include at least one of the following: document block type, chapter title, title path, chapter affiliation, sequential position, keywords, semantic tags, hierarchical information, or relative positional relationship.

5. The method according to claim 1, characterized in that, Step S4 specifically includes: (1) Based on at least one of the following constraints in the target document block: document block type, title path, chapter affiliation, sequential position, keywords, hierarchical information, or relative positional relationship, candidate document blocks are filtered in the structured document block index; (2) If a unique candidate document block is obtained through screening, the unique candidate document block shall be determined as the target document block; (3) If multiple candidate document blocks are obtained through filtering, the filtering continues according to the additional limiting conditions until the target document block is determined, or the candidate document block confirmation information is output.

6. The method according to claim 1, characterized in that, Step S5 specifically includes: (1) When the target document block is a title block or a chapter block, the area from the starting position of the target document block to the starting position of the next same-level title block or higher-level title block is determined as the chapter structure boundary; (2) When the target document block is a list item block, the list block to which it belongs is determined according to its parent-child relationship information, and the list structure boundary is determined according to the start position and end position of the list block to which it belongs; (3) When the target document block is a table row block or a table cell block, the table block to which it belongs is determined according to its parent-child relationship information, and the table structure boundary is determined according to the table header, row structure or column structure of the table block to which it belongs. (4) When the target document block is a code block, formula block, reference block or metadata block, its complete block start position and complete block end position are determined as the structural boundary.

7. The method according to claim 1, characterized in that, In step S6, generating a controlled context according to a preset context control strategy specifically includes: (1) Select the title block in the title path to which the target document block belongs; (2) Select a document block that has a parent-child relationship, sibling relationship, or adjacent relationship with the target document block; (3) Select a document block that has a format dependency relationship with the target document block; (4) Based on the preset token budget, the selected document blocks are cropped, compressed, or summarized; (5) Add target content tags to the target document block and add context content tags to the context document block; wherein, the target content tags are used to identify target content regions that are allowed to be rewritten by the large language model, and the context content tags are used to identify context content regions that are only for reference by the large language model and are prohibited from being rewritten.

8. The method according to claim 1, characterized in that, In step S8, the rewritten result is subjected to structural consistency verification, including at least one of the following: Verify whether the rewriting result retains the document block type of the target document block; Verify whether the rewritten result retains the heading level, list level, table row and column structure, code block boundaries, formula boundaries, link addresses, image reference addresses, or footnote reference relationships of the target document block; Verify whether the rewriting result does not modify the content marked as prohibited from rewriting in the controlled context; Verify whether the rewriting result retains the protected segments, terms, variables, numbers, placeholders, or format marks specified in the rewriting constraints.

9. The method according to claim 1, characterized in that, Step S9 specifically includes: (1) Determine the local replacement interval based on the start and end offsets of the target document block; (2) Replace the original content within the local replacement interval with the rewriting result, while keeping the document content outside the local replacement interval in the document to be rewritten unchanged; (3) Update the structured document block index corresponding to the target document block according to the rewriting result, and generate the rewritten document.

10. A local content rewriting system for a large language model based on document structure parsing and instruction mapping, characterized in that, The system runtime implements the steps of the large language model local content rewriting method based on document structure parsing and instruction mapping as described in any one of claims 1-9, including: The document acquisition module is used to acquire the document to be rewritten and the natural language rewriting instructions for the document to be rewritten. The document structure parsing module is used to perform structured parsing on the document to be rewritten, divide the document to be rewritten into multiple document blocks, and establish a structured document block index for each document block. The instruction mapping module is used to parse the natural language rewriting instructions and map them into structured query instructions; The target location module is used to perform rule matching in the structured document block index according to the target document block constraints in the structured query instruction to determine the target document block to be rewritten. The structural boundary determination module is used to determine the structural boundary corresponding to the target document block based on the document block type, hierarchy information, parent-child relationship information, adjacency relationship information and position offset information of the target document block; A controlled context generation module is used to generate a controlled context based on the target document block and its structural boundaries; the controlled context includes a target content area that is allowed to be rewritten and a context content area that is for reference only and is prohibited from being rewritten; The large language model rewriting module is used to input the content of the target document block, the controlled context, and the rewriting constraints into the large language model to obtain the rewriting result for the target document block; The structural consistency verification module is used to perform structural consistency verification on the rewritten result. The document backfilling module is used to backfill the rewriting result to the corresponding position in the document to be rewritten, based on the position offset information of the target document block, when the rewriting result passes the structural consistency check, thereby generating the rewritten document.