Special character replacement method and device, equipment and medium

By parsing the markup and value attributes of the PDF template file, determining and replacing special characters using regular expressions, the problem of inaccurate character replacement in traditional solutions is solved, ensuring the correctness of the policy content and user experience.

CN120822492APending Publication Date: 2025-10-21CHINA PING AN PROPERTY INSURANCE CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202510790212.2
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-06-12
Publication Date
2025-10-21

AI Technical Summary

Technical Problem

Traditional special character replacement solutions cannot recognize the contextual semantics of characters, resulting in incorrect replacement of policy content and poor user experience.

Method used

By obtaining the PDF template file and data source object, parsing the markup attribute and value attribute of the file template element, determining whether it is an HTML element, and using pre-calibrated mapping relationships and regular expressions to replace special characters.

Benefits of technology

It achieves accurate replacement of special characters, ensures the correctness of the policy content, and improves the user experience.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120822492A_ABST
    Figure CN120822492A_ABST
Patent Text Reader

Abstract

The invention relates to the technical field of financial or medical management, in particular to a special character replacement method and device, equipment and a medium, and the method comprises the steps: obtaining a to-be-processed PDF template file and a data source object corresponding to the to-be-processed PDF template file, analyzing the to-be-processed PDF template file, and determining file template elements, the file template element comprises a markup attribute and a value attribute, determining a display value of the file template element according to a data expression and a data source object in the value attribute in the file template element, judging whether the markup attribute of the file template element is an HTML (Hypertext Markup Language) element or not according to the display value of the file template element, and if the markup attribute of the file template element is the HTML element, displaying the HTML element in the file template element. If yes, replacing the special character through the regular expression according to the pre-calibrated corresponding relation between the special character and the target character, and generating the target character corresponding to the PDF template file to be processed, so that the special character can be accurately replaced, and the correctness of the insurance policy content is ensured.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of finance or medical management technology, and in particular to a special character replacement method, device, equipment and medium. Background Art

[0002] With the rapid development of science and technology, the amount of medical or financial data has exploded. Due to the complexity of medical or financial business scenarios, there are more and more interactions between systems, more and more interaction methods are involved, and the special character encoding in the interaction process is not consistent. Therefore, special character replacement is becoming more and more important.

[0003] However, traditional special character replacement solutions primarily use a unified replacement table to process characters, which fails to recognize the contextual semantics of characters. For example, a policy amount range of "<1 million" becomes a policy amount range of 1 million. This inability to accurately replace special characters can lead to incorrect policy content and a poor user experience. Therefore, accurately replacing special characters is a pressing technical challenge. Summary of the Invention

[0004] Based on this, it is necessary to address the above technical issues. The embodiments of the present invention provide a special character replacement method, device, equipment and medium, which can accurately replace special characters and ensure the correctness of the policy content.

[0005] A first aspect of an embodiment of the present application provides a method for replacing special characters, the method comprising: Obtain the PDF template file to be processed and the data source object corresponding to the PDF template file to be processed; Parsing the PDF template file to be processed to determine a file template element, wherein the file template element includes a markup attribute and a value attribute, the markup attribute is used to identify the element type, and the value attribute is used to set a data expression; Determine the display value of the file template element according to the data expression in the value attribute in the file template element and the data source object; Determining, based on the display value of the file template element, whether the markup attribute of the file template element is an HTML element; If the markup attribute of the file template element is an HTML element, the special characters are replaced by regular expressions according to a pre-marked mapping relationship to generate target characters corresponding to the PDF template file to be processed, wherein the mapping relationship is a correspondence between the pre-marked special characters and the target characters.

[0006] A second aspect of an embodiment of the present application provides a special character replacement device, the special character replacement device comprising: An acquisition module is used to acquire a PDF template file to be processed and a data source object corresponding to the PDF template file to be processed; a parsing module, configured to parse the PDF template file to be processed and determine a file template element, wherein the file template element includes a markup attribute and a value attribute, the markup attribute is used to identify the element type, and the value attribute is used to set a data expression; a determination module, configured to determine a display value of the file template element according to a data expression in a value attribute of the file template element and the data source object; a judging module, configured to judge whether the markup attribute of the file template element is an HTML element according to the display value of the file template element; A generation module is used to replace the special characters by regular expressions according to a pre-calibrated mapping relationship if the markup attribute of the file template element is an HTML element, so as to generate target characters corresponding to the PDF template file to be processed, wherein the mapping relationship is a correspondence between the pre-calibrated special characters and the target characters.

[0007] In a third aspect, a computer device is provided, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the special character replacement method as described in the first aspect when executing the computer program.

[0008] In a fourth aspect, a computer-readable storage medium is provided, wherein the computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the special character replacement method as described in the first aspect is implemented.

