A method and system for automatic filling of local forms
By converting tabular data into a hierarchical JSON key-value pair structure, using a vector database and a lightweight language to generate a model to populate the data, and mapping it to the target location via VBA macros, the system solves the accuracy and flexibility problems of existing systems in filling out complex forms, and achieves intelligent data allocation and data security.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- JISHOU UNIVERSITY
- Filing Date
- 2025-02-13
- Publication Date
- 2026-05-01
AI Technical Summary
Existing automated form filling systems lack accuracy and flexibility when handling complex and diverse forms, making it difficult to achieve fast and intelligent data allocation, and also pose information security risks.
By converting tabular data into a hierarchical JSON key-value pair structure, vector database retrieval and a lightweight language generation model are used to fill in the missing data. VBA macros are then used to map the filled tabular data to the target location, combining enhanced generation technology and language models for intelligent data filling.
It achieves high efficiency, accuracy, and intelligence in automatic form filling, ensures data security, adapts to complex data filling needs, improves the flexibility and accuracy of filling, and reduces the risk of data leakage.
Smart Images

Figure CN120106026B_ABST
Abstract
Description
A method and system for automatically filling in local forms Technical Field
[0001] This invention relates to the field of natural language processing technology, and in particular to a method and system for automatically filling in local forms. Background Technology
[0002] With the rapid development of large language model technology, automated applications based on natural language processing are widely used in information processing, data filling, and other fields. Retrieval-Augmented Generation (RAG) combines retrieval and generation techniques, enabling large language models to obtain relevant information from external data sources when generating content, thus improving the accuracy and contextual relevance of data processing. Automatic form filling systems based on large language models and RAG technology have significant advantages, especially in data-intensive and repetitive filling tasks. Contextual Learning (ICL) based on large language model prompt word engineering has demonstrated unprecedented natural language understanding and reasoning capabilities in various scenarios, and it also shows impressive performance in form applications. In particular, a strategy called "minimum to maximum prompts" is proposed, which decomposes complex problems into smaller problems, gradually guiding the model to reason and solve them. This strategy combines COT (Content-Oriented Thinking) technology, presenting the problem-solving process as a coherent thought chain, thereby improving the model's accuracy and robustness in solving complex tasks.
[0003] In many applications, users frequently need to fill out structured forms or reports, such as financial reports and government documents. However, traditional form-filling methods rely on manual operation, resulting in low efficiency and a high risk of errors. To address this, automated form-filling systems have emerged. These systems use specific code to quickly fill in data in forms, but they still have limitations in supporting complex formats, information accuracy, and data allocation. For example, traditional automated form-filling systems typically rely on fixed templates and rules, and have limited ability to handle variations in form formats and complex layouts, making it difficult to meet diverse practical needs. Existing text generation technologies based on large language models (LLMs) are mainly used for free text generation or simple fill-in-the-blank tasks. They rely on pre-trained models and large amounts of contextual training data to complete data filling by predicting and generating text. However, this method has limitations when dealing with structured tables, especially when the table format is complex and requires accurate filling. LLM models struggle to fill in the forms efficiently and accurately, lack retrieval functions, and rely on the model's own training data for filling, which can easily lead to inaccurate information. Simulating mouse movement is too slow and occupies the user's workspace, preventing mouse movement. Data protection is poor, as data needs to be uploaded to the cloud or server, making user data vulnerable to leakage. Most existing autofill tools use rule-based automation scripts to automatically fill in forms according to user-preset formats and templates. This method is widely used for filling large batches of fixed-format forms, especially suitable for standardized and simple data input scenarios. However, it relies on fixed rule sets and is difficult to handle forms with varying formats or non-standardized forms. Even with autofill tools, they are only designed for a specific type of form and lack NLP capabilities, making it difficult to understand the forms and troubleshoot errors. Therefore, there is an urgent need to propose a local form autofill method and system to solve the technical problems of how to accurately and quickly autofill forms and achieve intelligent data allocation. Summary of the Invention
[0004] The main objective of this invention is to propose a local form autofill method and system, which aims to solve the technical problem of how to accurately and quickly autofill forms and achieve intelligent data allocation.
[0005] To achieve the above objectives, the present invention provides a method for automatically filling in local forms, wherein the method includes the following steps:
[0006] S1. Select the table area to be filled in, convert the table data in the table area into a first format, and convert the table data in the first format into a hierarchical JSON key-value pair structure;
[0007] S2. Split the data in the hierarchical JSON key-value pair structure according to the data object, retrieve and supplement it through the vector database, and call the filling model to fill the missing data in the table area of the first format.
[0008] S3. Convert the first format table to a second format table, and map the data of the second format table to the corresponding target position in the table area to be filled, thereby completing the automatic filling of the table.
[0009] In one preferred embodiment, step S1 involves selecting the table area to be filled and converting the table data within that area into a first format, specifically as follows:
[0010] Select the table area to be filled in, start the table macro detection, determine whether the table area belongs to the table range of the document, and save the table position information to a text file;
[0011] Read the table position information saved in the text file, and use the Pandoc library to convert the table data in the selected table area into HTML format.
[0012] In one preferred embodiment, before converting the tabular data of the first format into a hierarchical JSON key-value pair structure, the method further includes: a preprocessing operation for the form to be filled, specifically:
[0013] Extract all elements from the first format table and store them as a table list;
[0014] By extracting the table serial number, the table to be operated on is located, the data is cleaned, extra line breaks in the cells are removed, and the line breaks are replaced with line break markers or placeholders;
[0015] Find cell labels and convert them, load an external dictionary file, and replace the content of the cell with the external dictionary file;
[0016] Replace blank cells in the first format table with blank placeholders.
[0017] In one preferred embodiment, step S1 converts the tabular data in the first format into a hierarchical JSON key-value pair structure, specifically as follows:
[0018] Initialize the OpenAI API client and set the URL and API key;
[0019] Call the interface, set the randomness of the population model to 0, and call the population model to convert the first format table into a hierarchical JSON format. Each data cell of the first format table is converted into a key-value pair with a hierarchical relationship.
[0020] One preferred embodiment is that the filling model is the GPT-4o model.
[0021] One preferred embodiment, step S2, specifically includes:
[0022] The data in the hierarchical JSON key-value pair structure is split into multiple documents according to the data object, and vector embeddings are generated for the split documents;
[0023] Create a vector database based on document chunking and embedding, specifying the name and ID of the vector storage collection;
[0024] A retrieval-based question-and-answer chain is constructed. Based on the prompts entered by the user, a search is performed in the vector database to obtain the search results. Then, a filling model is called to fill in the missing data in the first-format table area.
[0025] In one preferred embodiment, after step S2, the method further includes:
[0026] Data not present in the vector database during the filling process of the first-format table is extracted using a lightweight language generation model; special prompt words are set, and the lightweight language generation model filters out unknown data with empty values in the first-format table area and the parent structure of the unknown data, and outputs the filtered first-format table data to a specified text file in append mode; the user updates the vector database according to the text file.
[0027] One preferred embodiment is that updating the vector database includes:
[0028] The target vector is merged by searching for existing documents in the vector database by ID according to the path of the storage vector database file. The content and metadata of the documents are extracted, new content is read from the documents and concatenated with the existing content to form a new feature vector. At the same time, the metadata is updated, source information is appended, a new document object is constructed, and the merged content and metadata are stored.
[0029] Alternatively, you can directly add new feature vectors, read new document content, define metadata, mark the source as a file, use a document class to combine the read text content with the metadata to generate a new document object, set an ID, and add the new document object and its corresponding ID to the vector database using the document object addition method.
[0030] One preferred embodiment, step S3, specifically includes:
[0031] The Pandoc library is used to convert a completed HTML table into a Word table, and VBA macros are used to map the contents of the Word table to the corresponding target positions in the table area to be filled, thus completing the automatic filling of the table.
[0032] A system including the aforementioned local form autofill method includes a format conversion module, a database retrieval module, a data missing identification module, and a table format restoration module connected in sequence.
[0033] The format conversion module is used to convert the table data in the table area into a first format, and convert the table data in the first format into a hierarchical JSON key-value pair structure;
[0034] The database retrieval module is used to retrieve supplementary data from the vector database and call the filling model to fill in the missing data in the table area of the first format.
[0035] The missing data identification module is used to extract missing data, generate a text file, and update the vector database.
[0036] The table format restoration module is used to convert the first format table to a second format table, and map the second format table data to the corresponding target position in the table area to be filled.
[0037] In the above technical solution of the present invention, the local form automatic filling method includes the following steps: selecting a form area to be filled, converting the form data within the form area into a first format, and converting the form data in the first format into a hierarchical JSON key-value pair structure; splitting the data in the hierarchical JSON key-value pair structure according to data objects, retrieving and supplementing it through a vector database, and calling a filling model to fill in the missing data in the form area of the first format; converting the form in the first format to obtain a form in the second format, and mapping the form data in the second format to the corresponding target position in the form area to be filled, thereby completing the automatic filling of the form. The present invention solves the technical problem of how to accurately and quickly perform automatic form filling and achieve intelligent data allocation.
[0038] This invention combines language models and enhanced generation technology to achieve high efficiency, accuracy, and intelligence in automatic form filling. By converting the form into a specific format through language models, the highest level of understanding is ensured. Combined with enhanced generation technology, relevant data can be retrieved in real time during the form filling process, ensuring accuracy and avoiding problems caused by missing or incorrect information in traditional automatic filling systems. In addition, this invention supports local data storage, which greatly improves information security, reduces the risk of data leakage, and ensures the privacy of user data.
[0039] In this invention, VBA macros are used to replace content to ensure that the structure of merged cells and nested tables remains fixed, avoiding data misalignment or layout chaos during the filling process. While ensuring the integrity of the content, the original table format is maintained, so that users do not need to manually adjust the table format, ensuring the visual and structural consistency of the filled table. Enhanced generation technology is adopted to dynamically adjust the information allocation according to actual needs and adjust the content filling according to the dynamic changes of the table, avoiding the limitations brought by fixed rules. This allows the system to intelligently adapt to various complex data filling needs, improving the flexibility and accuracy of automatic form filling. Attached Figure Description
[0040] To more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on the structures shown in these drawings without creative effort.
[0041] Figure 1 is a first schematic diagram of a local form autofill method according to an embodiment of the present invention;
[0042] Figure 2 is a second schematic diagram of a local form autofill method according to an embodiment of the present invention;
[0043] Figure 3 is a first schematic diagram of a local form autofill system according to an embodiment of the present invention;
[0044] Figure 4 is a second schematic diagram of a local form autofill system according to an embodiment of the present invention.
[0045] The realization of the objective, functional characteristics and advantages of the present invention will be further explained in conjunction with the embodiments and with reference to the accompanying drawings. Detailed Implementation
[0046] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only a part of the embodiments of the present invention, and not all of them. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0047] Furthermore, in this invention, descriptions involving "first," "second," etc., are for descriptive purposes only and should not be construed as indicating or implying their relative importance or implicitly specifying the number of technical features indicated. Therefore, a feature defined with "first" or "second" may explicitly or implicitly include at least one of that feature.
[0048] Furthermore, the technical solutions of the various embodiments of the present invention can be combined with each other, but only if they are based on the ability of those skilled in the art to implement them. When the combination of technical solutions is contradictory or cannot be implemented, it should be considered that such combination of technical solutions does not exist and is not within the scope of protection claimed by the present invention.
[0049] Referring to Figures 1-2, according to one aspect of the present invention, the present invention provides a method for automatically filling in local forms, wherein the method includes the following steps:
[0050] S1. Select the table area to be filled in, convert the table data in the table area into a first format, and convert the table data in the first format into a hierarchical JSON key-value pair structure;
[0051] S2. Split the data in the hierarchical JSON key-value pair structure according to the data object, retrieve and supplement it through the vector database, and call the filling model to fill the missing data in the table area of the first format.
[0052] S3. Convert the first format table to a second format table, and map the data of the second format table to the corresponding target position in the table area to be filled, thereby completing the automatic filling of the table.
[0053] Specifically, in this embodiment, step S1, selecting the table area to be filled and converting the table data within the table area to the first format, specifically involves:
[0054] When the user selects a table area to be filled, the plugin operation is triggered, and the table macro detection is started. The VBA macro detects the currently selected table area to be filled, determines whether the table area belongs to the table range of the document, and saves the table position information to a text file.
[0055] Read the table order information saved in the text file, convert the table data in the selected table area into HTML format using the Pandoc library, and generate a parsing object for subsequent operations.
[0056] Specifically, in this embodiment, before the step of converting the first-format table data into a hierarchical JSON key-value pair structure, the method further includes: a preprocessing operation for the form to be filled, specifically:
[0057] Extract all elements from the first format table and store them as a table list;
[0058] By extracting the table sequence number, i.e. the table position information, the table to be operated is located, the data is cleaned, extra line breaks in the cells are removed, and the line breaks are replaced with line break markers or placeholders.
[0059] Find cell tags and perform cell tag conversion, load an external dictionary file, and replace the content within the cell with the external dictionary file; the cell tags include and the cell tag conversion specifically involves converting a cell into a cell.
[0060] Replace blank cells in the first format table with blank placeholders; this ensures that blank cells are not forgotten during the conversion of the fill model, while avoiding the effects of line breaks and parentheses.
[0061] Specifically, in this embodiment, the external dictionary file is one of the important operations in data cleaning. It can remove the effects of additional formatting that comes with converting the table to be filled into a first format table. Specifically, it removes the effects of additional formatting that comes with converting a Word table to an HTML table. This is mainly done by extracting content from the Word table in the source document, and replacing the content within the Word table cell by the start and end positions of the non-space characters. This rule is used to fill the corresponding content of the Word table cell into the corresponding content of the HTML table cell. The content is matched one-to-one by index, and the table structure is kept consistent, that is, the number of rows and columns match, thus ensuring that there are no formatting issues in the table content.
[0062] Specifically, in this embodiment, step S1 converts the tabular data in the first format into a hierarchical JSON key-value pair structure, specifically as follows:
[0063] Initialize the OpenAI API client and set the URL and API key;
[0064] The API is invoked, setting the randomness of the generated population model to 0 to ensure consistent and deterministic results. A streaming response is used for easy result viewing. The population model converts a first-format table into a hierarchical JSON format, where each data unit of the first-format table is converted into a key-value pair with a hierarchical relationship. Specifically, the population model converts the first-format table into hierarchical JSON format based on a prompt: "Please convert the following HTML table containing nested tables into hierarchical JSON format." Each row or main content block is treated as a JSON object, and all objects are stored in a JSON array. For nested tables... For nested tables, merged cells, or sections containing multiple elements, use nested objects or arrays of objects to ensure the data structure accurately reflects the table's hierarchical relationship; ensure no information is omitted, and guarantee that the final JSON data fully reflects the content of the original HTML table; this step is crucial for filling models, as JSON conversion simplifies the content and significantly improves the model's understanding of its completeness, making it ideal for cases with exceptionally complex and redundant table structures; this process primarily converts input into output, transforming a complex HTML table with nested tables, merged cells, etc., into JSON data that preserves all content and hierarchical structure within the table.
[0065] Specifically, in this embodiment, the filling model is the GPT-4o model.
[0066] Specifically, in this embodiment, before filling in the form, the known content needs to be stored in the vector database to ensure that the form has basic content. The storage methods for the known content are varied, including text files, PDF documents, Word documents, CSV documents, and web pages. In practice, text files are commonly used. This invention does not impose specific limitations and can be set according to needs. In the text file, the format is arbitrary, as long as the relationship is constructed correctly. After the HTML form is filled in, you can also choose to save the HTML form.
[0067] Specifically, in this embodiment, step S2 is as follows:
[0068] The data in the hierarchical JSON key-value pair structure is split into multiple documents according to the data object, and vector embeddings are generated for the split documents. These vector representations not only compress the original data, but also preserve the semantic relationships between words or sentences, and there is a one-to-one correspondence between the vectors and the documents.
[0069] A vector database is created based on document chunking and embedding, and the name and ID of the vector storage set are specified to ensure the uniqueness of the vectors and avoid duplication during retrieval;
[0070] A retrieval-based question-and-answer chain is constructed. Based on user-input prompts, a search is performed in a vector database to obtain the search results. A fill-in model is then invoked to fill in the missing data within a table area of the first format. This invention employs a hierarchical chain type, which effectively improves the efficiency of retrieval and generation, such as a MapReduce chain. The fill-in model, i.e., a language generation model, and a text embedding model (Text-Embedding-Ada-002), achieves a tight integration of content retrieval and generation. The prompts are: "Find the closest content from the vector database, fill in the missing parts of the JSON, be sure to fill in completely, all found content should be filled into the corresponding fields of the JSON, if no relevant information is found in the vector database, please fill in the value of the field as 'empty', please ensure that this rule is applied to the entire JSON, please complete all fields in the JSON according to the above requirements, please think carefully before answering, and do not omit anything." Based on the prompts, content is retrieved from the vector database and the fill-in model is invoked to fill in the JSON, finally generating a filled JSON.
[0071] Specifically, in this embodiment, after step S2, the method further includes:
[0072] Data not present in the vector database during the first-format table filling process is extracted using a lightweight language generation model. A special prompt word is set, and the lightweight language generation model filters out unknown data with empty values within the first-format table area, along with the parent structure of the unknown data. The filtered first-format table data is then output to a specified text file in append mode. The user updates the vector database based on the text file. The lightweight language generation model is the GPT-4o-Mini model. The special prompt word is: "The keyword for content with an empty value in the JSON, along with its parent structure, is printed out." The original structure is maintained, but content with non-empty values is prohibited. Even if it is the same object, if the value is not empty, it should be ignored and only the JSON should be printed. Other unnecessary content does not need to be printed. If there is no information with an empty value in the JSON, only a '{}' character can be printed. The language model prints the information based on prompt words and stores the filtered JSON in append mode into the specified file to ensure that the new content does not overwrite the existing content. At the same time, a prompt is given to the user after the operation is completed. After the form is filled out, the user can open the corresponding text file to supplement the information, and then update it through the vector database.
[0073] Specifically, in this embodiment, updating the vector database includes:
[0074] The target vector is merged by searching for existing documents in the vector database by ID according to the path of the storage vector database file. The content and metadata of the documents are extracted, new content is read from the documents and concatenated with the existing content to form a new feature vector. At the same time, the metadata is updated, source information is appended, a new document object is constructed, and the merged content and metadata are stored.
[0075] Alternatively, you can directly add new feature vectors, read new document content, define metadata, mark the source as a file, use a document class to combine the read text content with the metadata to generate a new document object, set an ID, and add the new document object and its corresponding ID to the vector database using the document object addition method.
[0076] Specifically, in this embodiment, step S3 is as follows:
[0077] The Pandoc library is used to convert a completed HTML table into a Word table. The format of the Word table is slightly different from the initial table to be filled, but the change in format will not affect the result because the table structure and line breaks remain consistent. The content of the template table is the pre-filled version of the initial table to be filled. A VBA macro is then used to map the content of the Word table to the corresponding target position within the table area to be filled, completing the automatic table filling. This ensures that the data is filled without damaging the original table. During this process, the VBA macro identifies the content of each line in the cell according to the line break, replacing the content of each line in the table cell one by one from the beginning of a non-space character to the end of another non-space character, ensuring that the data is accurately transferred to the target position.
[0078] Referring to Figures 3 and 4, according to another aspect of the present invention, the present invention provides a local form autofill system, wherein the local form autofill system includes a format conversion module, a database retrieval module, a data missing identification module, and a table format restoration module connected in sequence;
[0079] The format conversion module is used to convert the table data in the table area into a first format, and convert the table data in the first format into a hierarchical JSON key-value pair structure;
[0080] The database retrieval module is used to retrieve supplementary data from the vector database and call the filling model to fill in the missing data in the table area of the first format.
[0081] The missing data identification module is used to extract missing data, generate a text file, and update the vector database.
[0082] The table format restoration module is used to convert the first format table to a second format table, and map the second format table data to the corresponding target position in the table area to be filled.
[0083] Specifically, in this embodiment, the local form autofill system includes a UI layer, a business logic layer, and a data access layer. Users can select and configure table areas in the UI layer to trigger corresponding operations. The business logic layer handles data filling and transformation, including: table data conversion, converting user-selected table data into HTML format; data hierarchical JSONification, using a tree-like nested hierarchical diagram with the original table structure to convert HTML table data into a hierarchical JSON key-value pair structure to support the simplest vector database search; data filling, supplementing missing information in the hierarchical JSON through vector database retrieval and returning relevant data, and filling the HTML table using LLM; table generation, applying the HTML table content filled by the Large Language Model (LLM) to the user table using VBA, ensuring the structure remains unchanged; and the data access layer is used for local data storage and updates. For data not retrieved from the vector database, LLM stores it in a text file, and users can use the update function to complete this information and update the vector database.
[0084] Specifically, in this embodiment, the format conversion module uses the Pandoc library to convert HTML table data into hierarchical JSON, facilitating data segmentation, retrieval, and filling. By selecting the current table, a table macro is activated to check if the selected content falls within a specific table in the document. If the selected content belongs to a table range, the table's index is written to a text file. The Pandoc document conversion tool is used to convert the Word document into HTML format, generating a parsing object for easier manipulation. During the parsing process, all HTML data is processed...
[0086]
[0087]
[0088]
[0089]
[0090]
[0091]
[0092]
[0093]
[0094]
[0095]
[0096]
[0097]
[0098]
[0099]
[0100] Elements are extracted and stored as a table list; the table number is extracted to locate the table to be operated on, then data cleaning is performed, removing redundant line breaks from cells and replacing them with placeholders {{BR}}, and finding all... and For each cell, an external dictionary file is loaded and its contents are replaced with the cell's content; the final step in data processing is to format the table, through... Cell to The process involves preprocessing cells and replacing the content of blank cells with `<!--FILL-->`, completing all preprocessing operations for the table to be filled. An external dictionary file, in the format `{Word cell index: Word cell content}`, is also a crucial part of data cleaning, removing the additional formatting issues associated with converting Word documents to HTML. This is achieved by extracting content from the source document's Word tables, replacing the content at the beginning and end of non-whitespace characters in the Word table cell content. This rule is used to fill the corresponding content in the HTML table cells with the corresponding content, ensuring a consistent table structure, matching row and column numbers, and addressing formatting issues. After these steps, the HTML is converted to hierarchical JSON. The API client is initialized, setting the base URL and API key. The interface is called, specifying the use of the GPT-4o model and setting the randomness of model generation to 0 to ensure the results are as predictable as possible. The code is consistent with the HTML table structure and uses a streaming response for easy viewing of results. The modified prompt is: "Please convert the following HTML table containing nested tables to hierarchical JSON format; requirements: each row or each main content block should be treated as a JSON object, and all objects should be stored in a JSON array; for nested tables, merged cells, or sections containing multiple contents, use nested objects or arrays of objects to ensure the data structure accurately reflects the table's hierarchical relationship; do not omit any information, ensuring the final JSON data fully reflects the content of the original HTML table; only print the JSON, other information does not need to be printed, where <!--FILL--> is a whitespace placeholder, and {{BR}} is a newline placeholder." This prompt is crucial for LLM, as JSON conversion simplifies the content and significantly improves the model's understanding of the content, making it ideal for situations with exceptionally complex and redundant table structures.
[0085] For small tables, there won't be much improvement. For simpler table types with fewer merged cells, nested cells, and object array cells, the initial stage involves using LLM to identify the fields to be filled in the HTML table. Then, tags (e.g., '#1', '#2') are entered into these fields. In the subsequent filling stage, the tags are replaced with generated content via code at the corresponding locations in the HTML table. Then, the header / keyword cell content is used as the key, and the value cell content or the field to be filled is used as the value. The LLM then converts the HTML table into a hierarchical JSON format, for example, '...'. Name #1 'Convert to '{"Name":"#1"}' or ' #1 year #February #3rd The first approach converts the data to '{"Date of Birth":"#Year#Month#Day"}', supplementing the hierarchical JSON using LLM+RAG. Examples include '{"Name":"Xiaoming"}' and '{"Date of Birth":"December 15, 2001"}'. Finally, replacing the tags achieves the HTML table's fill effect. For simpler tables, which rarely contain merged, nested, or array-of-object cells, two solutions exist: The first is to convert the table to content separated by the "|" character, such as "Name|". The directly separated table is then processed by LLM, becoming "Name|Xiaoming". The table is then filled using code. The second approach utilizes blank cells to the right or below the main cell as the filling position, prioritizing right-side blank cells. Under this strategy, directly writing fixed code for filling simpler tables is very convenient. Specifically, in this embodiment, the database retrieval module is used to retrieve the data to be filled. By retrieving from the vector database, the returned document is provided to the filling model for data filling. Before filling in the form, the known content is stored in the vector database to ensure that the form has basic content. The storage methods for the known content are diverse, including text files (txt), PDF documents, Word documents, CSV files, and web pages. In actual operation, text files are used. In the text file, the format is arbitrary, as long as the relationship construction is correct. Using JSON to store the most basic content is the current method. After the HTML form is filled in, it can also be stored. The content of the loaded text file is divided into multiple small documents according to the block size, and vector embeddings are generated for the segmented documents. These feature vector representations not only compress the original data but also preserve the semantic relationships between words or sentences, and the feature vectors and documents are in one-to-one correspondence. A database is created based on document chunking and embedding, specifying the name and ID of the vector storage set to ensure the uniqueness of feature vectors and avoid duplication during retrieval. A retrieval-based question-and-answer chain is constructed, where the user's input question is used to retrieve the most relevant content from the vector database to generate an answer. When dealing with large amounts of document data, using a hierarchical chain type (such as a MapReduce chain) can effectively improve retrieval and generation efficiency. By combining the advantages of natural language generation models (such as GPT-3.5-Turbo) and text embedding models (Text-Embedding-Ada-002), a tight integration of content retrieval and generation is achieved. The prompt is set as: "Find the closest content from the vector database and fill in the missing parts of the JSON. Ensure completeness; all found content should be filled into the corresponding fields in the JSON. If no relevant information is found in the vector database, please fill in the value of the field as 'empty'. Please ensure that this rule is applied to the entire JSON."Please complete all fields in the JSON as required above. Please think carefully before answering and do not omit any. Based on the prompt, retrieve content from the vector database and populate the JSON by calling LLM, finally generating the filled JSON. Specifically, in this embodiment, the data missing identification module extracts missing data through a lightweight language generation model, generates text for the user to supplement, and then updates it back to the vector database; through the lightweight language generation model, it filters out content with a value of 'empty' and its parent structure from the JSON data input by the user, and outputs the filtered JSON to a specified text file for the user to manually supplement; the prompt is set as follows: "Print out the keywords of the content with a value of 'empty' in the following JSON, along with the parent structure, while maintaining the original structure, but do not include content with a value other than 'empty'. Even if it is the same object, if the value is not 'empty', it should be ignored, only the JSON should be printed, and other extra content does not need to be printed; if there is no information with a value of 'empty' in the JSON, only a '{}' character can be printed." The LLM prints information based on the above prompts, appends the filtered JSON to a specified file to ensure that new content does not overwrite existing content, and prompts the user upon completion. Once the form is filled out, the user can open the text file to supplement information, and then update the vector database. Method 1: Merge target feature vectors. Based on the path to the stored vector database file, search by ID to retrieve existing documents from the vector database, extract the document content and metadata, read new content from the file and concatenate it with existing content to form a new feature vector, update the metadata, append source information, construct a new document object, and store the merged content and metadata. Method 2: Add new feature vectors. Read the new document content, define metadata, mark the source as a file, use a document class to combine the read text content with the metadata to generate a document object, set an ID, and add the new document object and its corresponding ID to the vector database using the document object addition method. These two methods update the corresponding information to the vector database, flexibly optimizing database efficiency or ensuring data consistency for later form filling.Specifically, in this embodiment, the table format restoration module is used to convert the HTML table filled in by the LLM into a new Word document using the Pandoc library, which serves as the template table. The original table is the table to be filled in. Because line breaks have already been replaced with placeholders, there is no need to worry about the LLM losing line breaks when filling in the HTML table. The placeholders in the HTML table are ultimately restored to actual line breaks () to ensure that the line breaks in the converted Word table correspond one-to-one with those in the original Word table. Plain text pasting is a good way to preserve formatting. There is no need to record the specific content of the format; simply replacing each line of content in the template table with plain text in the original table will preserve the formatting. This method achieves the final complete form filling effect. Based on this strategy, LLM can perform character filling followed by format copying and pasting. For example, "Name:" becomes "Name: Xiaoming" after filling, which is called the target content. Then, VBA is used to compare it with the original cell content character by character. When the target content and the original cell content have the same character, the pointer jumps to the next character together. When different characters are encountered, the format of the previous character of the original cell content is copied and pasted together with the character content of the target content to the next character after the current character of the original cell content. At the same time, the position of the pointer pointing to the character in the original cell content remains unchanged, while the pointer points to the character in the target content and jumps to the next character, until there is a common character or the character comparison ends. Specifically, in this embodiment, based on table serialization, that is, based on converting the table data in the table area into a first format, the first format includes HTML, XML, or Markdown format, etc. In this invention, the first format is HTML format. Through LLM-driven table layout parsing technology, the complex HTML table structure is structured into a hierarchical JSON format, reducing tag redundancy and improving processing efficiency. Specifically, in this embodiment, a precise prompting strategy is adopted. Elements such as placeholder tags, nested objects, and object arrays are used to improve the accuracy of LLM in table understanding and generation tasks. Placeholder tags are used to mark specific content in table cells, such as <!--FILL--> marking blank cells, [newline] or {{BR}} marking line breaks, which helps LLM accurately identify and fill in the content of each cell, reducing errors. Nested objects are used for multi-level data structures, such as {address:{province:"XX province", city:"XX city", district:"XX district"}}, which helps LLM understand the hierarchical relationship of the data. Object arrays are suitable for tables containing multiple records, such as [{name:"Xiaoming", age:18},{name:"Xiaohong", age:19}], which helps LLM recognize this as a structure and process the table content row by row. Through this strategy, LLM can more accurately parse the meaning and hierarchical structure of each field in the table, thereby improving the practicality and accuracy of automatic table filling.Specifically, in this embodiment, using local HTML tables or hierarchical JSON data to construct the vector database can simplify it to the simplest key-value pair form. JSON storage can effectively reduce storage space and is easy to manage, but the conversion process is time-consuming and may lose some relational information. HTML storage maintains the original table structure and avoids information loss, but this requires the model to have a good table understanding ability, and the management of feature vectors is more complex. Both methods have their advantages and disadvantages. In actual application, a combination of the two methods is adopted. In RAG, table data can be optimized through tag-enhanced queries, such as adding descriptive ID tags to each feature vector, such as "{id: Xiaoming, content: {age: 18}}", to ensure that the model can more accurately capture the context, reduce interference, achieve accurate retrieval and enhanced generation of key content, and ensure context relevance when filling in the form. Specifically, in this embodiment, the JSON intermediate representation is optimized. In the JSON intermediate representation, an optimized "hierarchical JSON structure" is used to represent table data. In this structure, the tree-like nested hierarchy shows the hierarchical relationship of the table, and the relationship between each level is clear. Merged cells are represented using a hierarchical JSON object array so that the model can accurately understand the complete logic of the table. At the same time, each row of information in the table is represented as an independent object to facilitate block processing and data retrieval. Specifically, in this embodiment, in multi-cell content queries, each row is treated as a whole object containing multiple key-value pairs. Efficiency is improved through a multi-key query strategy, matching multiple key-value pairs in a single query. This avoids redundant operations caused by single-key-value queries, where the retrieved content may be too scattered, leading to a decrease in generation accuracy. Because it is parallel processing, the system maintains high query accuracy while improving processing efficiency, enabling rapid processing of multi-cell information scenarios. When filling out tables using VBA macros, plain text pasting is used to avoid overwriting or modifying the format. Specifically, the content is split into rows, with each row treated as a whole and replaced using a newline character as the boundary. This ensures that the original format and layout of each cell in the complex table remain unchanged, thus solving the problem of filling out complex tables while preserving the original table format.Specifically, in this embodiment, the present invention can be applied not only to filling student information forms, but also to automatically filling forms such as financial statements. The present invention is not specifically limited. Taking the filling of a student information form as an example, in the student information form, when the user selects a blank table area, the system automatically recognizes the table structure and reads the required fields. The system performs the following steps in sequence: Selection and Serialization: Selecting the table area and converting the data in the table area into HTML format for subsequent data processing; Hierarchical JSON Conversion: Converting the HTML table into hierarchical JSON structured data, where the content of each cell is stored in key-value pairs; Data Retrieval and Filling: For missing fields in the student information form, such as student age or class, the system calls a vector database for retrieval. If no relevant information is found in the vector database, GPT-... The 4o model infers or generates content; table generation and format preservation: after LLM filling is completed, the system re-imports the data into Word and uses VBA to ensure that the table format is consistent with the original structure; the system can automatically fill in the required information in blank fields of student information tables, greatly reducing manual input and improving efficiency; in addition, the system ensures the accuracy of each field's content through a vector database, such as matching age or class based on student ID; taking the filling of financial statements as an example, financial statements usually include multiple data columns, involving complex data summarization and grouping. The specific process of the system when filling financial statements is as follows: table conversion: after the user selects the financial statement area, the system converts the area into HTML format; hierarchical JSONization and grouping processing: according to the structure of the financial statement, the system converts the data into hierarchical JSON arrays by rows and columns. Merged cells are processed into hierarchical JSON objects to clearly show the hierarchical relationship; data filling and calculation: the system retrieves and fills in the missing financial data through a vector database. If the table contains summary columns or calculated fields, the system calls LLM for data inference and calculation. Formatting and export: After the financial data is filled in, the system imports the data into the original table, preserving the original format, including currency symbols and percentage formats. The system provides data completion and automatic calculation functions for financial statements, effectively reducing the complexity and error rate of manual form filling. The system also maintains the original format of the reports, ensuring that the exported results meet professional standards for financial reports. For ease of understanding of the terminology used in this invention, the following explanation is provided: Large Language Model (LLM) refers to a natural language processing model trained on a large corpus, capable of understanding and generating natural language. It learns from large amounts of text data, mastering the rules and patterns of language, thus demonstrating high capabilities in various language tasks, such as text generation, translation, and question answering. Large language models have wide applications; the GPT series of models is a representative example.Its main advantage lies in its ability to generate coherent and context-consistent text, but it may require optimization in conjunction with other techniques when handling structured tasks. Retrieval-Augmented Generation (RAG) is a technique that combines information retrieval and text generation. It enhances the accuracy and relevance of the generated content by utilizing relevant information from external data sources or knowledge bases during the text generation process. RAG technology enables large language models to not only rely on training data for generation but also retrieve useful content from external databases or documents in real time, thereby generating more accurate results. This is particularly suitable for tasks requiring high accuracy and complex reasoning, such as form filling. The above are merely preferred embodiments of the present invention and do not limit the patent scope of the present invention. Any equivalent structural transformations made using the content of the present invention's specification and drawings under the inventive concept of the present invention, or direct / indirect applications in other related technical fields, are included within the patent protection scope of the present invention.
Claims
1. A method for automatically filling in local forms, characterized in that, Includes the following steps: S1. Select the table area to be filled, convert the table data within the table area to a first format, and convert the table data in the first format to a hierarchical JSON key-value pair structure; before converting the table data in the first format to a hierarchical JSON key-value pair structure, the process further includes: preprocessing the table to be filled, specifically: extracting all elements from the first format table and storing them as a table list; locating the table to be operated on by extracting the table number, performing data cleaning, removing redundant line breaks in the cells, and replacing the line breaks with line break markers or placeholders; finding cell labels and performing cell label conversion, loading an external dictionary file, and replacing the content within the cells with the external dictionary file; In the first format table, blank cells are replaced with blank placeholders; step S1 converts the first format table data into a hierarchical JSON key-value pair structure, specifically: initializing the OpenAI API client and setting the URL and API key; calling the interface, setting the randomness generated by the filling model to 0, and using streaming response, calling the filling model to convert the first format table into a hierarchical JSON format, where each data unit of the first format table is converted into a key-value pair with a hierarchical relationship; wherein, calling the filling model converts the first format table into a hierarchical JSON format according to the prompt words, that is, converts the HTML table into a hierarchical JSON format according to the prompt words, requiring each row or each Each content block is treated as a JSON object, and all objects are stored in a JSON array. For nested tables, merged cells, or parts containing multiple contents, nested objects or arrays of objects are used for representation; S2, the data in the hierarchical JSON key-value pair structure is split according to data objects, retrieved through a vector database, and the filling model is called to fill in the missing data in the table area of the first format; Step S2 specifically involves: dividing the text file with basic content for table filling into multiple documents according to block size, and generating vector embeddings for the split documents; creating a vector database based on the document blocks and vector embeddings, specifying the name and ID of the vector storage set; constructing a retrieval-based question-and-answer chain, based on the user The prompts entered by the user are retrieved from the vector database to obtain the search results. The fill model is then called to fill the JSON array. Based on the filled JSON array, the missing data in the first format table area is filled. S3: The first format table that has been filled is converted to a second format table. The data in the second format table is mapped to the corresponding target position in the table area to be filled, thereby completing the automatic filling of the table. Specifically, step S3 is as follows: The completed HTML table is converted to a Word table using the Pandoc library, and the content of the Word table is mapped to the corresponding target position in the table area to be filled using VBA macros, thereby completing the automatic filling of the table.
2. The method for automatically filling in a local form according to claim 1, characterized in that, Step S1 involves selecting the table area to be filled in and converting the table data within the table area into a first format. Specifically, this involves selecting the table area to be filled in, starting table macro detection, determining whether the table area belongs to the table range of the document, and saving the table position information to a text file; reading the table position information saved in the text file, and converting the table data within the selected table area into HTML format using the Pandoc library.
3. A method for automatically filling in local forms according to any one of claims 1-2, characterized in that, The filling model is the GPT-4o model.
4. A method for automatically filling in local forms according to any one of claims 1-2, characterized in that, Following step S2, the method further includes: extracting data that is not present in the vector database during the filling process of the first format table using a lightweight language generation model; setting prompt words, filtering out unknown data with empty values in the first format table area and the parent structure of the unknown data using the lightweight language generation model, and outputting the filtered first format table data to a specified text file in append mode; the user supplements information in the specified text file, and then updates the vector database; the lightweight language generation model is the GPT-4o-Mini model.
5. The method for automatically filling in a local form according to claim 4, characterized in that, The updating of the vector database includes: merging target feature vectors: based on the path of the stored vector database file, retrieving existing documents from the vector database using ID search, extracting the document content and metadata, reading new content from a specified text file and concatenating it with the existing content of the existing document to form a new feature vector, simultaneously updating the metadata, appending source information, constructing a new document object, and storing the merged content and metadata; or directly adding new feature vectors: reading the content of a specified text file, defining metadata, marking the source as a file, using a document class to combine the read text content with the metadata to generate a new document object, setting an ID, and adding the new document object and its corresponding ID to the vector database using the document object addition method.
6. A system comprising the local form autofill method according to any one of claims 1-5, characterized in that, The system includes a format conversion module, a database retrieval module, a data missing identification module, and a table format restoration module connected in sequence. The format conversion module converts the table data within the table area into a first format and then converts the first format table data into a hierarchical JSON key-value pair structure. The database retrieval module retrieves data from a vector database and calls a filling model to fill in the missing data within the first format table area. The data missing identification module extracts the missing data, generates a text file, and updates the vector database. The table format restoration module converts the first format table to a second format table and maps the second format table data to the corresponding target position within the table area to be filled.
Citation Information
Patent Citations
Dialogue method and system based on document retrieval enhanced machine language model
CN117807199A
Automatic retrieval and automatic form filling system for form information in non-fixed format
CN118966170A