JSON entry intelligent translation method and system based on AI agent
By performing corpus injection and AI intelligent body correction when translating JSON entries, the problems of JSON format destruction, disordered order and inaccurate professional vocabulary in the prior art are solved, and the translation results with high accuracy and consistency are achieved.
Patent Information
- Application Number
- CN202510047914.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-01-13
- Publication Date
- 2025-02-18
AI Technical Summary
The prior art is prone to destroy the JSON format when translating JSON entries. AI translation may lead to confusing order and missing data, inaccurate professional vocabulary translation, inability to freely translate, and the consistency of high-frequency vocabulary translation is difficult to guarantee.
The intelligent translation method of JSON entry based on AI agents is adopted, and self-built professional terms and free-translated phrases are injected in advance through corpus injection processing to ensure translation accuracy, and the results are corrected by AI agents after translation.
It effectively overcomes problems such as JSON format destruction, disordered sequence, and inaccurate professional vocabulary, ensures the accuracy and consistency of translation results, and supports controllable free translation.
Smart Images

Figure CN119476317A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer technology, and in particular to a JSON entry intelligent translation method and system based on an AI agent. Background Art
[0002] In the process of transforming the original Chinese site into an international site that supports multi-language switching, it is necessary to extract a large number of Chinese term files in JSON object format and then translate them into corresponding languages. The existing translation platform has poor translation effect, mainly with the following problems: 1. Ordinary machine translation often destroys the JSON format.
[0003] 2. When AI translation translates multiple pieces of data at one time, the order may be messed up or one or more pieces of data may be missed, resulting in the loss of the correspondence between the key and value of the JSON object.
[0004] 3. The translation of professional vocabulary is inaccurate and cannot be consistent with the self-built professional vocabulary.
[0005] 4. Unable to perform controllable free translation. For example, the Chinese word is car wash customer, and the corresponding English or other language desired meaning is customer created quickly.
[0006] 5. The translation consistency of high-frequency words cannot be guaranteed. Summary of the invention
[0007] One or more embodiments of this specification describe a method and system for intelligent translation of JSON terms based on an AI agent, which can at least partially overcome the above-mentioned technical problems.
[0008] In a first aspect, a JSON term intelligent translation method based on an AI agent is provided, the method comprising: Get the JSON entry to be translated; Based on the target language into which the JSON term needs to be translated, selecting a corpus that records corpus data in the same language as the original language of the JSON term and translations of the corpus data in the target language; Performing corpus injection processing on the JSON entry: matching the JSON entry with each corpus data in the corpus respectively, and if there is corpus data matching the JSON entry, replacing the matching content in the JSON entry with the translation of the corresponding corpus data; Constructing a first prompt word based on the JSON term after the corpus injection processing and a preset translation rule to prompt the AI agent to translate the JSON term to obtain a first translation result; A second prompt word is constructed based on the JSON entry after the corpus injection processing, the first translation result and the translation rule to prompt the AI agent to correct the first translation result to obtain a second translation result.
[0009] As an optional implementation of the method of the first aspect, obtaining the JSON term to be translated specifically includes: Get the original file to be translated; If the original file is in JSON format, the original file is directly used as the JSON entry; If the original file is not in JSON format, the original file is read line by line as a text array, and then the text array is converted into the JSON entry.
[0010] As an optional implementation of the method of the first aspect, the method further includes: Before the JSON terms are subjected to corpus injection processing, a high-frequency vocabulary statistical analysis is performed on the JSON terms, and the analysis results are displayed to the user, so that the user can adjust the corpus data in the corpus based on the analysis results.
[0011] As an optional implementation of the method of the first aspect, the method further includes: When replacing the matching content in the JSON entry with the translation of the corresponding corpus data, a special character is spliced at both ends of the translation respectively; After the JSON entry is processed by corpus injection, if two consecutive special characters appear in the JSON entry, the two special characters are replaced by spaces; if a single special character appears in the JSON entry and the left and right characters are both in the target language, the special character is replaced by a space.
[0012] In the second aspect, a JSON term intelligent translation system based on an AI agent is provided, including: A data acquisition module configured to acquire JSON terms to be translated; The corpus injection module is configured to select a corpus based on the target language into which the JSON term needs to be translated, wherein the corpus records the corpus data in the same language as the original language of the JSON term and the translation of the corpus data in the target language; perform corpus injection processing on the JSON term: match the JSON term with each corpus data in the corpus respectively, and if there is corpus data matching the JSON term, replace the matching content in the JSON term with the translation of the corresponding corpus data; An AI translation module is configured to construct a first prompt word based on the JSON term after the corpus injection processing and a preset translation rule to prompt the AI agent to translate the JSON term to obtain a first translation result; The correction module is configured to construct a second prompt word based on the JSON entry after the corpus injection processing, the first translation result and the translation rule to prompt the AI agent to correct the first translation result to obtain a second translation result.
[0013] As an optional implementation manner of the system according to the second aspect, the data acquisition module includes: A text content reading and writing module is configured to check the format of the original file to be translated. If the original file is in JSON format, the content of the original file is directly read and directly parsed into the JSON terms; if the original file is not in JSON format, the original file is read line by line as a text array; The format conversion module is configured to convert the text array into the JSON entry.
[0014] As an optional implementation manner of the system according to the second aspect, the system further includes: The high-frequency vocabulary statistics module is configured to perform high-frequency vocabulary statistics analysis on the JSON terms before performing corpus injection processing on the JSON terms, and display the analysis results to the user so that the user can adjust the corpus data in the corpus based on the analysis results.
[0015] As an optional implementation manner of the system according to the second aspect, the corpus injection module is further used for: When replacing the matching content in the JSON entry with the translation of the corresponding corpus data, a special character is spliced at both ends of the translation respectively; After the JSON entry is processed by corpus injection, if two consecutive special characters appear in the JSON entry, the two special characters are replaced by spaces; if a single special character appears in the JSON entry and the left and right characters are both in the target language, the special character is replaced by a space.
[0016] In a third aspect, a computer-readable storage medium is provided, on which a computer program is stored, characterized in that when the computer program is executed by a processor, the processor executes the above-mentioned AI agent-based JSON term intelligent translation method.
[0017] In a fourth aspect, an electronic device is provided, including: One or more processors; and a memory associated with the one or more processors, the memory being used to store program instructions, which, when read and executed by the one or more processors, enable the electronic device to execute the above-mentioned AI-agent-based JSON term intelligent translation method.
[0018] Beneficial effects: One or more embodiments of this specification provide a method for intelligent translation of JSON terms based on an AI agent. This method injects pre-text data into JSON terms before translation. This method can inject self-built professional terms, industry vocabulary, paraphrase phrases and other text data in advance to ensure the accuracy of translation. After translation, this method uses an AI agent to correct the translation results, further ensuring the accuracy of the translation results.
[0019] Correspondingly, the AI agent-based JSON term intelligent translation system described in the present invention also has the above-mentioned technical effects. BRIEF DESCRIPTION OF THE DRAWINGS
[0020] In order to more clearly illustrate the embodiments of this specification or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are some embodiments of this specification. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.
[0021] Figure 1 It is a flowchart of a JSON term intelligent translation method based on an AI agent involved in an embodiment of this specification.
[0022] Figure 2 It is a structural diagram of a JSON term intelligent translation system based on an AI agent involved in an embodiment of this specification. DETAILED DESCRIPTION
[0023] First of all, it should be noted that the terms used in the embodiments of the present invention are only for the purpose of describing specific embodiments, and are not intended to limit the present invention. The singular forms "a", "the" and "the" used in the embodiments of the present invention and the appended claims are also intended to include plural forms, unless the context clearly indicates otherwise.
[0024] In order to enable those skilled in the art to better understand the technical solutions in this specification, the technical solutions in the embodiments of this specification will be clearly and completely described below in conjunction with the drawings in the embodiments of this specification. Obviously, the described embodiments are only part of the embodiments of this specification, not all of the embodiments. Therefore, it should be recognized by those skilled in the art that various changes and modifications can be made to the embodiments described herein without departing from the scope and spirit of the present invention. Similarly, for the sake of clarity and conciseness, the description of well-known functions and structures is omitted in the following description.
[0025] It should be noted that: in other embodiments, the steps of the corresponding method are not necessarily performed in the order shown and described in this specification. In some other embodiments, the steps included in the method may be more or less than those described in this specification. In addition, a single step described in this specification may be decomposed into multiple steps for description in other embodiments; and multiple steps described in this specification may be combined into a single step for description in other embodiments.
[0026] The following will further describe in detail the AI-agent-based JSON term intelligent translation method and system described in the embodiments of this specification in conjunction with the accompanying drawings and specific embodiments of the specification, but this detailed description does not constitute a limitation on the embodiments of this specification.
[0027] In some embodiments, a JSON term intelligent translation method based on an AI agent is provided, such as Figure 1 As shown, the method includes steps S100 to S108.
[0028] S100: Obtain JSON terms to be translated.
[0029] The format of the original file to be translated may not necessarily be JSON format. Therefore, before translation, you can read the original file first and check the format of the original file. If the original file is in JSON format, read the content directly and parse it into JSON entries directly. If the original file is not in JSON format, read the content of the original file line by line as a text array, and then convert the text array to obtain the above JSON entries.
[0030] Take the original file selected from the i18n text word library as an example. The i18n text word library supports file storage in YAML, TOML, properties and other formats. The common i18n text word library is composed of a unique keyword (key) corresponding to a text content (value) and connected by "=". Therefore, when converting the original file in i18n to JSON format, you can first read the text array content of the original file, and then perform secondary processing to split each line of entries into two sections through the first "=" sign, and generate a file cache by mapping the key on the left side of "=" and the subscript of the current entry, which is used for conversion back to the source format after the translation is completed. The text content to the right of "=" is the text content to be translated. The subscript is used as the key of the JSON object and the text content is used as the value of the JSON object to obtain the JSON entry.
[0031] S102: Select a corpus based on the target language into which the JSON terms need to be translated.
[0032] The above corpus records the corpus data in the same language as the original language of the JSON term and the translation of the corpus data in the target language. In other words, if the JSON term to be translated is a Chinese term, and the translation task is to translate the Chinese JSON term into an English JSON term, then the selected corpus should contain the Chinese corpus data and the English translation corresponding to the corpus data.
[0033] When constructing the above-mentioned corpus, you can include self-built professional terms, industry vocabulary, paraphrase phrases and other materials into the corpus according to the needs of the translation field, so as to improve the accuracy of professional vocabulary translation. After such a design, the professional vocabulary in the translation results can be consistent with the self-built professional vocabulary, and the controllability of the paraphrase results can be guaranteed.
[0034] In some embodiments, after determining the corpus, the JSON entry to be translated can also be subjected to high-frequency vocabulary statistical analysis, and the high-frequency vocabulary appearing in the JSON entry can be found according to the analysis results, and then the corpus data stored in the corpus can be compared to see whether these high-frequency words have corresponding corpus data in the corpus. If not, they can be manually supplemented. Specifically, the open source framework jieba can be used to perform high-frequency vocabulary statistics on the content of the current JSON entry, and de-duplicate processing can be performed against the existing corpus, and the remaining high-frequency words can be arranged in reverse order of word frequency to generate a report. At this time, the report can be displayed to the user, waiting for the user to intervene and determine whether the corpus data needs to be supplemented to the corpus. Through this design, users can be assisted in maintaining the corpus in advance to ensure the consistency of the overall translation.
[0035] S104: Perform corpus injection processing on the JSON entry: match the JSON entry with each corpus data in the corpus respectively, and if there is corpus data matching the JSON entry, replace the matching content in the JSON entry with the translation of the corresponding corpus data.
[0036] When performing corpus injection processing on JSON terms, all corpus data in the corpus can be read first and sorted in order from long to short. Taking the original file to be translated selected from the i18n lexicon as an example, the text content (value) of the JSON term is traversed, and for each text content (value), it is matched with the corpus data one by one in order from long to short. If a certain corpus data is matched and contained in the text content (value), the sentence / vocabulary in the text content (value) is replaced with the translation of the target language of the corpus data until all the corpus data is traversed.
[0037] In this process, adjacent corpora may be injected. In some implementations, spaces can be added in the middle to avoid the problem of two words being connected and difficult to distinguish. Specifically, when inserting corpora into the text content (value) of a JSON entry, a special character can be spliced at both ends of the inserted translation, for example: \u270E. After the corpus injection processing operation is completed, if two special characters appear in the JSON entry, such as "\u270E\u270E", these two special characters are replaced with spaces. If a single special character appears with both the target language on the left and right, the special character is replaced with a space. For example, after the Chinese JSON entry is injected with corpus, if the left and right sides of a special character "\u270E" are both English letters, then this "\u270E" is replaced with a space.
[0038] S106: Construct a first prompt word based on the JSON terms after the corpus injection processing and the preset translation rules to prompt the AI agent to translate the JSON terms to obtain a first translation result.
[0039] The above-mentioned AI agent can be implemented using a pre-trained AI large language model. Before using the AI agent to translate the JSON entry, the JSON entry can be cut to avoid processing failures caused by token overflow of the AI agent. For example, for JSON entries stored in the form of key-value pairs, the text content (value) of the JSON entry can be split according to 40% of the token length of the word processing supported by the preset AI agent. Then, the maximum single processing length is determined by accumulating the content length. If the maximum length has been reached, the key-value pairs to be translated are reassembled into a new JSON object. These newly generated JSON objects are used as the content of the translation task. The translation task can also include fields such as task id, task order, task type, and translation result. The settings of these fields are mainly used for the subsequent assembly of translation task results. If a long text is encountered, the long text to be translated can be split into multiple translation tasks according to punctuation marks for translation, and the split translation tasks are written into a cache folder. If some exceptions are encountered, the translation task can be re-executed to avoid repeated calculations. When splitting a long text, the splitting order of the long text is recorded, so that in the subsequent translation result merging process, the translation results of multiple translation tasks can be merged by using the recorded splitting order of the long text.
[0040] After constructing the translation task, you can construct a prompt word to prompt the AI agent to perform the translation task. Specifically, you can construct the first prompt word based on the translation task generated by the JSON entry and the preset translation rules. The first prompt word can include the AI agent task role setting, translation rule setting, and specific translation task. The following is an example of the first prompt word, in which the variable (the part that needs to be filled in) will be represented by "${variable name}": “ You are a professional translator. You translate each line from ${current language} to ${target language}. Return the translation in the same text format. Maintain case sensitivity and spaces. Do not add extra punctuation such as quotation marks. Take care to output only the translation.
[0041] To achieve optimal clarity in your translation, please make sure to adhere to the following guidelines: Language Pair: Always confirm the language pair (e.g., Chinese to English, represented as zh-CN,en-US) at the beginning to avoid any confusion.
[0042] Text Formatting: Maintain the same formatting provided in the source text. If each term is enclosed in quotation marks, continue this pattern in the translation.
[0043] Case sensitivity: Pay attention to the capitalization used in the source text. If a term begins with a capital letter, the translation should reflect this.
[0044] Whitespace: Do not change whitespace in the source text. The translation should remain consistent.
[0045] Output: Unless explicitly stated otherwise, only the requested translation is provided, without any additional comments or explanations.
[0046] Translate the following lines: ``` ${Translation task content} ``` ” S108: Construct a second prompt word based on the JSON entry after the corpus injection processing, the first translation result and the translation rule to prompt the AI agent to correct the first translation result to obtain a second translation result.
[0047] After obtaining the first translation result, the second prompt word can be constructed to guide the AI agent to correct the first translation result, thereby ensuring that the second translation result complies with the translation rules set above. Specifically, the second prompt word can include AI agent task role settings, translation rule settings, verification tasks, first translation results, translation task content corresponding to the first translation result, etc. The following provides an example of the second prompt word, in which the variables (that is, the part that needs to be filled in) will be represented by "${variable name}": “ You are a professional translator.
[0048] The following is the translation result from ${current language} to ${target language}. Please verify that the result complies with the following rules, and try to correct the formatting and remove any unexpected additional comments or explanations: Language Pair: Always confirm the language pair (e.g. Chinese to English, represented as zh-CN,en-US) at the beginning to avoid any confusion.
[0049] Text Formatting: Maintain the same formatting provided in the source text. If each term is enclosed in quotation marks, continue this pattern in the translation.
[0050] Case sensitivity: Pay attention to the capitalization used in the source text. If a term begins with a capital letter, the translation should reflect this.
[0051] Whitespace: Do not change whitespace in the source text. The translation should remain consistent.
[0052] Output: Unless explicitly stated otherwise, only the requested translation is provided, without any additional comments or explanations.
[0053] Original translation: ``` ${Translation task content} ``` Translation results: ``` ${Translation result} ``` Please return the corrected result directly without any additional comments or explanations. If the correction is not possible, please return the following: Correction failed ” If the AI agent returns a correction failure, the number of correction attempts can be recorded, and the maximum number of attempts is built-in as N times. The value of N can be modified as needed. If the maximum number of attempts is not reached, the translation result of the corresponding translation task is cleared and re-transmitted to the AI agent to re-execute the translation task. If the maximum number of executions has been reached, the translation task is marked as a translation failure and the results are summarized. After all translation tasks are executed, the corresponding failure report can be generated. According to the failure report, manual intervention can be performed to manually fill in some abnormal situations that the AI agent cannot handle temporarily.
[0054] If the AI agent returns a corrected result, the corrected translation result will be used as the second translation result and saved in the cache file. The completed translation task will not be repeated.
[0055] After all translation tasks are completed, the translation results are returned to the AI agent in the order of the original translation task splitting for combination, thereby generating a complete JSON entry in the target language.
[0056] The above is the specific content of the JSON term intelligent translation method based on AI agent described in this embodiment. Compared with the prior art, this method has at least the following advantages: 1. Use AI agents to translate text in JSON format, retaining the original JSON format.
[0057] 2. The AI agent checks the first translation result and corrects format errors, finds out problems such as disordered order and loss of correspondence between key and value, and automatically performs re-translation.
[0058] 3. Through pre-corpus injection, self-built professional terms, industry vocabulary, paraphrase phrases and other corpora can be injected in advance to ensure the accuracy of translation.
[0059] 4. Through high-frequency word statistical analysis, high-frequency words in the translation content can be counted in advance, helping users to maintain a corpus that lacks high-frequency words in advance, so as to ensure the consistency of the overall translation.
[0060] Corresponding to the above-mentioned JSON term intelligent translation method based on AI agent, this embodiment also provides a JSON term intelligent translation system based on AI agent. Figure 2 , Figure 2 Schematic diagram of the structure of a JSON term intelligent translation system based on an AI agent proposed in one or more embodiments of this specification. The system can be used to implement the above-mentioned JSON term intelligent translation method based on an AI agent. It should be noted that the JSON term intelligent translation method based on an AI agent described in one or more embodiments of this application can rely on Figure 2 The JSON term intelligent translation system based on AI agent is shown to be implemented, but not limited to this system.
[0061] like Figure 2 As shown, the AI agent-based JSON term intelligent translation system includes: The data acquisition module is configured to acquire JSON terms to be translated.
[0062] The corpus injection module is configured to select a corpus based on the target language into which the JSON term needs to be translated, the corpus recording the corpus data in the same language as the original language of the JSON term and the translation of the corpus data in the target language; perform corpus injection processing on the JSON term: match the JSON term with each corpus data in the corpus respectively, and if there is corpus data matching the JSON term, replace the matching content in the JSON term with the translation of the corresponding corpus data.
[0063] The AI translation module is configured to construct a first prompt word based on the JSON terms after the corpus injection processing and the preset translation rules to prompt the AI agent to translate the JSON terms to obtain a first translation result.
[0064] The correction module is configured to construct a second prompt word based on the JSON entry after the corpus injection processing, the first translation result and the translation rule to prompt the AI agent to correct the first translation result to obtain a second translation result.
[0065] Optionally, the above-mentioned data acquisition module may specifically include a text content reading and writing module and a format conversion module.
[0066] The working principle of the text content reading and writing module is as follows: before translation, the original file can be read first to check the format of the original file. If the original file is a JSON format file, the content is directly read and directly parsed into JSON entries. If the original file is a non-JSON format file, the content of the original file can be read line by line as a text array, and the text array is input into the format conversion module.
[0067] The format conversion module is used to convert the text array read by the text content reading and writing module into JSON format. By expanding the format conversion module, the translation system can support more file formats. Taking the original file selected from the i18n text word library as an example, the i18n text word library supports file storage in YAML, TOML, properties and other formats. The common i18n text word library is composed of a unique keyword (key) corresponding to a text content (value) and connected with "=". Therefore, when the format conversion module converts the original file in i18n into JSON format, it can first read the text array content of the original file, and then perform secondary processing to split each line of entries into two sections through the first "=" sign, and generate a file cache by mapping the key on the left side of "=" and the subscript of the current entry, which is used to convert back to the source format after the translation is completed. The text content to the right of "=" is the text content to be translated. The subscript is used as the key of the JSON object and the text content is used as the value of the JSON object to obtain the JSON entry.
[0068] The format conversion module can also be used to convert the format of the second translation result. If the original file is in JSON format, the format conversion module can directly generate a JSON format file from the second translation result and name the JSON format file in the target language. If the original file is not in JSON format, the format conversion module can convert the second translation result in JSON format into the original format of the original file.
[0069] Optionally, the above-mentioned AI-agent-based JSON term intelligent translation system may also have a high-frequency vocabulary statistics module, which is used to perform high-frequency vocabulary statistics analysis on the JSON terms before corpus injection processing is performed on the JSON terms, and display the analysis results to the user, so that the user can adjust the corpus data in the corpus based on the analysis results.
[0070] Specifically, the high-frequency vocabulary statistics module can use the open source framework jieba to perform high-frequency vocabulary statistics on the content of the current JSON entry, and perform deduplication processing against the existing corpus, and generate a report by sorting the remaining high-frequency words in reverse order of frequency. At this time, the high-frequency vocabulary statistics module can display the report to the user and suspend the next work, waiting for the user to intervene and determine whether the corpus data needs to be supplemented to the corpus. After the user operation is completed, the high-frequency vocabulary statistics module can be triggered to continue working and transfer the JSON entry to the corpus injection module.
[0071] Optionally, when the corpus injection module performs corpus injection processing on the JSON entry, it can first read all the corpus data in the corpus and sort them in order from long to short. Taking the original file to be translated selected from the i18n word library as an example, the text content (value) of the JSON entry is traversed, and the corpus injection module matches each text content (value) with the corpus data one by one in the order of the corpus data from long to short. If a certain corpus data is matched and contained in the text content (value), the sentence / vocabulary in the text content (value) is replaced with the translation of the target language of the corpus data until all the corpus data is traversed. In this process, adjacent corpora may be injected. In some embodiments, the corpus injection module can avoid the problem of two words being connected and difficult to distinguish by adding spaces in the middle. Specifically, when the corpus injection module inserts corpus into the text content (value) of the JSON entry, a special character can be spliced at both ends of the inserted translation, for example: \u270E. After the corpus injection processing operation is completed, if two consecutive special characters appear in the JSON entry, such as "\u270E\u270E", the corpus injection module replaces these two special characters with spaces. If a single special character appears with both the target language on the left and right, the corpus injection module replaces the special character with a space. For example, after the corpus injection processing of the Chinese JSON entry, if the left and right sides of a special character "\u270E" are both English letters, then this "\u270E" will be replaced with a space.
[0072] Optionally, the AI translation module can cut the JSON entries before using the AI agent to translate the JSON entries to avoid processing failures caused by token overflow of the AI agent. For example, for JSON entries stored in the form of key-value pairs, the AI translation module can split the text content (value) of the JSON entry according to 40% of the token length of the word processing supported by the preset AI agent. Then, the AI translation module determines whether the maximum single processing length has been reached by accumulating the content length. If the maximum length has been reached, the key-value pairs to be translated are reassembled into a new JSON object. The AI translation module uses these newly generated JSON objects as the content of the translation task. The translation task can also include fields such as task id, task order, task type, and translation result. The settings of these fields are mainly used for the subsequent assembly of translation task results. If a long text is encountered, the AI translation module can split the long text to be translated into multiple translation tasks according to punctuation marks for translation, and write the split translation tasks into a cache folder. If some exceptions are encountered, the translation task can be re-executed to avoid repeated calculations. When splitting a long text, the AI translation module records the splitting order of the long text, so that in the subsequent translation result merging process, the translation results of multiple translation tasks can be merged by recording the splitting order of the long text.
[0073] The AI translation module can deploy the open source project one-api, which is used to request various third-party large model interfaces according to the request format of Open AI (ChatGPT), such as Baidu Wenxin Yiyan series models, Alibaba Tongyi Qianwen series models, ByteDance Doubao large model, etc. This greatly facilitates the selection and replacement of AI agents, and also reduces the development cost of interfaces.
[0074] After constructing the translation task, the AI translation module can construct a prompt word to prompt the AI agent to perform the translation task. Specifically, the AI translation module can construct the first prompt word based on the translation task generated by the JSON entry and the preset translation rules. The first prompt word can include the AI agent task role setting, translation rule setting and specific translation task. The following is an example of the first prompt word, in which the variable (the part that needs to be filled in) will be represented by "${variable name}": “ You are a professional translator. You translate each line from ${current language} to ${target language}. Return the translation in the same text format. Maintain case sensitivity and spaces. Do not add extra punctuation such as quotation marks. Take care to output only the translation.
[0075] To achieve optimal clarity in your translation, please make sure to adhere to the following guidelines: Language Pair: Always confirm the language pair (e.g. Chinese to English, represented as zh-CN,en-US) at the beginning to avoid any confusion.
[0076] Text Formatting: Maintain the same formatting provided in the source text. If each term is enclosed in quotation marks, continue this pattern in the translation.
[0077] Case sensitivity: Pay attention to the capitalization used in the source text. If a term begins with a capital letter, the translation should reflect this.
[0078] Whitespace: Do not change whitespace in the source text. The translation should remain consistent.
[0079] Output: Unless explicitly stated otherwise, only the requested translation is provided, without any additional comments or explanations.
[0080] Translate the following lines: ``` ${Translation task content} ``` ” When executing a translation task, the AI translation module can call the interface at a certain limited frequency, because the large model platform generally limits the interface call frequency to ensure normal operation. After completing the translation task, the AI translation module records the first translation result received into the translation result field and passes the translation result field to the correction module.
[0081] Optionally, after obtaining the first translation result, the correction module can guide the AI agent to correct the first translation result by constructing a second prompt word, thereby ensuring that the second translation result complies with the translation rules set above. Specifically, the second prompt word may include AI agent task role settings, translation rule settings, verification tasks, first translation results, translation task content corresponding to the first translation result, etc. The following provides an example of a second prompt word, in which the variables (that is, the part that needs to be filled in) will be represented by "${variable name}": “ You are a professional translator.
[0082] The following is the translation result from ${current language} to ${target language}. Please verify that the result complies with the following rules, and try to correct the formatting and remove any unexpected additional comments or explanations: Language Pair: Always confirm the language pair (e.g. Chinese to English, represented as zh-CN,en-US) at the beginning to avoid any confusion.
[0083] Text Formatting: Maintain the same formatting provided in the source text. If each term is enclosed in quotation marks, continue this pattern in the translation.
[0084] Case sensitivity: Pay attention to the capitalization used in the source text. If a term begins with a capital letter, the translation should reflect this.
[0085] Whitespace: Do not change whitespace in the source text. The translation should remain consistent.
[0086] Output: Unless explicitly stated otherwise, only the requested translation is provided, without any additional comments or explanations.
[0087] Original translation: ``` ${Translation task content} ``` Translation results: ``` ${Translation result} ``` Please return the corrected result directly without any additional comments or explanations. If the correction is not possible, please return the following: Correction failed ” If the correction module receives a correction failure from the AI agent, it can record the number of correction attempts and set the maximum number of attempts to N. The value of N can be modified as needed. If the maximum number of attempts is not reached, the correction module will clear the translation result of the corresponding translation task and retransmit it to the AI agent to re-execute the translation task. If the maximum number of executions has been reached, the correction module will mark the translation task as a translation failure and summarize the results. After all translation tasks are executed, the correction module can generate a corresponding failure report. According to the failure report, manual intervention can be performed to manually fill in some abnormal situations that the AI agent cannot handle temporarily.
[0088] If the correction module receives the result of successful correction returned by the AI agent, the corrected translation result will be used as the second translation result mentioned above and saved in the cache file. The completed translation task will not be executed again.
[0089] After all translation tasks are completed, the correction module returns the translation results to the AI agent in the order of the original translation task split, thereby generating a complete JSON entry in the target language. Finally, the complete JSON entry in the target language can be sent to the format conversion module of the data acquisition module and converted into a format consistent with the original file.
[0090] Corresponding to the above-mentioned JSON term intelligent translation method based on AI agent, this embodiment also provides a computer-readable storage medium on which a computer program is stored. When the computer program is executed by a processor, the processor executes the above-mentioned JSON term intelligent translation method based on AI agent.
[0091] Corresponding to the above-mentioned JSON term intelligent translation method based on AI agent, this embodiment further provides an electronic device, including: One or more processors; and a memory associated with the one or more processors, the memory being used to store program instructions, which, when read and executed by the one or more processors, enable the electronic device to execute the above-mentioned AI-agent-based JSON term intelligent translation method.
[0092] It is to be understood that the structure illustrated in the embodiments of this specification does not constitute a specific limitation on the system of the embodiments of this specification. In other embodiments of the specification, the above system may include more or fewer components than shown in the figure, or combine some components, or split some components, or arrange the components differently. The components shown in the figure may be implemented in hardware, software, or a combination of software and hardware.
[0093] Each embodiment in this specification is described in a progressive manner, and the same or similar parts between the embodiments can be referred to each other, and each embodiment focuses on the differences from other embodiments. In particular, for the device embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiment.
[0094] The above is a description of a specific embodiment of the specification. Other embodiments are within the scope of the appended claims. In some cases, the actions or steps recorded in the claims can be performed in an order different from that in the embodiments and still achieve the desired results. In addition, the processes depicted in the drawings do not necessarily require the specific order or continuous order shown to achieve the desired results. In some embodiments, multitasking and parallel processing are also possible or may be advantageous.
[0095] It should be noted that the above examples are only specific embodiments of the present invention, and the present invention is obviously not limited to the above examples, and there are many similar variations. All variations directly derived or associated from the contents disclosed by the technicians in this field should fall within the protection scope of the present invention.
Claims
1. A JSON term intelligent translation method based on AI agent, characterized in that: The method comprises: Get the JSON entry to be translated; Based on the target language into which the JSON term needs to be translated, selecting a corpus that records corpus data in the same language as the original language of the JSON term and translations of the corpus data in the target language; Performing corpus injection processing on the JSON entry: matching the JSON entry with each corpus data in the corpus respectively, and if there is corpus data matching the JSON entry, replacing the matching content in the JSON entry with the translation of the corresponding corpus data; Constructing a first prompt word based on the JSON term after the corpus injection processing and a preset translation rule to prompt the AI agent to translate the JSON term to obtain a first translation result; A second prompt word is constructed based on the JSON entry after the corpus injection processing, the first translation result and the translation rule to prompt the AI agent to correct the first translation result to obtain a second translation result.
2. The method according to claim 1, characterized in that Get the JSON terms to be translated, including: Get the original file to be translated; If the original file is in JSON format, the original file is directly used as the JSON entry; If the original file is not in JSON format, the original file is read line by line as a text array, and then the text array is converted into the JSON entry.
3. The method according to claim 1, characterized in that The method further comprises: Before the JSON terms are subjected to corpus injection processing, a high-frequency vocabulary statistical analysis is performed on the JSON terms, and the analysis results are displayed to the user, so that the user can adjust the corpus data in the corpus based on the analysis results.
4. The method according to claim 1, characterized in that The method further comprises: When replacing the matching content in the JSON entry with the translation of the corresponding corpus data, a special character is respectively spliced at both ends of the translation; After the JSON entry is processed by corpus injection, if two consecutive special characters appear in the JSON entry, the two special characters are replaced by spaces; if a single special character appears in the JSON entry and the left and right characters are both characters in the target language, the special character is replaced by a space.
5. A JSON term intelligent translation system based on AI agent, characterized in that: include: A data acquisition module configured to acquire JSON terms to be translated; A corpus injection module is configured to select a corpus based on the target language into which the JSON term needs to be translated, wherein the corpus records corpus data in the same language as the original language of the JSON term and a translation of the corpus data in the target language; Performing corpus injection processing on the JSON entry: matching the JSON entry with each corpus data in the corpus respectively, and if there is corpus data matching the JSON entry, replacing the matching content in the JSON entry with the translation of the corresponding corpus data; An AI translation module is configured to construct a first prompt word based on the JSON term after the corpus injection processing and a preset translation rule to prompt the AI agent to translate the JSON term to obtain a first translation result; The correction module is configured to construct a second prompt word based on the JSON entry after the corpus injection processing, the first translation result and the translation rule to prompt the AI agent to correct the first translation result to obtain a second translation result.
6. The system according to claim 5, characterized in that The data acquisition module comprises: A text content reading and writing module is configured to check the format of the original file to be translated. If the original file is in JSON format, the content of the original file is directly read and directly parsed into the JSON terms; if the original file is not in JSON format, the original file is read line by line as a text array; The format conversion module is configured to convert the text array into the JSON entry.
7. The system according to claim 5, characterized in that The system further comprises: The high-frequency vocabulary statistics module is configured to perform high-frequency vocabulary statistics analysis on the JSON terms before performing corpus injection processing on the JSON terms, and display the analysis results to the user so that the user can adjust the corpus data in the corpus based on the analysis results.
8. The system according to claim 5, characterized in that The corpus injection module is also used for: When replacing the matching content in the JSON entry with the translation of the corresponding corpus data, a special character is respectively spliced at both ends of the translation; After the JSON entry is subjected to corpus injection processing, if two consecutive special characters appear in the JSON entry, the two special characters are replaced with spaces; If the left and right characters of a single special character appearing in the JSON entry are both characters in the target language, the special character is replaced with a space.
9. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the processor is caused to perform the method according to any one of claims 1 to 4.
10. An electronic device, characterized in that: include: one or more processors; And a memory associated with the one or more processors, the memory is used to store program instructions, and when the program instructions are read and executed by the one or more processors, the electronic device executes the method according to any one of claims 1 to 4.
Citation Information
Patent Citations
International resource intelligent acquisition method and storage medium
CN109062913A
Text translation method and device, electronic equipment and storage medium
CN113312928A
Translation method and device, electronic equipment and storage medium
CN117910483A
Batch translation and verification method and device based on large language model, electronic equipment, computer readable storage medium and program product
CN118607539A
Text translation method, text translation device, electronic equipment and storage medium
CN118839703A