[0009] In summary, the present invention provides a special character replacement method, device, equipment and medium. By obtaining a PDF template file to be processed and a data source object corresponding to the PDF template file to be processed, the PDF template file to be processed is parsed to determine the file template element, wherein the file template element includes a markup attribute and a value attribute, the markup attribute is used to identify the element type, and the value attribute is used to set a data expression. According to the data expression in the value attribute in the file template element and the data source object, the display value of the file template element is determined. According to the display value of the file template element, it is judged whether the markup attribute of the file template element is an HTML element. If the markup attribute of the file template element is an HTML element, the special characters are replaced by regular expressions according to a pre-calibrated mapping relationship to generate target characters corresponding to the PDF template file to be processed, wherein the mapping relationship is a pre-calibrated correspondence between special characters and target characters. It can be seen that this application determines whether the markup attribute of the file template element is an HTML element based on the display value of the file template element. If so, the special characters are replaced by regular expressions based on the correspondence between the pre-marked special characters and the target characters to generate the target characters corresponding to the PDF template file to be processed. The special characters can be replaced accurately, which ensures the correctness of the policy content, makes the generated text more in line with user expectations, and effectively improves the user experience. BRIEF DESCRIPTION OF THE DRAWINGS

[0010] In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the following briefly introduces the drawings required for use in the description of the embodiments of the present invention. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative labor.

[0011] Figure 1 This is a schematic diagram of an application environment of a special character replacement method provided by an embodiment of the present invention; Figure 2 1 is a flow chart of a special character replacement method provided by one embodiment of the present invention; Figure 3 1 is a schematic structural diagram of a special character replacement device provided by one embodiment of the present invention; Figure 4 It is a structural diagram of a computer device provided by one embodiment of the present invention. DETAILED DESCRIPTION

[0012] The following will clearly and completely describe the technical solutions in the embodiments of the present invention in conjunction with the accompanying drawings. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of them. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without making any creative efforts are within the scope of protection of the present invention.

[0013] It should be understood that when used in the present specification and the appended claims, the term "comprising" indicates the presence of described features, integers, steps, operations, elements and / or components, but does not preclude the presence or addition of one or more other features, integers, steps, operations, elements, components and / or groups thereof.

[0014] It will also be understood that the term "and / or" used in the present description and appended claims refers to and includes any and all possible combinations of one or more of the associated listed items.

[0015] As used in the present specification and the appended claims, the term “if” may be interpreted as “when” or “upon” or “in response to determining”, depending on the context. Similarly, the phrase “if it is determined” or “if compared to [described condition or event]” may be interpreted as meaning “upon determination” or “in response to determination” or “upon comparison to [described condition or event]” or “in response to comparison to [described condition or event]”, depending on the context.

[0016] In addition, in the description of the present specification and the appended claims, the terms "first", "second", "third", etc. are only used to distinguish the descriptions and cannot be understood as indicating or implying relative importance.

[0017] References to "one embodiment" or "some embodiments" in the present specification mean that a particular feature, structure, or characteristic described in conjunction with that embodiment is included in one or more embodiments of the present invention. Thus, phrases such as "in one embodiment," "in some embodiments," "in other embodiments," and "in yet other embodiments" appearing in various places in this specification do not necessarily refer to the same embodiment, but rather mean "one or more, but not all, embodiments," unless otherwise specifically emphasized. The terms "including," "comprising," "having," and variations thereof mean "including but not limited to," unless otherwise specifically emphasized.

[0018] It should be understood that the order of execution of the steps in the following embodiments does not necessarily mean the order in which they are executed. The order in which each process is executed should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of the present invention.

[0019] In order to illustrate the technical solution of the present invention, specific embodiments are provided below.

[0020] A special character replacement method provided by an embodiment of the present invention can be applied in Figure 1 In an application environment, a client communicates with a server. Clients include, but are not limited to, PDAs, desktop computers, laptops, ultra-mobile personal computers (UMPCs), netbooks, personal digital assistants (PDAs), and other computer devices. The server can be implemented as a standalone server or a server cluster consisting of multiple servers.

[0021] See also Figure 2 , is a flow chart of a special character replacement method provided by an embodiment of the present invention, the special character replacement method can be applied to Figure 1 The server in the above mentioned server connects to the corresponding client, such as Figure 2 As shown, the special character replacement method can be implemented by the following steps.

[0022] S201: Obtain a PDF template file to be processed and a data source object corresponding to the PDF template file to be processed.

[0023] In step S201, the PDF template file to be processed may refer to a PDF file used to generate an HTML file. A PDF file may include multiple pages, each of which may include text and / or image information. Specifically, the PDF template file to be processed may include only image information, only text information, or both. For example, the PDF template file to be processed may be a medical document, such as an electronic healthcare record (EHR), a type of electronic personal health record that includes medical records, electrocardiograms, medical images, treatment information, and other electronic records valuable for preservation and future reference. Text information may include text or characters, while image information may include grayscale or color images in any format. For example, image information may include an insurance policy image (e.g., an insurance policy, insurance contract, or insurance card). Documents containing policy images have flexible formats, occupy minimal storage space, and can be directly applied to embedded devices such as insurance systems, enabling storage of policies without affecting the policy content. With increasing practical application, the policy template library will continue to expand, further adapting to the needs of financial technology development. In document processing scenarios, the data source object corresponding to the PDF template file being processed is a collection of structured data extracted from external data sources (such as databases, files, APIs, etc.). It is used to populate specific locations in the PDF template (such as text boxes, tables, images, and other template elements). Its core function is to convert raw data into a format that the PDF template can recognize and call, thus integrating dynamic data with the static template.

