A multi-disciplinary question type Markdown structured output, analysis and rich text conversion method and system for paper test paper electronicization
Patent Information
- Application Number
- CN202610905373.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-06-23
- Publication Date
- 2026-10-30
AI Technical Summary
[0010]本发明要解决的技术问题是在多学科、多题型、含公式和富文本的纸质试卷电子化场景下,如何降低模型输出格式复杂度,使识别结果稳定落入题库字段,保留公式和排版展示能力,支持人工复核和错误回溯,并形成可规模化维护的模板与解析器工程闭环,为解决上述问题,提供面向纸质试卷电子化的多学科题型 Markdown 结构化输出、解析与富文本转换方法及系统
[0021]本发明的有益效果:通过学科×题型二维模板矩阵,解决了不同学科、不同题型字段差异大、单一提示词难以稳定适配的问题,提高了题目结构化提取的扩展性。
Smart Images

Figure CN123013852A_ABST
Abstract
Description
Technical Field
[0001] This invention belongs to the fields of educational informatization, intelligent document processing, multimodal large model application, test paper image understanding, structured information extraction and rich text conversion technology. Specifically, it relates to a method and system for Markdown structured output, parsing and rich text conversion of multi-disciplinary question types for the digitization of paper test papers. Background Technology
[0002] In the digitization of paper exam papers, a common process is as follows: first, the exam paper image is recognized using OCR, layout analysis, or a multimodal large-scale model; then, the recognition results are converted into structured data required by the question bank system. Existing technologies typically employ the following solutions: allowing the large model to directly output JSON structured data; extracting text, formulas, tables, etc., using an OCR or layout parsing pipeline, and then converting them into JSON using rules or models; allowing the large model to directly output HTML to preserve the display format; and converting multi-format documents into Markdown intermediate documents before extracting indicators or validating rules.
[0003] The above-mentioned solutions have significant shortcomings in the scenario of digitizing paper-based test papers.
[0004] First, directly requiring large models to output JSON results in poor stability. The questions often contain complex content such as mathematical formulas, backslashes, fractions, subscripts and superscripts, chart references, and nested sub-questions, requiring high precision in JSON string escaping. The model is prone to issues such as missing quotes, missing commas, unclosed parentheses, incorrect backslash counts, disordered field nesting, excessively long outputs, and even non-convergence, leading to JSON parsing failures on the backend.
[0005] Secondly, directly requiring large models to output HTML is too complex. HTML tags, attributes, nesting relationships, escape characters, and security filtering rules are all quite complex. Large models are prone to generating HTML with unclosed tags, incorrectly nested tags, or that do not conform to business style specifications, resulting in high subsequent cleaning costs.
[0006] Third, paper-based exam papers exhibit significant differences in subject matter and question types. The required fields, levels, and output structures differ for question types such as math problem-solving, English reading comprehension, English cloze tests, Chinese reading comprehension, and physics experiment questions. Using a single structured output prompt is insufficient to accommodate multiple subjects and question types.
[0007] Fourth, while existing technologies exist to reconstruct document parsing results into Markdown, their focus is usually on parsing multi-format documents, extracting indicators, or validating rules. They have not established a complete engineering closed loop for the digitization of paper exam papers, consisting of "multimodal large-scale native Markdown output protocol + subject question type template matrix + template binding parser + rich text HTML conversion".
[0008] A search revealed the following similar publicly available solutions: CN121859835A discloses a method for parsing and verifying multi-format documents, but its focus is not on test paper question type fields, template parser binding, or rich text input into the question bank; CN121835650A discloses a structured data parsing method, but does not establish a specific mechanism for rich text formulas or differences in subject question types; CN121768021A discloses a visual document analysis method, but its output still focuses on general document structures and does not directly solve the problem of inputting test question objects into the database.
[0009] Therefore, existing technologies have not yet formed a complete solution for the conversion of paper-based exam papers into electronic assets. Summary of the Invention
[0010] The technical problem this invention aims to solve is how to reduce the complexity of the model output format in the context of digitizing paper-based exam papers with multiple disciplines, multiple question types, formulas, and rich text, so that the recognition results can stably fall into the question bank fields, retain the ability to display formulas and layout, support manual review and error backtracking, and form a scalable and maintainable template and parser engineering closed loop. To solve the above problems, this invention provides a method and system for Markdown structured output, parsing, and rich text conversion of multiple disciplines for digitizing paper-based exam papers.
[0011] The object of this invention is achieved in the following manner: A method for Markdown structured output, parsing, and rich text conversion of multi-disciplinary question types for digitizing paper-based exam papers includes the following steps: S1: Receive images of paper exam papers or questions, and obtain information on the subject and question type of the questions; S2: Based on the subject and question type, select the corresponding prompt word template and parser from the pre-constructed subject × question type template matrix; wherein, the prompt word template specifies the output protocol that guides the multimodal large model output to conform to the preset Markdown structure, and the parser is used to parse the preset Markdown structure into structured question objects; S3: Generate complete prompts based on the selected prompt template, input the title image and the complete prompts into the multimodal large model, and obtain the Markdown structured text output by the multimodal large model; S4: Invoke the parser bound to the prompt word template to parse the Markdown structured text and generate an internal structured question object; S5: Perform HTML rich text conversion on the Markdown fields in the structured question object to obtain field-level HTML rich text; S6: Perform structured validation on the structured question object and the field-level HTML rich text, and output the validation result to the question bank system.
[0012] Each matrix unit in the subject × question type two-dimensional template matrix includes a subject identifier, question type identifier, output field definition, Markdown title and field mapping rules, example input and output, parser name and version number, and validation rules; each matrix unit corresponds to a unique template number and version number.
[0013] Furthermore, each matrix unit of the subject × question type template matrix includes at least: subject identifier, question type identifier, output field definition, Markdown title and field mapping rules, parser identifier, and version number; the output protocol includes: Use Markdown heading levels to represent the question structure, with first-level headings representing questions and second-level headings representing fields; Options are represented using Markdown lists, with option markers in the form of -A. and -B.; Use $...$ to represent inline formulas, and $$...$$ to represent block-level formulas. LaTeX backslashes within formulas remain unchanged. Includes an output termination tag and prohibits the output of JSON or HTML tags.
[0014] In step S4, when the parser parses the Markdown structured text, it performs the following sub-steps: Retrieve the parser instance based on the template identifier and parser version; Check if a termination marker exists; if not, mark the output as incomplete. Scan the Markdown text according to the heading level declared in the template, and segment the question stem, options, answer, explanation, sub-question and illustration reference into field fragments; Generates an internally structured question object, while retaining the original Markdown, template version, parser version, and exception information.
[0015] Furthermore, the HTML rich text conversion in step S5 includes a formula processing sub-step: Identify inline formulas $$...$ and block-level formulas $$...$$ from Markdown fields, record each formula fragment as a formula object and replace it with a formula placeholder; Perform controlled transformations on Markdown content to generate HTML fragments, allowing only preset security tags to be whitelisted; After completing the HTML security filtering, the formula placeholders will be restored to the formula rendering tags supported by the question bank system.
[0016] Furthermore, after obtaining the Markdown structured text in step S3 and before parsing in step S4, a preprocessing step is also included: cleaning the model output, detecting termination marks, repairing abnormal marks, and filtering illegal content; when a missing termination mark, a missing key title, an unclosed formula mark, or incomplete output content is detected, a retry, local repair, or manual review process is triggered.
[0017] Furthermore, the structured validation in step S6 includes at least one of the following: validation of required fields, validation of the number of options, validation of the range of answers, validation of paired formula tags, validation of the continuity of sub-question levels, validation of illegal HTML tags, and validation of the consistency between the template version and the parser version.
[0018] A multi-disciplinary Markdown structured output, parsing, and rich text conversion system for digitizing paper-based exam papers, used to implement the method described above, the system comprising: The test paper image input module is used to receive images of paper test papers or questions, and output image data and context information. The subject-specific question type routing module, whose input is connected to the output of the test paper image input module, is used to determine the subject and question type of the questions; The template matrix management module is used to maintain a two-dimensional template matrix of subject × question type. Each matrix unit contains prompt word templates and parser identifiers. The prompt word assembly module has its first input end connected to the output end of the subject question type routing module and its second input end connected to the output end of the template matrix management module, and is used to generate complete prompt words; The multimodal large model calling module has its first input end connected to the output end of the prompt word assembly module and its second input end connected to the output end of the test paper image input module, and is used to obtain Markdown structured text. The template binding parser module has its input end connected to the output end of the multimodal large model calling module and is bound to the parser specified in the template matrix management module. It is used to parse Markdown into internal structured question objects. The Markdown to HTML rich text conversion module has its input end connected to the output end of the template binding parser module, and is used to convert Markdown fields into HTML rich text. The structured validation module has its input terminals connected to the output terminals of the template binding parser module and the Markdown to HTML rich text conversion module, respectively, and is used to perform validation. The result output module has its input end connected to the output end of the structured verification module, and is used to output the verified structured objects to the question bank system.
[0019] The Markdown to HTML rich text conversion module embeds a formula placeholder and restoration submodule. This submodule replaces formula fragments with placeholders before Markdown parsing and restores the placeholders to formula rendering tags after HTML security filtering. The template binding parser module includes: a Markdown preprocessing unit for removing wrapping noise and checking termination tags; a field segmentation unit for segmenting field fragments according to the title level agreed upon in the template; and a structured object generation unit for outputting internal structured question objects containing the original Markdown and version information.
[0020] A computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the method.
[0021] The beneficial effects of this invention are: by using a two-dimensional template matrix of subject × question type, it solves the problem of large differences in fields between different subjects and question types and the difficulty in stable adaptation of a single prompt word, thereby improving the scalability of structured question extraction.
[0022] It adopts the native Markdown structured output protocol of multimodal large model, avoiding problems such as unclosed brackets, messy field nesting, failed backslash escaping, and output non-convergence caused by direct JSON output.
[0023] By binding the prompt word template with the backend parser and implementing a version synchronization mechanism, the problem of parser mismatch after prompt word format adjustment is solved, making the template and parser maintainable structured extraction units.
[0024] A controlled Markdown-to-HTML conversion mechanism is adopted for formulas and rich text for teaching purposes. This reduces the complexity of the model output while retaining the rich text information required for the question bank display, such as formulas, bolding, underlining, lists, and tables. Attached Figure Description
[0025] Figure 1 This is the overall flowchart of the system of the present invention.
[0026] Figure 2 This is a schematic diagram of a two-dimensional template matrix for the subject and question type of this invention.
[0027] Figure 3 This is a diagram showing the binding relationship between the prompt word template and the parser in this invention.
[0028] Figure 4 This is a flowchart illustrating the process of parsing Markdown into structured objects in this invention.
[0029] Figure 5 This is a flowchart illustrating the Markdown to HTML rich text conversion process of this invention.
[0030] Figure 6 This is a schematic diagram of the interface for reviewing the recognition results of the system of the present invention. Detailed Implementation
[0031] The present invention will now be described in further detail with reference to the accompanying drawings and specific embodiments.
[0032] It should be noted that the following detailed descriptions are exemplary and intended to provide further explanation of this application. Unless otherwise specified, all technical and scientific terms used herein have the same technical meaning as commonly understood by one of ordinary skill in the art to which this application pertains.
[0033] A method for Markdown structured output, parsing, and rich text conversion of multi-disciplinary question types for digitizing paper-based exam papers includes the following steps: S1: Receive images of paper exam papers or questions, and obtain information on the subject and question type of the questions; S2: Based on the subject and question type, select the corresponding prompt word template and parser from the pre-constructed subject × question type template matrix; wherein, the prompt word template specifies the output protocol that guides the multimodal large model output to conform to the preset Markdown structure, and the parser is used to parse the preset Markdown structure into structured question objects; S3: Generate complete prompts based on the selected prompt template, input the title image and the complete prompts into the multimodal large model, and obtain the Markdown structured text output by the multimodal large model; S4: Invoke the parser bound to the prompt word template to parse the Markdown structured text and generate an internal structured question object; S5: Perform HTML rich text conversion on the Markdown fields in the structured question object to obtain field-level HTML rich text; S6: Perform structured validation on the structured question object and the field-level HTML rich text, and output the validation result to the question bank system.
[0034] Each matrix unit in the subject × question type two-dimensional template matrix includes a subject identifier, question type identifier, output field definition, Markdown title and field mapping rules, example input and output, parser name and version number, and validation rules; each matrix unit corresponds to a unique template number and version number.
[0035] Furthermore, each matrix unit of the subject × question type template matrix includes at least: subject identifier, question type identifier, output field definition, Markdown title and field mapping rules, parser identifier, and version number; the output protocol includes: Use Markdown heading levels to represent the question structure, with first-level headings representing questions and second-level headings representing fields; Options are represented using Markdown lists, with option markers in the form of -A. and -B.; Use $...$ to represent inline formulas, and $$...$$ to represent block-level formulas. LaTeX backslashes within formulas remain unchanged. Includes an output termination tag and prohibits the output of JSON or HTML tags.
[0036] In step S4, when the parser parses the Markdown structured text, it performs the following sub-steps: Retrieve the parser instance based on the template identifier and parser version; Check if a termination marker exists; if not, mark the output as incomplete. Scan the Markdown text according to the heading level declared in the template, and segment the question stem, options, answer, explanation, sub-question and illustration reference into field fragments; Generates an internally structured question object, while retaining the original Markdown, template version, parser version, and exception information.
[0037] Furthermore, the HTML rich text conversion in step S5 includes a formula processing sub-step: Identify inline formulas $$...$ and block-level formulas $$...$$ from Markdown fields, record each formula fragment as a formula object and replace it with a formula placeholder; Perform controlled transformations on Markdown content to generate HTML fragments, allowing only preset security tags to be whitelisted; After completing the HTML security filtering, the formula placeholders will be restored to the formula rendering tags supported by the question bank system.
[0038] Furthermore, after obtaining the Markdown structured text in step S3 and before parsing in step S4, a preprocessing step is also included: cleaning the model output, detecting termination marks, repairing abnormal marks, and filtering illegal content; when a missing termination mark, a missing key title, an unclosed formula mark, or incomplete output content is detected, a retry, local repair, or manual review process is triggered.
[0039] Furthermore, the structured validation in step S6 includes at least one of the following: validation of required fields, validation of the number of options, validation of the range of answers, validation of paired formula tags, validation of the continuity of sub-question levels, validation of illegal HTML tags, and validation of the consistency between the template version and the parser version.
[0040] A multi-disciplinary Markdown structured output, parsing, and rich text conversion system for digitizing paper-based exam papers, used to implement the method described above, the system comprising: The test paper image input module is used to receive images of paper test papers or questions, and output image data and context information. The subject-specific question type routing module, whose input is connected to the output of the test paper image input module, is used to determine the subject and question type of the questions; The template matrix management module is used to maintain a two-dimensional template matrix of subject × question type. Each matrix unit contains prompt word templates and parser identifiers. The prompt word assembly module has its first input end connected to the output end of the subject question type routing module and its second input end connected to the output end of the template matrix management module, and is used to generate complete prompt words; The multimodal large model calling module has its first input end connected to the output end of the prompt word assembly module and its second input end connected to the output end of the test paper image input module, and is used to obtain Markdown structured text. The template binding parser module has its input end connected to the output end of the multimodal large model calling module and is bound to the parser specified in the template matrix management module. It is used to parse Markdown into internal structured question objects. The Markdown to HTML rich text conversion module has its input end connected to the output end of the template binding parser module, and is used to convert Markdown fields into HTML rich text. The structured validation module has its input terminals connected to the output terminals of the template binding parser module and the Markdown to HTML rich text conversion module, respectively, and is used to perform validation. The result output module has its input end connected to the output end of the structured verification module, and is used to output the verified structured objects to the question bank system.
[0041] The Markdown to HTML rich text conversion module embeds a formula placeholder and restoration submodule. This submodule replaces formula fragments with placeholders before Markdown parsing and restores the placeholders to formula rendering tags after HTML security filtering. The template binding parser module includes: a Markdown preprocessing unit for removing wrapping noise and checking termination tags; a field segmentation unit for segmenting field fragments according to the title level agreed upon in the template; and a structured object generation unit for outputting internal structured question objects containing the original Markdown and version information.
[0042] An electronic device includes a processor and a memory, the memory storing a computer program, the processor executing the computer program to implement the method.
[0043] A computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the method.
[0044] Example: Method Example This embodiment provides a method for the structured output, parsing, and rich text conversion of Markdown for multi-disciplinary question types in the digitization of paper-based exam papers.
[0045] Step S1: Receive image and obtain context information
[0046] The system receives scanned copies of paper exam papers, photographed images, or images of questions segmented after layout detection. Simultaneously, it acquires contextual information such as the subject, question type, grade level, and exam paper source. This information can be provided by upstream systems (such as the layout analysis module), manually specified, or automatically identified through a classification model.
[0047] Step S2: Select template and parser
[0048] Based on the subject and question type, the system selects the corresponding prompt word template and its associated parser from a pre-built two-dimensional template matrix of subject × question type. For example, for math multiple-choice questions, the template with template ID "math_choice_v1" is selected, and the parser "MathChoiceMarkdownParser" is bound to it.
[0049] Each matrix cell in a template matrix contains: a subject identifier (e.g., "Mathematics"), a question type identifier (e.g., "Multiple Choice"), output field definitions (question stem, options, answer, explanation, etc.), Markdown heading and field mapping rules, a parser identifier and version number, and validation rules. Template matrices can be implemented using configuration files, databases, or code registry entries.
[0050] For example: Step S3: Assemble prompts and call the model
[0051] Generate complete hints based on the selected template. Hints should include at least: a list of target fields (e.g., question stem, options, answer, explanation, sub-question, reading material, formula, image reference, etc.), Markdown heading hierarchy conventions (level 1 headings represent questions, level 2 headings represent fields, level 3 headings represent sub-questions), option marking conventions (e.g., "- A. …"), formula marking conventions (inline formulas use $$, block-level formulas use $$...$$, LaTeX backslashes within formulas remain unchanged), rich text marking conventions (e.g., bold, underline, center, custom spaces or underlines), and output termination markers (e.g., ...).<!--END_QUESTION--> ), and constraints prohibiting the direct output of JSON or HTML.
[0052] Input the question image and prompts into a multimodal large-scale model (such as the visual language model GPT-4V, LLaVA, etc.) to obtain the model's output Markdown structured text. For example, the model output for a math multiple-choice question would be: text # Question ## Question Stem If $a \ne b$, then the value of $\frac{a^2-b^2}{ab}$ is ( ).
[0053] ## Options - A. $ab$ - B. $a+b$ - C. $a^2+b^2$ - D. $2ab$ ## Answer B ## Analysis Since $a^2 - b^2 = (a + b)(ab)$, and $a \ne b$, therefore: $$ a^2 - b^2 = a + b $$ Therefore, the answer is B.
[0054] <!--END_QUESTION--> .
[0055] Step S4: Preprocessing Preprocessing of the model output includes: cleaning (removing any code block wrappers such as "```markdown" that may have been added to the model) and termination marker detection (confirming the presence of "```markdown" tags.<!--END_QUESTION-->The system includes functions such as error correction (e.g., replacing full-width dollar signs with half-width ones) and filtering illegal content. If a missing termination marker, missing key headings, incomplete formula marks, or obviously incomplete output content is detected, a retry, partial repair, or manual review process will be triggered.
[0056] Step S5: Parse Markdown Invokes the parser bound to the template. The parser converts the Markdown into an internal structured object based on the heading levels, field identifiers, list rules, and formula rules defined in the template version.
[0057] The parser's processing logic is as follows: Retrieve the parser instance based on the template_id and parser_version in the task.
[0058] Perform Markdown preprocessing on the content returned by the model to remove code block wrappers and explanatory prefixes and suffixes.
[0059] Check if a template-defined termination marker exists; if not, mark the output as incomplete.
[0060] The Markdown text is scanned according to the heading hierarchy declared in the template, and the content such as "Question Stem", "Options", "Answer", and "Explanation" is segmented into field fragments. For the options, the option tags and content are further parsed.
[0061] Normalize field fragments, for example, unify option labels to uppercase letters A, B, C, D, and formula symbols to $$...$ or $$...$$.
[0062] Generates an internally structured question object, preserving the original Markdown, template version, parser version, and exception information.
[0063] Taking the math multiple-choice question in this embodiment as an example, the structured object obtained after parsing is as follows: { "template_id": "math_choice_v1", "parser_id": "MathChoiceMarkdownParser", "stem_md": "If $a \\ne b$, then the value of $\\frac{a^2-b^2}{ab}$ is ( ).", "options": [ {"label": "A", "content_md": "$ab$"}, {"label": "B", "content_md": "$a+b$"}, {"label": "C", "content_md": "$a^2+b^2$"}, {"label": "D", "content_md": "$2ab$"} ], "answer": "B", "analysis_md": "Because $a^2-b^2=(a+b)(ab)$, and $a \\ne b$, therefore:\n$$\n\\frac{a^2-b^2}{ab}=a+b\n$$\nSo choose B." "validation_status": "parsed" }
[0064] Step S6: HTML Rich Text Conversion Convert Markdown fields in a structured object to HTML rich text. The conversion process includes: Formula extraction and placeholders: Scan field-level Markdown content, identify inline formulas ($...$ and block-level formulas $$...$$$, record each formula fragment as a formula object, and generate a unique placeholder for each formula (such as "@@FORMULA_001@@"). Replace the formula in the original content with the placeholder.
[0065] Controlled Markdown Parsing: Performs controlled Markdown subset parsing on the placeholder Markdown content to generate HTML fragments. Only predefined whitelisted safe tags are allowed, such as p, strong, em, u, ul, ol, li, table, etc., while script, style, iframe, and inline events are prohibited.
[0066] HTML security filtering: Performs DOM post-processing on the generated HTML fragments, checking tag closures, attribute whitelists, and empty paragraph cleanup, etc.
[0067] Formula restoration: Restore formula placeholders to formula rendering tags supported by the question bank system. In this embodiment, inline formulas are converted to [latex]...[ / latex] tags, and block-level formulas are converted to [latex display="true"]...[ / latex].
[0068] Output encapsulation: The output includes field-level conversion results for field_md, field_html, formula_list, and conversion_status.
[0069] Taking the parsed fields in this embodiment as an example, the converted HTML is: If [latex]a \ne b[ / latex], then the value of [latex]\frac{a^2-b^2}{ab}[ / latex] is ( ). Because a^2 - b^2 = (a + b)(ab) and a ≠ b, therefore: [latex display="true"]\frac{a^2-b^2}{ab}=a+b[ / latex] Therefore, the answer is B. .
[0070] Step S7: Structured Verification Perform validation on the structured question objects and the converted HTML, including: Does the required field exist (question stem, answer, etc.)? Does the number of options in a multiple-choice question meet the requirements of the question type (e.g., 4 options)? Does the answer fall within the range of options? Whether formula symbols appear in pairs; Are the sub-topic levels consecutive? Does the converted HTML contain illegal tags? Are the template version and parser version consistent?
[0071] If the verification passes, proceed to step S8; if it fails, trigger partial repair, retry, or manual review based on the error type.
[0072] Step S8: Input / Output The validated structured object is output to the question bank system. The output object retains the original Markdown text, structured fields, and HTML rich text fields, for example: { "question_id": "...", "stem_md": "...", "stem_html": "...", "options_md": [...], "options_html": [...], "answer": "B", "analysis_md": "...", "analysis_html": "...", "formula_list": [...], "template_version": "math_choice_v1", "parser_version": "1.0", "validation_status": "passed" }
[0073] Example: System Example: This embodiment provides a system for implementing the above method. (Refer to...) Figure 1 The system includes the following modules: Test paper image input module: used to receive scanned copies of paper test papers, photographed images, or question images after page layout detection and segmentation, and output image data and context information.
[0074] Subject-based question type routing module: Its input end is connected to the output end of the test paper image input module, and it is used to determine the subject and question type of the questions based on the source of the test paper, manual configuration, model recognition results or upstream system information, and output the subject and question type identifiers.
[0075] Template Matrix Management Module: Used to maintain a two-dimensional template matrix of subjects and question types. Each matrix cell contains prompt word templates, field definitions, Markdown output protocol, parser identifier, and version number. This module provides interfaces for adding, deleting, modifying, and querying templates.
[0076] The prompt word assembly module has its first input end connected to the output end of the subject question type routing module and its second input end connected to the output end of the template matrix management module. It is used to generate complete prompt words to be sent to the multimodal large model based on the question image, subject question type, field requirements and template content.
[0077] The multimodal large model calling module has its first input end connected to the output end of the prompt word assembly module and its second input end connected to the output end of the test paper image input module. It is used to input the question image and prompt words into the multimodal large model to obtain Markdown structured output.
[0078] The Markdown preprocessing module connects to the output of the multimodal large model calling module at its input end. It is used to clean the model output, detect termination marks, repair abnormal marks, and filter illegal content. If a missing termination mark, missing key headings, unclosed formula marks, or obviously incomplete output content is detected, a retry, partial repair, or manual review process is triggered.
[0079] Template Binding Parser Module: Its input is connected to the output of the Markdown preprocessing module and is bound to the parser specified in the template matrix management module. This module converts Markdown into internal structured question objects based on the template declaration. Specifically, it includes: a Markdown preprocessing unit (for removing wrapping noise and checking termination tags), a field segmentation unit (for segmenting field fragments according to the heading levels agreed upon in the template), a normalization unit (for standardizing option labels and formula markup formats), and a structured object generation unit (for outputting internal structured question objects containing the original Markdown and version information).
[0080] Structured validation module: Its input is connected to the output of the template binding parser module, and it is used to validate field integrity, number of options, formula closure, question number hierarchy, and consistency of answer parsing.
[0081] The Markdown to HTML rich text conversion module connects to the output of the structured validation module at its input end, converting Markdown content such as question stems, options, and explanations into displayable HTML rich text. This module also includes a built-in formula placeholder and restoration submodule, which replaces formula fragments with placeholders before Markdown parsing and restores the placeholders to formula rendering tags after HTML security filtering.
[0082] The output module has its input end connected to the output end of the Markdown to HTML rich text conversion module. It is used to output the question bank object containing the original Markdown text, structured fields, HTML rich text fields, and parsing status.
[0083] The connection relationships between the above modules are as follows: Figure 1 As shown, the data flow is as follows: test paper image → image input module → subject question type routing module + template matrix management module → prompt word assembly module → multimodal large model calling module → Markdown preprocessing module → template binding parser module → structured validation module → Markdown to HTML rich text conversion module → result output module → question bank system.
[0084] The following module names are exemplary names compiled according to this solution; The naming conventions mentioned above are not limited to specific programming languages or class names. Actual systems can be implemented using services, functions, classes, configuration tables, or database records, as long as they can accomplish the same template selection, Markdown output, formula placeholders, structured parsing, HTML conversion, and validation / database entry processes; all fall under the scope of this solution.
[0085] Example: Specific application scenario: The following example, a multiple-choice question from a math exam, illustrates the complete workflow of this invention.
[0086] Input: A slice of a multiple-choice question from a scanned copy of a paper exam paper. The image contains the question stem "If a≠b, then the value of (a²-b²) / (ab) is ( )", and four options: A.a-b, B.a+b, C.a²+b², and D.2a-b.
[0087] Processing procedure: The subject-based question routing module identifies the question as a "mathematics-multiple choice question" and selects the template "math_choice_v1" and the parser "MathChoiceMarkdownParser" from the template matrix.
[0088] The prompt assembly module generates prompts, requiring the model to output them in the following format: First-level heading "# Question", second-level headings "## Question Stem", "## Options", "## Answer", "## Explanation", options in "- A. …", formulas in $$, and ending with "<!--END_QUESTION--> "Finish.
[0089] The multimodal large model calling module inputs the image and prompt words into the visual language model, and the model returns the Markdown text as shown in step S3.
[0090] The Markdown preprocessing module checks for the presence of termination tags, formula closing, and no exceptions, then outputs the cleaned text.
[0091] The template binding parser module parses Markdown and generates structured objects.
[0092] Structured validation module validation: The question stem is not empty, there are 4 options, the answer "B" is within the range of options, the formulas are paired, and the validation passes.
[0093] The Markdown to HTML rich text conversion module performs formula placeholders and conversions to generate HTML rich text.
[0094] The output module stores the structured objects and HTML in the database.
[0095] Output: A new question is added to the question bank system, including editable Markdown text, displayable HTML rich text, formula list and other metadata.
[0096] Example: Detailed implementation of formula processing For problems containing formulas, this embodiment provides a preferred formula processing method.
[0097] First, define formula marking conventions in the template: inline formulas use $...$, block-level formulas use $$...$$, LaTeX backslashes inside formulas are output as single backslashes, and the model does not perform JSON string escaping.
[0098] Secondly, before HTML conversion, the system extracts formulas from each Markdown field. The extraction algorithm uses regular expressions to match $$ and $$...$$, but nesting and escaping issues need to be considered. Each extracted formula generates a unique ID and records the formula type (inline / block), source LaTeX string, and position offset.
[0099] Next, replace the formulas in the original field content with placeholders, such as "@@FORMULA_001@@". The placeholders should be designed to avoid conflicting with normal Markdown text and to facilitate subsequent recovery.
[0100] Next, the placeholder Markdown content is parsed using standard Markdown parsing (e.g., using libraries like markdown-it or marked), generating HTML. Since formulas have been replaced by placeholders, the Markdown parser will not incorrectly parse special characters such as underscores and asterisks in the formulas.
[0101] Next, perform security filtering on the generated HTML. Libraries such as DOMPurify can be used to configure whitelisted tags and attributes, removing all scripts and dangerous content.
[0102] Finally, iterate through the text nodes in the HTML, replacing placeholders with formula rendering tags. For example, replace "@@FORMULA_001@@" with... [latex]...[ / latex] Alternatively, it can be directly output in the format required by the front-end formula rendering component.
[0103] In this way, both the formula boundaries are protected and a safe and stable rich text conversion is achieved.
[0104] The following example is a de-identification example, used to demonstrate the complete chain of this solution from model Markdown output to structured fields and HTML rich text.
[0105] Input conditions: Input source: Screenshot of a single question from a paper exam paper Subject: Mathematics Question type: Multiple choice Template number: math_choice_v1 Parser ID: MathChoiceMarkdownParser Does it contain formulas? Yes Does it include illustrations: No Markdown output of multimodal large models based on templates: # Question ## Question Stem If $a \ne b$, then the value of $\frac{a^2-b^2}{ab}$ is ( ).
[0106] ## Options - A. $ab$ - B. $a+b$ - C. $a^2+b^2$ - D. $2ab$ ## Answer B ## Analysis Since $a^2 - b^2 = (a + b)(ab)$, and $a \ne b$, therefore: $$ a^2 - b^2 = a + b $$ Therefore, the answer is B.
[0107] <!--END_QUESTION--> Field fragments after formula placeholders: Question: If @@FORMULA_001@@, then the value of @@FORMULA_002@@ is ( ).
[0108] Option B: @@FORMULA_004@@ Analysis: Because @@FORMULA_007@@ and @@FORMULA_008@@, therefore: @@FORMULA_009@@. Hence, the answer is B.
[0109] The parsed structured object: { "template_id": "math_choice_v1", "parser_id": "MathChoiceMarkdownParser", "stem_md": "If $a \\ne b$, then the value of $\\frac{a^2-b^2}{ab}$ is ( ).", "options": [ {"label": "A", "content_md": "$ab$"}, {"label": "B", "content_md": "$a+b$"}, {"label": "C", "content_md": "$a^2+b^2$"}, {"label": "D", "content_md": "$2ab$"} ], "answer": "B", "analysis_md": "Because $a^2-b^2=(a+b)(ab)$, and $a \\ne b$, therefore: \\n$$\\n\\frac{a^2-b^2}{ab}=a+b\\n$$\\n, so the answer is B." "formula_count": 9, "validation_status": "passed" } Transformed field-level HTML: If [latex]a \ne b[ / latex], then [latex]\frac{a^2-b^2}{ab}[ / latex] The value is ( ). Because [latex]a^2-b^2=(a+b)(ab)[ / latex], And [latex]a \ne b[ / latex], therefore: [latex]\frac{a^2-b^2}{ab}=a+b[ / latex] Therefore, the answer is B. This example demonstrates the complete technical chain of this solution: the model side does not output JSON or HTML, the backend first performs placeholders and validation on the formulas, then parses the structured fields according to the template, and finally generates secure HTML by field, while retaining the original Markdown text for review and rollback.
[0110] Example: Template-parser binding and version management This embodiment details the template matrix and binding mechanism.
[0111] Here is a specific configuration example (in JSON format) of the template matrix: { "template_id": "math_choice_v1", "subject": "mathematics", "question_type": "Multiple choice question", "field_schema": ["question stem", "options", "answer", "explanation"], "markdown_protocol": { "title_level": "First-level headings represent titles, second-level headings represent fields", "option_rule": "- A. Option content", "formula_rule": "$...$ or $$...$$", "end_marker": "<!--END_QUESTION--> " }, "parser_id": "MathChoiceMarkdownParser", "parser_version": "1.0", "validator_rules": ["Required field validation", "Number of options validation", "Formula closure validation"] "html_mapping_rules": ["Formula placeholders", "List mappings", "Table mappings", "Security label filtering", "Formula markup restoration"] }
[0112] When a template needs updating (e.g., adding a new field "knowledge point"), the developers create a new version "math_choice_v2" and simultaneously update the parser version "MathChoiceMarkdownParser v1.1". This parser declares support for both "math_choice_v1" and "math_choice_v2". When processing a question, the system automatically calls the corresponding parser based on the template version specified in the question task. Simultaneously, the system records the template version, parser version, and model version for each question, facilitating problem backtracking.
[0113] To avoid parsing failures due to changes in prompt words, this solution binds the prompt word template to the parser: 1. Each template has a unique template number and version number, such as `math_choice_v1`.
[0114] 2. Specify a unique or default parser for each template, such as `MathChoiceMarkdownParser`.
[0115] 3. The parser declares the range of template versions it supports.
[0116] 4. When the template changes, update the parser or add a new parser version.
[0117] 5. The system records the template version, parser version, and model version when processing each question, which facilitates problem backtracking.
[0118] This mechanism enables the prompt words and program parsing rules to form a complete structured extraction unit, rather than relying on the model's free output in isolation.
[0119] In one specific implementation, the parser can operate according to the following processing logic: 1. Obtain the parser instance based on the `template_id` and `parser_version` in the task.
[0120] 2. Perform Markdown preprocessing on the model's returned content to remove code block wrapping, whitespace noise, and model interpretability prefixes and suffixes.
[0121] 3. Check if a template-defined termination marker exists; if not, mark it as incomplete output.
[0122] 4. Scan the Markdown text according to the heading levels declared in the template, and segment the content such as the question stem, options, answers, explanations, sub-questions, and illustration references into field fragments.
[0123] 5. Normalize field fragments, for example, unify option labels to A, B, C, D, and formula symbols to `$...$` or `$$...$$`.
[0124] 6. Perform validations on the parsed results, including field integrity, formula closure, number of options, answer range, and image reference validity.
[0125] 7. Generate internal structured question objects, and retain the original Markdown, template version, parser version, and exception information.
[0126] If the parser detects inconsistent template versions, missing key fields, incomplete formulas, or illegal tags in the HTML conversion results, the system will not directly insert the data into the database, but will instead proceed to a partial retry, rule repair, or manual review process.
[0127] Example: Preprocessing and Anomaly Handling This example illustrates the handling strategy when the model output is incomplete or has an incorrect format.
[0128] Scenario 1: The model output is missing a termination marker. The preprocessing module detected the absence of a termination marker.<!--END_QUESTION-->If the system detects an incomplete output, it will send the currently output content along with the prompt to the model, requesting the model to complete only the missing parts (e.g., "Please continue outputting the remaining content and end with the termination marker"). If the system fails after two retries, the question will be marked as "requires manual review" and moved to the manual review queue.
[0129] Scenario 2: The formula markers in the model output are not closed, for example, there is only one $ without a matching $. The preprocessing module attempts to automatically fix this: after detecting the inline formula start character, it searches for the next $. If it is found within a reasonable distance, it completes the formula; otherwise, it treats the entire suspicious content as plain text and records a warning. The fixed content then enters the parser.
[0130] Scenario 3: The parser detects a missing key field (such as "question stem"). Instead of directly reporting an error, the system infers the missing field based on the default value defined in the template or from other fields (e.g., if the model included the question stem in the "parse" field, it attempts to migrate the data using rules). If this cannot be fixed, the system proceeds to manual review.
[0131] Example: Markdown to HTML Rich Text Conversion Mechanism The Markdown to HTML conversion in this solution is not a simple display conversion, but a controlled conversion for the storage of educational assets. Its features include: 1. Only allow a subset of Markdown supported by the question bank system, and disable scripts, inline events, untrusted external links, etc.
[0132] 2. The formula content is checked for boundaries before conversion to avoid incorrect truncation of LaTeX.
[0133] 3. Establish stable mappings for commonly used teaching formats such as spaces, underlines, fill lines, centering, and tables.
[0134] 4. Perform security filtering and field-level storage on HTML results, so that the question stem, options, and explanations can be displayed and edited separately.
[0135] 5. Retain the original Markdown text for secondary editing and rollback in case of conversion failure.
[0136] In one optional implementation, the Markdown to HTML rich text conversion module can employ a processing flow of "field-level conversion, formula placeholders, security whitelisting, and post-processing recovery," instead of directly converting the entire question as a single large string. This flow is used to illustrate the engineering implementation methods supported by this solution and does not require a real system to adopt all of the following steps: 1. Field-level input: The parser first breaks down the question stem, options, answer, explanation, reading material, sub-questions, illustration references, etc., into independent Markdown fields.
[0137] 2. Formula placeholders: In implementations that require protection of formula boundaries, the formula processing module can be called to replace the formula fragments `$...$` and `$$...$$` with placeholders and record the formula object.
[0138] 3. Markdown Lexical Analysis: Performs Markdown parsing on field content, generates intermediate tokens or abstract syntax trees, and identifies nodes such as headings, paragraphs, lists, tables, bold, italics, code, and quotations.
[0139] 4. Controlled Node Filtering: In implementations using security whitelists, only business-supported node types are allowed to enter the HTML generation process, such as `p`, `strong`, `em`, `u`, `ul`, `ol`, `li`, `table`, `thead`, `tbody`, `tr`, `td`, `th`, `br`, `span`, and `div`; while `script`, `style`, `iframe`, inline events, and untrusted links are prohibited.
[0140] 5. Custom tag mapping: Map commonly used tags in teaching scenarios to business HTML, such as fill-in-the-blank lines, center alignment, indentation, underline, question numbers, image references, and table styles.
[0141] 6. HTML Generation: Generate HTML fragments by field and record the source field and transformation status for each fragment.
[0142] 7. DOM Post-processing: In implementations that require further assurance of HTML stability, tag closure checks, attribute whitelist filtering, empty paragraph cleanup, nested list repair, and table column consistency checks can be performed on HTML fragments.
[0143] 8. Formula Restoration: In implementations using formula placeholders, the formula placeholders can be replaced with formula rendering markers supported by the question bank system; in one implementation of this system, the model side outputs `$...$` or `$$...$$`, and the program side converts it to `[latex]...[ / latex]`.
[0144] 9. Output encapsulation: It can output fields such as `field_md`, `field_html`, `formula_list`, `image_refs`, `conversion_status`, and `error_messages`; the actual field names, HTML tag formats, and formula markup formats are subject to the specific system implementation.
[0145] The data flow of the conversion module can be represented as: Field-level Markdown Formula extraction and placeholders ->Markdown token / AST parsing -> Business whitelist filtering -> HTML fragment generation -> DOM-safe post-processing -> Restore formula markers -> Field-level HTML + Formula List + Transition Status The following is an example of a field-level conversion result. The `[latex]...[ / latex]` in the following JSON represents a formula encapsulation method used in this system. The actual field naming can use the existing format `difficulty_and_knowledge_builder`: { "field": "analysis", "source_md": "From the difference of squares formula $a^2-b^2=(a+b)(ab)$, we can obtain the result as $a+b$." "html": " From the difference of squares formula [latex]a^2-b^2=(a+b)(ab)[ / latex], we can obtain <strong> The result is [latex]a+b[ / latex]< / strong> . ", "formula_list": ["FORMULA_001", "FORMULA_002"], "conversion_status": "passed" } For Markdown syntax not supported by the question bank system, the conversion module does not discard the original text directly, but processes it according to the following strategy: 1. If it can be mapped to an existing business style, convert it to a controlled HTML tag.
[0146] 2. If mapping is not possible but does not affect the meaning of the question, then keep it as plain text and record the reason for downgrading.
[0147] 3. If the conversion may affect the formula, answer, options, or question structure, it will be marked as a conversion failure and will be subject to manual review.
[0148] 4. If untrusted HTML or script content is found, filter the content and log the security interception event.
[0149] The aforementioned optional conversion mechanism distinguishes this solution from the solution that "directly outputs HTML from large models": large models only need to output stable Markdown, while HTML tag closing, security filtering, formula markup restoration, and business style unification can be completed by the program side according to the actual system capabilities.
[0150] Example: A complete example of a mathematical problem containing formulas The following example is a de-identification example, used to demonstrate the complete chain of this solution from model Markdown output to structured fields and HTML rich text.
[0151] Input conditions: Input source: Screenshot of a single question from a paper exam paper Subject: Mathematics Question type: Multiple choice Template number: math_choice_v1 Parser ID: MathChoiceMarkdownParser Does it contain formulas? Yes Does it include illustrations: No Markdown output of multimodal large models based on templates: # Question ## Question Stem If $a \ne b$, then the value of $\frac{a^2-b^2}{ab}$ is ( ).
[0152] ## Options - A. $ab$ - B. $a+b$ - C. $a^2+b^2$ - D. $2ab$ ## Answer B ## Analysis Since $a^2 - b^2 = (a + b)(ab)$, and $a \ne b$, therefore: $$ a^2 - b^2 = a + b $$ Therefore, the answer is B.
[0153] <!--END_QUESTION--> Field fragments after formula placeholders: Question: If @@FORMULA_001@@, then the value of @@FORMULA_002@@ is ( ).
[0154] Option B: @@FORMULA_004@@ Analysis: Because @@FORMULA_007@@ and @@FORMULA_008@@, therefore: @@FORMULA_009@@. Hence, the answer is B.
[0155] The parsed structured object: { "template_id": "math_choice_v1", "parser_id": "MathChoiceMarkdownParser", "stem_md": "If $a \\ne b$, then the value of $\\frac{a^2-b^2}{ab}$ is ( ).", "options": [ {"label": "A", "content_md": "$ab$"}, {"label": "B", "content_md": "$a+b$"}, {"label": "C", "content_md": "$a^2+b^2$"}, {"label": "D", "content_md": "$2ab$"} ], "answer": "B", "analysis_md": "Because $a^2-b^2=(a+b)(ab)$, and $a \\ne b$, therefore: \\n$$\\n\\frac{a^2-b^2}{ab}=a+b\\n$$\\n, so the answer is B." "formula_count": 9, "validation_status": "passed" } Transformed field-level HTML: If [latex]a \ne b[ / latex], then [latex]\frac{a^2-b^2}{ab}[ / latex] The value is ( ). Because [latex]a^2-b^2=(a+b)(ab)[ / latex], And [latex]a \ne b[ / latex], therefore: [latex]\frac{a^2-b^2}{ab}=a+b[ / latex] Therefore, the answer is B. This example demonstrates the complete technical chain of this solution: the model side does not output JSON or HTML, the backend first performs placeholders and validation on the formulas, then parses the structured fields according to the template, and finally generates secure HTML by field, while retaining the original Markdown text for review and rollback.
[0156] Example: Comparison of direct JSON / HTML output failure: The following are examples of anonymization based on the identified problem types in the project, used to illustrate the typical failure mechanism of the old solution.
[0157] Example of failure 1: Backslashes in formulas result in an invalid JSON string.
[0158] { "stem": "Calculate the value of \frac{a^2-b^2}{ab}", Analysis: The answer can be obtained from the equation a² - b² = a + b. } In the above output, LaTeX backslash sequences such as `\frac` and `\b` may be recognized as illegal escape or control characters by the JSON parser, resulting in a `JSONDecodeError`. If converted to Markdown output, the formula can be expressed as: ## Question Stem Calculate the value of $\frac{a^2-b^2}{ab}$.
[0159] ## Analysis The answer can be obtained from $\frac{a^2-b^2}{ab}=a+b$.
[0160] Example of failure 2: Direct JSON output with unclosed parentheses or quotes.
[0161] { "stem": "Given the function $f(x)=x^2-2x+1$, find $f(3)$", "options": [ {"label": "A", "content": "$2$"}, {"label": "B", "content": "$3$"}, {"label": "C", "content": "$4$"} ], "answer": "C", "analysis": "$f(3)=3^2-2\times3+1=4$, therefore the answer is C". The output is missing a string closing quote and an object closing character, making it unparseable by the backend. The Markdown solution uses headings and closing tags to determine output completeness; even if a field is long, it can be validated and partially padded by field segment.
[0162] Example of failure 3: Direct HTML output shows a nested tag error.
[0163] Depend on <strong>$a^2-b^2=(a+b)(ab)$ possible \frac{a^2-b^2}{ab} < / strong> The above HTML has issues such as unclosed tags, incorrect nesting order, and unclear formula boundaries. In the Markdown solution, the model only outputs lightweight tags such as `**bold**` and `$...$`, while tag closing, security filtering, and formula markup restoration are handled uniformly by the program.
[0164] Example: Formula expression, verification, and conversion mechanism Formula processing in the digitization of paper exam papers is a key technical detail that distinguishes this solution from ordinary document structure extraction. Mathematics, physics, chemistry, and other subjects frequently contain fractions, radicals, subscripts and superscripts, matrices, systems of equations, chemical formulas, reaction conditions, unit symbols, and graphical variables. If a large multimodal model is required to directly output JSON, LaTeX commands such as `\frac`, `\sqrt`, `\times`, and `\begin{cases}` in the formulas will be coupled with JSON string escaping rules, leading to incorrect backslash counts, incomplete string closures, or parsing failures. This solution uses Markdown natively to carry formulas, with the backend program handling formula recognition, validation, and rich text conversion.
[0165] In one specific implementation, formula processing includes at least the following steps: 1. Template Constraints: The prompt word template requires the model to use only two types of formula boundaries: inline formulas use `$...$`, and block-level formulas use `$$...$$`. The LaTeX text inside the formula is not JSON-escaped.
[0166] 2. Formula Extraction: The Markdown preprocessing module scans field content, identifies inline formulas, block-level formulas, and multi-line formula environments, and records each formula fragment as a formula object.
[0167] 3. Placeholder Replacement: Before normal Markdown parsing, replace formula fragments with placeholders in the form of `@@FORMULA_001@@` to prevent the Markdown parser from mistakenly parsing underscores, asterisks, angle brackets, etc. in the formula as ordinary format.
[0168] 4. Formula validation: Check if formula boundaries appear in pairs, check if block-level formulas are fully closed, check if brackets in common LaTeX commands are balanced, and check if HTML scripts or untrusted tags are mixed into the formula.
[0169] 5. Normalization processing: Normalize the full-width dollar signs, consecutive spaces, incorrect line breaks, etc. that the model may output; minor issues that can be fixed are marked for automatic repair, and issues that cannot be fixed are subject to manual review.
[0170] 6. HTML Restoration: After the Markdown content has been converted to HTML and security filtered, the formula placeholders are restored to the formula rendering tags supported by the question bank system. For example, the LaTeX content in `$...$` or `$$...$$` is converted to `[latex]...[ / latex]` format, or it is preserved as a field that can be recognized by other front-end formula rendering components.
[0171] 7. Preservation of original text: The structured object simultaneously saves the original LaTeX text of the formula, the formula location, the formula type, and the converted HTML fragment, which is convenient for rollback display or manual correction when the front-end rendering fails.
[0172] The data structure of a formula object can be represented as follows: { "formula_id": "FORMULA_001", "field": "stem_md", "formula_type": "inline", "source_latex": "\\frac{a^2-b^2}{ab}=a+b", "placeholder": "@@FORMULA_001@@", "validation_status": "passed", "render_markup": "[latex]\\frac{a^2-b^2}{ab}=a+b[ / latex]" } Taking a math problem as an example, the Markdown output by the model can be: ## Question Stem If $a \ne b$, simplify: $$ \frac{a^2-b^2}{ab} $$ ## Analysis Using the difference of squares formula $a^2-b^2=(a+b)(ab)$, we can obtain the result $a+b$.
[0173] Before conversion, the system extracts three formula fragments and temporarily converts the main text into: If @@FORMULA_001@@, simplify: @@FORMULA_002@@ Using the difference of squares formula, we can obtain the result as @@FORMULA_003@@.
[0174] After completing the secure conversion from Markdown to HTML, the placeholders are restored to formula rendering nodes. This method eliminates the need for complex JSON escaping in the model output and avoids directly generating HTML formula tags, allowing the program to reliably control formula boundaries, formula fields, and the final display format.
[0175] This invention can be widely applied in the field of educational informatization, such as converting scanned copies of paper test papers, exercise books, homework sheets, and supplementary teaching materials into structured questions in a question bank system. The method and system of this invention have been deployed in actual projects, processing more than 3,000 sets of test papers and 100,000 questions, covering multiple subjects such as Chinese, mathematics, English, humanities, and science, proving its industrial applicability and stability.
[0176] The above description is only a preferred embodiment of the present invention. It should be noted that those skilled in the art can make several changes and improvements without departing from the overall concept of the present invention, and these should also be considered within the scope of protection of the present invention.
Claims
1. A method for Markdown structured output, parsing, and rich text conversion of multi-disciplinary question types for digitizing paper-based exam papers, characterized by: Includes the following steps: S1: Receive images of paper exam papers or questions, and obtain information on the subject and question type of the questions; S2: Based on the subject and question type, select the corresponding prompt word template and parser from the pre-constructed subject × question type template matrix; wherein, the prompt word template specifies the output protocol that guides the multimodal large model output to conform to the preset Markdown structure, and the parser is used to parse the preset Markdown structure into structured question objects; S3: Generate complete prompts based on the selected prompt template, input the title image and the complete prompts into the multimodal large model, and obtain the Markdown structured text output by the multimodal large model; S4: Invoke the parser bound to the prompt word template to parse the Markdown structured text and generate an internal structured question object; S5: Perform HTML rich text conversion on the Markdown fields in the structured question object to obtain field-level HTML rich text; S6: Perform structured validation on the structured question object and the field-level HTML rich text, and output the validation result to the question bank system.
2. The method according to claim 1, characterized in that: Each matrix unit in the subject × question type two-dimensional template matrix includes a subject identifier, question type identifier, output field definition, Markdown title and field mapping rules, example input and output, parser name and version number, and validation rules; each matrix unit corresponds to a unique template number and version number.
3. The method according to claim 1, characterized in that: Each matrix unit of the subject × question type template matrix includes at least: subject identifier, question type identifier, output field definition, Markdown title and field mapping rules, parser identifier, and version number; the output protocol includes: Use Markdown heading levels to represent the question structure, with first-level headings representing questions and second-level headings representing fields; Options are represented using Markdown lists, with option markers in the form of -A. and -B.; Use $...$ to represent inline formulas, and $$...$$ to represent block-level formulas. LaTeX backslashes within formulas remain unchanged. Includes an output termination tag and prohibits the output of JSON or HTML tags.
4. The method for Markdown structured output, parsing, and rich text conversion of multi-disciplinary question types for digitizing paper-based exam papers according to claim 1, characterized in that: In step S4, when the parser parses the Markdown structured text, it performs the following sub-steps: Obtain the parser instance based on the template identifier and parser version; Check if a termination marker exists; if not, mark the output as incomplete. Scan the Markdown text according to the heading level declared in the template, and segment the question stem, options, answer, explanation, sub-question and illustration reference into field fragments; Generates an internally structured question object, while retaining the original Markdown, template version, parser version, and exception information.
5. The method for multi-disciplinary Markdown structured output, parsing, and rich text conversion of paper-based exam papers according to claim 1, characterized in that: The HTML rich text conversion in step S5 includes a formula processing sub-step: Identify inline formulas $$...$ and block-level formulas $$...$$ from Markdown fields, record each formula fragment as a formula object and replace it with a formula placeholder; Perform controlled transformations on Markdown content to generate HTML fragments, allowing only preset security tags to be whitelisted; After completing the HTML security filtering, the formula placeholders will be restored to the formula rendering tags supported by the question bank system.
6. The method for Markdown structured output, parsing, and rich text conversion of multi-disciplinary question types for digitizing paper-based exam papers according to claim 1, characterized in that: After obtaining the Markdown structured text in step S3 and before parsing in step S4, a preprocessing step is also included: cleaning the model output, detecting termination marks, repairing abnormal marks, and filtering illegal content; when a missing termination mark, a missing key title, an unclosed formula mark, or incomplete output content is detected, a retry, partial repair, or manual review process is triggered.
7. The method according to claim 1, characterized in that: The structured validation in step S6 includes at least one of the following: validation of required fields, validation of the number of options, validation of the range of answers, validation of paired formula tags, validation of the continuity of sub-question levels, validation of illegal HTML tags, and validation of the consistency between the template version and the parser version.
8. A multi-disciplinary Markdown structured output, parsing, and rich text conversion system for digitizing paper-based exam papers, characterized by: The system for implementing the method of any one of claims 1 to 7 comprises: The test paper image input module is used to receive images of paper test papers or questions, and output image data and context information. The subject-specific question type routing module, whose input is connected to the output of the test paper image input module, is used to determine the subject and question type of the questions; The template matrix management module is used to maintain a two-dimensional template matrix of subject × question type. Each matrix unit contains prompt word templates and parser identifiers. The prompt word assembly module has its first input end connected to the output end of the subject question type routing module and its second input end connected to the output end of the template matrix management module, and is used to generate complete prompt words; The multimodal large model calling module has its first input end connected to the output end of the prompt word assembly module and its second input end connected to the output end of the test paper image input module, and is used to obtain Markdown structured text. The template binding parser module has its input end connected to the output end of the multimodal large model calling module and is bound to the parser specified in the template matrix management module. It is used to parse Markdown into internal structured question objects. The Markdown to HTML rich text conversion module has its input end connected to the output end of the template binding parser module, and is used to convert Markdown fields into HTML rich text. The structured validation module has its input terminals connected to the output terminals of the template binding parser module and the Markdown to HTML rich text conversion module, respectively, and is used to perform validation. The result output module has its input end connected to the output end of the structured verification module, and is used to output the verified structured objects to the question bank system.
9. The Markdown structured output, parsing, and rich text conversion system for multi-disciplinary question types digitization of paper-based exam papers as described in claim 8, characterized in that: The Markdown to HTML rich text conversion module has an embedded formula placeholder and restoration submodule. The formula placeholder and restoration submodule is used to replace formula fragments with placeholders before Markdown parsing and restore the placeholders to formula rendering marks after HTML security filtering. The template binding parser module includes: a Markdown preprocessing unit for removing wrapping noise and checking termination markers; a field segmentation unit for segmenting field fragments according to the title level agreed upon in the template; and a structured object generation unit for outputting an internal structured title object containing the original Markdown and version information.
10. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by a processor, it implements the method of any one of claims 1 to 7.
Citation Information
Patent Citations
Efficient visual document analysis and understanding method
CN121768021A
Structured data analysis method, electronic equipment and storage medium
CN121835650A
Multi-format document analysis and verification method, system and program product
CN121859835A