[0024] Specifically, the PDF template file to be processed is an index tree structure, the root node is the name or number of the PDF template file to be processed, the page tree can be the directory of the PDF template file to be processed, and is used to index each page of the PDF file to be processed. The contents of the PDF template file to be processed are isolated from each other by page (in Figure 4 Corresponding to n pages in the PDF template file to be processed). The content stream is the main carrier of the content of the PDF template file to be processed. Each page in the PDF template file to be processed can be decoded to obtain the content stream of the PDF template file to be processed. The obtained content stream includes the resource index and content index of each page. Among them, the resource index refers to the resources in each page content that cannot be written in plain text on the PDF template file to be processed. It is a compressed binary stream (including text information and image information) used by the PDF file to be processed; the content index refers to the resources (including text information and image information) that can be written in plain text on the PDF file to be processed. For example, graphic elements can include straight lines, curved lines, circular fills, rectangular fills, and color tables, etc.

[0025] In one embodiment of the invention, obtaining a PDF template file to be processed includes: Receiving a file printing request initiated by a client, wherein the file printing request includes file request parameters, and the request parameters include a template file identifier and a template file type; Generate a complete template file path by splicing according to the template file identifier, template file type, predefined template file storage path and naming rules; Determine whether the template file path meets the preset file path condition; If the template file path meets the preset file path condition, the PDF template file to be processed is obtained.

[0026] Specifically, file request parameters are obtained from the file printing request initiated by the medical client (such as a web application or an API call). Based on a preset parsing method, the file request parameters are parsed to extract the template file type and template file identifier in the file request parameters. Template file types (such as "medical record template", "prescription", and "examination report") are used to classify and manage templates for different business scenarios. Template file identifiers (such as "MR-2024-v3" and "PRES-OPD-001") uniquely identify a specific version of a template. Based on business logic and file management requirements, predefined template file storage paths and naming rules are used. Then, according to the template file type, template file identifier, predefined template file storage path, and naming rules, a complete template file path is generated by splicing. For example, the template file type is "Outpatient Medical Record", the template file identifier is "2024 Standard Edition", and all templates are stored in the general folder of the electronic medical record library (predefined storage path). The classification rule is outpatient medical record → placed in the outpatient / subfolder, inpatient medical record → placed in the inpatient / subfolder, and the naming rule is type-year-version number. According to "Outpatient Medical Record", the outpatient / subfolder is found, and according to "2024 Standard Edition", the outpatient-2024-01.html file is found, and finally the full path is located: / Electronic Medical Record Library / Outpatient / Outpatient-2024-01.html. After obtaining the template file path, it is necessary to determine whether the template file path meets the preset file path conditions. The preset file path conditions can be whether it is within the specified area, whether the file type is correct, and whether the path is legal. It can be set according to the actual situation, and this application does not impose any restrictions on this. If the template file path meets the preset file path conditions, the PDF template file to be processed and the data source object corresponding to the PDF template file to be processed are obtained. In this way, the corresponding template file can be flexibly and dynamically selected and loaded according to different requests, so that the PDF template file to be processed and the data source object corresponding to the PDF template file to be processed can be obtained efficiently and safely.

[0027] In one embodiment of the invention, obtaining a data source object corresponding to a PDF template file to be processed includes: Receiving a file print request initiated by a client, wherein the file print request includes file request parameters, and the request parameters include a template file identifier, a data format identifier, and a filtering condition; Locating the PDF template file to be processed according to the template file identifier, calling a corresponding parsing tool according to the data format identifier, reading the text content of the PDF template file to be processed, and filtering the text content of the PDF template file to be processed in combination with the filtering condition; Convert the filtered file content of the PDF template file to be processed into a structured data source object.

[0028] Specifically, file request parameters are obtained from a file print request initiated by a medical client (e.g., a web application or API call). Based on a preset parsing method, the file request parameters are parsed to extract the template file identifier, data format identifier, and filtering conditions from the file request parameters. The template file identifier uniquely identifies the PDF template to be processed; the data format identifier specifies the data format type (e.g., JSON, XML, etc.); and the filtering conditions are conditions used for content filtering. The PDF template file to be processed is located based on the template file identifier, and then a corresponding parsing tool (e.g., a JSON parser, an XML parser, etc.) is called based on the data format identifier. The parsing tool reads the text content of the PDF template file to be processed and filters the text content of the PDF template file to be processed based on the filtering conditions, retaining only the text content that meets the conditions. For example, only the text in the "Insurance Amount Clause" section of the PDF template file to be processed is extracted. The filtered content is then converted into a structured data source object, which is typically a specific data structure in a programming language. Through the above steps, the file content of the filtered PDF template file to be processed is converted into a unified data source object, thereby enabling flexible acquisition and efficient processing of diverse data, laying the foundation for subsequent rapid replacement of special characters.

[0029] In an embodiment of the present application, by obtaining the PDF template file to be processed and the data source object corresponding to the PDF template file to be processed, special characters can be quickly replaced subsequently, thereby improving the efficiency of replacing special characters and ensuring the overall quality of the PDF template file.

[0030] S202: Parse the PDF template file to be processed to determine a file template element, wherein the file template element includes a markup attribute and a value attribute, the markup attribute is used to identify the element type, and the value attribute is used to set a data expression.

[0031] In step S202, the markup attribute is used to specify the markup type or rendering method of the template element, that is, to determine how the element content should be parsed and processed, and the value attribute is used to specify the content value or data expression of the template element, that is, the actual data that the element will eventually display. First, the PDF template file to be processed needs to be parsed, that is, the form fields, comments, page headers, page text content, footers, etc. of the PDF template are analyzed through specific tools or algorithms (such as PDF libraries or OCR technology) to determine the file template elements. PDF template files are essentially binary files based on page description languages ​​(such as PostScript), containing elements such as text, images, and vector graphics. The purpose of parsing is to extract dynamic elements in the template (such as placeholders, form fields, etc.) for subsequent replacement of special characters.

[0032] In one embodiment of the invention, parsing the PDF template file to be processed to determine the file template elements includes: Obtaining primitives and primitive values ​​of the primitives from text information in the to-be-processed PDF template file by using a regular expression or an HTML parser; A file template element is determined according to the primitive and the primitive value of the primitive.

[0033] Specifically, a primitive refers to a program segment consisting of several instructions that implement a specific function and cannot be interrupted during execution. The value of a primitive refers to the specific instruction content of the several instructions that make up the primitive. For example, the primitive in this embodiment may include a character type rendering instruction and a text font rendering instruction. Accordingly, the value of the primitive may include the value corresponding to the character type rendering instruction (e.g., rendering a character as a special character) and the value of the text font rendering instruction (e.g., rendering text as Songti). In other words, the text information in the to-be-processed PDF template file may be a PDF instruction. The PDF instruction can be directly extracted from the text information included in the to-be-processed PDF template file, and the primitive and its primitive value are determined based on the extracted PDF instruction. A file template element generally refers to the basic component or element that constitutes a file template, including: a title / title area, a placeholder, and a style definition. After obtaining the primitive and its primitive value from the text information, the file template element is determined based on the primitive and its primitive value by establishing an association between the primitive and the template element type, position, and format. For example, if the primitive includes a "character type rendering instruction," the file template element is determined to be a character element. Through this method, key information can be efficiently extracted from PDF template files to obtain file template elements, which can be applied to scenarios that require efficient and accurate processing of dynamic documents.

[0034] In this embodiment, by parsing the PDF template file to be processed, the file template elements can be quickly and accurately determined, ensuring that the imported data is consistent with the template content, so as to provide an accurate data basis for subsequent rapid replacement of special characters.

[0035] S203: Determine the display value of the document template element according to the data expression in the value attribute in the document template element and the data source object.

[0036] In step S203, the data expression follows the format of $object.field.subfield, and the data expression needs to be parsed first. Specifically, the data expression prefix $ is removed, and then it is split by . to obtain a field path list. For example, for the expression $ABC, after processing, a list of ["A", "B"B", "C"] will be obtained, and this list will serve as a guide for accessing the attributes of each level of the data source object. After obtaining the field path list, the object attributes are recursively accessed in the data source object based on the field path list. Starting from the top level of the data source object, the corresponding sub-object is found according to the first element of the field path list, and then based on the sub-object, the search continues according to the next element of the field path list, and so on, until the last element of the field path list is accessed. The value obtained at this time is the display value of the template element. Among them, the data expression in the value attribute in the file template element is a dynamic instruction embedded in the template element, which is used to specify how to obtain or calculate the display value from the data source.

[0037] In one embodiment of the invention, determining the display value of the document template element according to the data expression in the value attribute of the document template element and the data source object includes: Remove the prefix from the data expression in the value attribute in the file template element and split it to obtain a field path list, wherein the field path list is a guide for accessing attributes of each level of the data source object; According to the field path list, object properties are recursively accessed in the data source object to obtain the display value of the file template element.

[0038] Specifically, the data expression in the value attribute in the file template element is prefixed and split to obtain a field path list, where the field path list is a guide for accessing attributes at each level of the data source object. For example, the data expression in the value attribute is ${user.address.city}.

[0039] Removing the expression markers "${" and "}" yields the pure path string "user.address.city." This is then split into the field list "user," "address," and "city" using the "." separator. The final value is then retrieved from the data source object layer by layer according to the field path list. Starting from the root level of the data source object, the sub-attributes are accessed sequentially according to the order of the field path list. If the current level is still an object (such as a nested dictionary), the access continues downwards. If the value is a final value (such as a string or number), the recursion terminates and the result is returned. Furthermore, if an intermediate level does not exist or has a type mismatch (such as attempting to retrieve an attribute on a string), the recursion terminates and returns an error or the default value. This continues until the end of the path list is reached, at which point the attribute value at the current level is returned as the display value. The final value retrieved recursively is then populated into the corresponding element in the file template for display or output (such as generating reports or HTML pages). This demonstrates that by converting data expressions into field paths and recursively accessing the data source object, the display values ​​of file template elements can be accurately and efficiently generated, improving the readability and maintainability of the template file.

[0040] In this embodiment, the display value of the file template element can be generated dynamically, accurately and efficiently based on the data expression in the value attribute in the file template element and the data source object corresponding to the PDF template file to be processed, thereby realizing dynamic filling and display of document content while reducing maintenance costs, so as to provide strong data support for the subsequent improvement of the efficiency of special character replacement.

[0041] S204: Determine, based on the display value of the document template element, whether the markup attribute of the document template element is an HTML element.

[0042] In step S204, HTML elements are the basic components of Hypertext Markup Language (HTML) documents, used to define the structure and content of web pages. The display value is the content of the template element ultimately rendered in the PDF (e.g., text, numbers, dates, etc.). For example, "Policy Type, Illness Insurance" or "2023-10-25." The markup attribute specifies the markup language type of the display value (e.g., HTML, plain text). Based on the display value of the file template element, a determination is made as to whether the markup attribute of the file template element is an HTML element. If the markup attribute of the file template element is an HTML element, step S205 is executed to replace the special characters using a regular expression based on pre-configured special character mappings to generate target characters corresponding to the PDF template file to be processed. If the markup attribute of the file template element is not an HTML element, the steps of the special character replacement method are not performed. For example, if markup="html" is set, the display value is considered to be an HTML element. If markup="text" is set or is undefined, the display value is considered to be plain text.

[0043] In this embodiment, by judging whether the markup attribute of the file template element is an HTML element based on the display value of the file template element, special characters can be quickly replaced subsequently, thereby improving the printing platform's processing of HTML-modified PDF content, so that electronic policy documents can be generated in a timely and correct manner.

[0044] S205: If the markup attribute of the file template element is an HTML element, the special characters are replaced by regular expressions according to a pre-calibrated mapping relationship to generate target characters corresponding to the PDF template file to be processed, wherein the mapping relationship is a correspondence between the pre-calibrated special characters and the target characters.

[0045] In step S205, after the markup attribute of the file template element is an HTML element, the correspondence between pre-marked special characters and target characters is determined, that is, characters with special meanings in HTML (such as <, >, &) are mapped to corresponding target characters (such as <;, >, &). Since some characters in HTML (such as <, >, &) may cause format errors or security risks in PDF rendering, it is necessary to use regular expressions to match special characters in HTML content and replace them with safe characters based on the mapping relationship. A pre-configured special character mapping table (such as {"<": "<;", ">": ">;"}) is read, and a regular expression (such as / [&<>] / g) is used to match special characters in the HTML string. The matched characters are replaced with target characters according to the mapping table, and the replaced HTML characters are output. The replaced characters are then injected into the corresponding elements of the PDF template for subsequent parsing by a rendering engine (such as PDFKit or iText) to generate the final PDF document. In this way, the processed HTML content can be consistent with the expected content, and by maintaining the mapping relationship of special characters, the regular expression for special character processing can be dynamically changed, and the dynamic processing of relevant special characters can be adjusted or added at any time.

[0046] In one embodiment of the invention, before replacing the special characters by regular expressions to generate target characters corresponding to the PDF template file to be processed, the following steps are included: Obtaining attribute information of the PDF template file to be processed; According to the attribute information, determining whether the file format of the to-be-processed PDF template file is a preset format; If the file format of the to-be-processed PDF template file is not a preset format, a regular expression corresponding to the attribute information of the to-be-processed PDF template file is matched according to the preset format rule.

[0047] Specifically, in actual applications, different files have different contents that need to be processed as the business develops at different stages. By obtaining the attribute information of the PDF template file to be processed and the data source object corresponding to the PDF template file to be processed, and then judging whether the file format of the PDF template file to be processed is the preset format according to the attribute information of the PDF template file to be processed, the file format of the PDF template file to be processed includes multiple formats, such as .doc format, .txt format, and .pdf format. In order to reduce the additional workload caused by developing different processing logic codes for files of different formats, when the file format of the PDF template file to be processed is not the preset format, the file format is converted to the preset format. The file of the preset format has a corresponding regular expression for matching, and then the regular expression corresponding to the attribute information of the PDF template file to be processed is matched according to the preset format rules, thereby realizing the processing of files of different file formats, determining the regular expressions required for files with different attribute information at this time, and improving the processing efficiency of files of different file formats.

[0048] In another embodiment, if the attribute information includes the creation time of the file, then the time interval between the current time and the creation time of the PDF template file to be processed is determined, and the regular expression corresponding to the time interval is directly obtained. Then, files with different creation times are processed accordingly according to different regular expressions. For example, if the time interval between the creation time of the policy file and the current time is greater than 6 months, the matching regular expression A masks the policy text content "policy price" and "policy type" in the policy file based on regular expression A. When the time interval is less than 6 months, the matching regular expression B masks the policy text content "policy price" in the policy file based on regular expression B, and does not mask the policy text content "policy type".

[0049] In one embodiment of the invention, the special characters are replaced by regular expressions according to a pre-calibrated mapping relationship to generate target characters corresponding to the PDF template file to be processed, including: Format the text content of the PDF template file to be processed into a string array; Filter the string array according to a regular expression to obtain special characters in the string array that meet the requirements of the regular expression; According to the pre-calibrated correspondence between special characters and target characters, the special characters are replaced with corresponding target characters to generate target characters corresponding to the PDF template file to be processed.

[0050] Specifically, when it is necessary to process the content contained in the PDF template file to be processed, such as the policy personnel information and policy content information stored in the policy file, specific information needs to be processed. The processing includes mask processing, replacement processing, and deletion processing. First, the PDF template file to be processed containing text content is obtained, and then the text of the PDF template file to be processed is pre-processed, that is, the text content of the PDF template file to be processed is formatted, that is, the text content of the PDF template file to be processed is processed by calling a content analysis tool such as tika, so that the text content of the PDF template file to be processed is formatted into strings one by one, and then the collection of these strings is defined as a string array.

[0051] A configuration file is pre-set, in which a regular expression is configured. The configuration file is an XML configuration file. A regular expression is formulated in the XML configuration file. A regular expression is a logical formula for string operations, including operations on common characters (for example, letters between a and z) and special characters (called "metacharacters"). A "regular string" is composed of some pre-defined characters and combinations of these characters. The strings are filtered through the "regular string". Specifically, according to the rules of the XML configuration file, the string array is filtered using the regular expression, and special characters that meet the regular expression rules are found from the string array. For example, if the policy amount range is "<1 million", the special character to be found is "<", and these special characters are defined as strings to be processed. The regular expression includes different conditional rules, and different strings are matched according to different conditional rules. Furthermore, special characters that meet multiple conditional rules can also be matched according to the combination of multiple conditional rules. For example, a conditional rule included in the regular expression is to filter out strings containing the character "&&". By filtering the strings in the string array according to the regular expression, special characters containing the character "&&" can be filtered out.

[0052] After obtaining the special characters, the special characters are replaced according to the pre-marked correspondence between the special characters and the target characters, and the special characters are replaced with the corresponding target characters to generate the target characters corresponding to the PDF template file to be processed. The replacement includes changing the characters, for example, replacing the character a with the character b, that is, replacing the character "<" with less than; the replacement also includes deleting the characters, that is, replacing the character a with the empty character, and the replacement also includes adding the characters, that is, replacing the character a with the character ab; after replacing the special characters, the target characters corresponding to the PDF template file to be processed are generated. In this embodiment, the replaced characters are defined as the target characters.

[0053] For example, in the financial insurance industry, insurance policies or contracts usually need to dynamically generate PDF files based on customer information, insurance terms, product parameters, etc. The original insurance information is as follows: insurance policy number: 2024-123456; insured name: Zhang San; insurance amount: 100,000 yuan; exemption clause: Insurance companies are not liable for losses caused by force majeure factors such as war and earthquakes. Special characters are "<, >" with predefined mappings: < corresponds to <; > corresponds to >; & corresponds to &. Replace the matching special characters < with <; > with >. The resulting string becomes: "Disclaimer Clause: ; Insurance companies are not liable for losses caused by force majeure factors such as war and earthquakes." This avoids ambiguity in clauses caused by character parsing errors. When batch-generating insurance policies, automated character processing can quickly process large amounts of insurance information, reduce manual intervention, improve business processing efficiency, provide clear and accurate insurance contract documents, and enhance customer trust.

[0054] In this embodiment, upon determining that the markup attribute of a file template element is an HTML element, the special characters are replaced using regular expressions based on the correspondence between pre-calibrated special characters and target characters, generating the target characters corresponding to the PDF template file to be processed. This ensures the security and display consistency of the PDF template file, improves the printing platform's processing of HTML-modified PDF content, and enables the timely and correct generation of electronic policy documents. By improving the processing of HTML special characters, the correctness of the policy content is guaranteed (ensuring 100% accurate presentation of unstructured data such as special symbols and mathematical formulas in the policy terms), thereby protecting the legality of the contract, reducing the company's financial losses, and improving customer satisfaction.

[0055] In summary, the present invention provides a special character replacement method, device, equipment and medium. By obtaining a PDF template file to be processed and a data source object corresponding to the PDF template file to be processed, the PDF template file to be processed is parsed to determine the file template element, wherein the file template element includes a markup attribute and a value attribute, the markup attribute is used to identify the element type, and the value attribute is used to set a data expression. According to the data expression in the value attribute in the file template element and the data source object, the display value of the file template element is determined. According to the display value of the file template element, it is judged whether the markup attribute of the file template element is an HTML element. If the markup attribute of the file template element is an HTML element, the special characters are replaced by regular expressions according to a pre-calibrated mapping relationship to generate target characters corresponding to the PDF template file to be processed, wherein the mapping relationship is a pre-calibrated correspondence between special characters and target characters. It can be seen that this application determines whether the markup attribute of the file template element is an HTML element based on the display value of the file template element. If so, the special characters are replaced by regular expressions based on the correspondence between the pre-marked special characters and the target characters to generate the target characters corresponding to the PDF template file to be processed. The special characters can be replaced accurately, which ensures the correctness of the policy content, makes the generated text more in line with user expectations, and effectively improves the user experience.

[0056] See also Figure 3 , Figure 3 Schematic diagram of the structure of the special character replacement device provided by the embodiment of the present invention. The special character replacement device corresponds to the special character replacement method in the above embodiment. Figure 2 as well as Figure 2 For the convenience of explanation, only the parts related to this embodiment are shown. Figure 3 The special character replacing device 30 includes: an acquisition module 31, a parsing module 32, a determination module 33, a judgment module 34, and a generation module 35.

[0057] An acquisition module 31 is configured to acquire a PDF template file to be processed and a data source object corresponding to the PDF template file to be processed; A parsing module 32 is configured to parse the PDF template file to be processed and determine a file template element, wherein the file template element includes a markup attribute and a value attribute, the markup attribute is used to identify the element type, and the value attribute is used to set a data expression; A determination module 33, configured to determine a display value of the document template element according to a data expression in a value attribute of the document template element and the data source object; A judging module 34, configured to judge whether the markup attribute of the file template element is an HTML element according to the display value of the file template element; The generation module 35 is used to replace the special characters by regular expressions according to a pre-calibrated mapping relationship if the markup attribute of the file template element is an HTML element, so as to generate target characters corresponding to the PDF template file to be processed, wherein the mapping relationship is a correspondence between the pre-calibrated special characters and the target characters.

[0058] Optionally, the acquisition module 31 is specifically configured to: Receiving a file printing request initiated by a client, wherein the file printing request includes file request parameters, and the request parameters include a template file identifier and a template file type; Generate a complete template file path by splicing according to the template file identifier, template file type, predefined template file storage path and naming rules; Determine whether the template file path meets the preset file path condition; If the template file path meets the preset file path condition, the PDF template file to be processed is obtained.

[0059] Optionally, the parsing module 32 is specifically configured to: Obtaining primitives and primitive values ​​of the primitives from text information in the to-be-processed PDF template file by using a regular expression or an HTML parser; A file template element is determined according to the primitive and the primitive value of the primitive.

[0060] Optionally, the determining module 33 is specifically configured to: Receiving a file print request initiated by a client, wherein the file print request includes file request parameters, and the request parameters include a template file identifier, a data format identifier, and a filtering condition; Locating the PDF template file to be processed according to the template file identifier, calling a corresponding parsing tool according to the data format identifier, reading the text content of the PDF template file to be processed, and filtering the text content of the PDF template file to be processed in combination with the filtering condition; Convert the filtered file content of the PDF template file to be processed into a structured data source object.

[0061] Optionally, the determining module 33 is further configured to: Remove the prefix from the data expression in the value attribute in the file template element and split it to obtain a field path list, wherein the field path list is a guide for accessing attributes of each level of the data source object; According to the field path list, object properties are recursively accessed in the data source object to obtain the display value of the template element.

[0062] Optionally, the generating module 35 is previously specifically used to: Obtaining attribute information of the PDF template file to be processed; According to the attribute information, determining whether the file format of the to-be-processed PDF template file is a preset format; If the file format of the to-be-processed PDF template file is not a preset format, a regular expression corresponding to the attribute information of the to-be-processed PDF template file is matched according to the preset format rule.

[0063] Optionally, the generating module 35 is specifically configured to: Format the text content of the PDF template file to be processed into a string array; Filter the string array according to a regular expression to obtain special characters in the string array that meet the requirements of the regular expression; According to the pre-calibrated correspondence between special characters and target characters, the special characters are replaced with corresponding target characters to generate target characters corresponding to the PDF template file to be processed.

[0064] It should be noted that the information interaction, execution process and other contents between the above-mentioned units are based on the same concept as the embodiment of the method of the present invention. Their specific functions and technical effects can be found in the method embodiment part and will not be repeated here.

[0065] Figure 4 This is a schematic diagram of the structure of a computer device provided by an embodiment of the present invention. Figure 4 As shown, the computer device of this embodiment includes: at least one processor ( Figure 4 Only one is shown), a memory, and a computer program stored in the memory and executable on at least one processor, wherein when the processor executes the computer program, the steps in any of the above-mentioned special character replacement method embodiments are implemented.

[0066] The computer device may include, but is not limited to, a processor and a memory. Figure 4 The above is merely an example of a computer device and does not constitute a limitation on the computer device. The computer device may include more or fewer components than shown in the figure, or a combination of certain components, or different components. For example, it may also include a network interface, a display screen, and an input system.

[0067] In one embodiment, a computer-readable storage medium is provided. When instructions in the computer-readable storage medium are executed by a processor in a computer device, the computer device is enabled to perform the steps of any embodiment of a special character replacement method disclosed in the present invention, which are not repeated here. The computer-readable storage medium can be either non-volatile or volatile.

[0068] The processor may be a CPU, other general-purpose processors, a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field-programmable gate array (FPGA), other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. A general-purpose processor may be a microprocessor or any conventional processor.

[0069] Memory includes readable storage media, internal memory, and the like. Internal memory can be the internal memory of a computer device, providing an environment for the operation of the operating system and computer-readable instructions stored in the readable storage medium. The readable storage medium can be the computer device's hard drive. In other embodiments, it can also be an external storage device, such as a plug-in hard drive, a Smart Media Card (SMC), a Secure Digital (SD) card, or a flash memory card. Furthermore, memory can include both the computer device's internal storage unit and external storage devices. Memory is used to store the operating system, associated applications, a boot loader, data, and other programs, such as the program code of a computer program. Memory can also be used to temporarily store data that has been output or is about to be output.

[0070] It is understood by those skilled in the art that all or part of the processes in the above-mentioned embodiments can be implemented by instructing the relevant hardware through a computer program. The computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to memory, storage, database or other media used in the embodiments provided in this application may include non-volatile and / or volatile memory. Non-volatile memory may include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM) or flash memory. Volatile memory may include random access memory (RAM) or external cache memory. By way of illustration and not limitation, RAM is available in many forms such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), double data rate SDRAM (DDRSDRAM), enhanced SDRAM (ESDRAM), Synchronous Link DRAM (SLDRAM), Rambus direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM), etc.

[0071] Those skilled in the art can clearly understand that for the sake of convenience and brevity in description, only the division of the above-mentioned functional units and modules is used as an example for illustration. In actual applications, the above-mentioned functions can be distributed and completed by different functional units and modules as needed, that is, the internal structure of the system can be divided into different functional units or modules to complete all or part of the functions described above. The functional units and modules in the embodiment can be integrated into one processing unit, or each unit can exist physically alone, or two or more units can be integrated into one unit. The above-mentioned integrated unit can be implemented in the form of hardware or in the form of a software functional unit. In addition, the specific names of the functional units and modules are only for the convenience of distinguishing each other and are not used to limit the scope of protection of the present invention. The specific working process of the units and modules in the above-mentioned system can refer to the corresponding process in the aforementioned method embodiment, which will not be repeated here. If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium.

[0072] The above-described embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit the same. Although the present invention has been described in detail with reference to the aforementioned embodiments, persons skilled in the art should understand that the technical solutions described in the aforementioned embodiments may still be modified, or some of the technical features thereof may be replaced by equivalents. Such modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the various embodiments of the present invention, and should all be included in the scope of protection of the present invention.

Claims

1. A special character replacement method, characterized in that: include: Obtain the PDF template file to be processed and the data source object corresponding to the PDF template file to be processed; Parsing the PDF template file to be processed to determine a file template element, wherein the file template element includes a markup attribute and a value attribute, the markup attribute is used to identify the element type, and the value attribute is used to set a data expression; Determine the display value of the file template element according to the data expression in the value attribute in the file template element and the data source object; Determining, based on the display value of the file template element, whether the markup attribute of the file template element is an HTML element; If the markup attribute of the file template element is an HTML element, the special characters are replaced by regular expressions according to a pre-marked mapping relationship to generate target characters corresponding to the PDF template file to be processed, wherein the mapping relationship is a correspondence between the pre-marked special characters and the target characters.

2. The special character replacement method according to claim 1, wherein: The obtaining of the PDF template file to be processed and the data source object corresponding to the PDF template file to be processed includes: Receiving a file printing request initiated by a client, wherein the file printing request includes file request parameters, and the request parameters include a template file identifier and a template file type; Generate a complete template file path by splicing according to the template file identifier, template file type, predefined template file storage path and naming rules; Determine whether the template file path meets the preset file path condition; If the template file path meets the preset file path condition, the PDF template file to be processed is obtained.

3. The special character replacement method according to claim 1, wherein: The step of parsing the PDF template file to be processed and determining the file template elements includes: Obtaining primitives and primitive values ​​of the primitives from text information in the to-be-processed PDF template file by using a regular expression or an HTML parser; A file template element is determined according to the primitive and the primitive value of the primitive.

4. The special character replacement method according to claim 1, wherein: The step of obtaining the data source object corresponding to the PDF template file to be processed includes: Receiving a file print request initiated by a client, wherein the file print request includes file request parameters, and the request parameters include a template file identifier, a data format identifier, and a filtering condition; Locating the PDF template file to be processed according to the template file identifier, calling a corresponding parsing tool according to the data format identifier, reading the text content of the PDF template file to be processed, and filtering the text content of the PDF template file to be processed in combination with the filtering condition; Convert the filtered file content of the PDF template file to be processed into a structured data source object.

5. The special character replacement method according to claim 1, wherein: The determining the display value of the file template element according to the data expression in the value attribute in the file template element and the data source object includes: Remove the prefix from the data expression in the value attribute in the file template element and split it to obtain a field path list, wherein the field path list is a guide for accessing attributes of each level of the data source object; According to the field path list, object properties are recursively accessed in the data source object to obtain the display value of the template element.

6. The special character replacement method according to claim 1, wherein: Before replacing the special characters by regular expressions to generate target characters corresponding to the PDF template file to be processed, the method includes: Obtaining attribute information of the PDF template file to be processed; According to the attribute information, determining whether the file format of the to-be-processed PDF template file is a preset format; If the file format of the to-be-processed PDF template file is not a preset format, a regular expression corresponding to the attribute information of the to-be-processed PDF template file is matched according to the preset format rule.

7. The special character replacement method according to claim 1, wherein: The step of replacing the special characters by regular expressions according to the pre-calibrated mapping relationship to generate target characters corresponding to the PDF template file to be processed includes: Format the text content of the PDF template file to be processed into a string array; Filter the string array according to a regular expression to obtain special characters in the string array that meet the requirements of the regular expression; According to the pre-calibrated correspondence between special characters and target characters, the special characters are replaced with corresponding target characters to generate target characters corresponding to the PDF template file to be processed.

8. A special character replacement device, characterized in that: include: An acquisition module is used to acquire a PDF template file to be processed and a data source object corresponding to the PDF template file to be processed; a parsing module, configured to parse the PDF template file to be processed and determine a file template element, wherein the file template element includes a markup attribute and a value attribute, the markup attribute is used to identify the element type, and the value attribute is used to set a data expression; a determination module, configured to determine a display value of the file template element according to a data expression in a value attribute of the file template element and the data source object; a judging module, configured to judge whether the markup attribute of the file template element is an HTML element according to the display value of the file template element; A generation module is used to replace the special characters by regular expressions according to a pre-calibrated mapping relationship if the markup attribute of the file template element is an HTML element, so as to generate target characters corresponding to the PDF template file to be processed, wherein the mapping relationship is a correspondence between the pre-calibrated special characters and the target characters.

9. A computer device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein: When the processor executes the computer program, the special character replacement method according to any one of claims 1 to 7 is implemented.

10. A computer-readable storage medium storing a computer program, characterized in that: When the computer program is executed by a processor, the special character replacement method according to any one of claims 1 to 7 is implemented.