Prompt replacement method and device, equipment, storage medium and program product
By parsing the code file to generate an abstract syntax tree, and finding and replacing the prompts in the method call nodes, the problems of low efficiency and low accuracy of prompt replacement are solved, achieving efficient and accurate prompt replacement.
Patent Information
- Application Number
- CN202411712582.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-26
- Publication Date
- 2025-11-11
- Estimated Expiration
- 2044-11-26
AI Technical Summary
In existing technologies, the replacement of prompts in business code is inefficient and prone to incomplete replacement or errors.
By parsing the target code file, an abstract syntax tree is generated. Method call nodes in the abstract syntax tree are found and replaced, and matching prompts are identified and replaced.
It improves the efficiency and accuracy of prompt replacement, avoiding omissions and errors caused by manual replacement.
Smart Images

Figure CN119829061B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of computer technology, and in particular to a method, apparatus, device, storage medium, and program product for replacing prompts. Background Technology
[0002] During project product development or on-site delivery, there are often frequent modifications to tooltips in business code. Since tooltips can be written in various ways, developers need to quickly replace them when business requirements change. Traditionally, replacing tooltips involves creating a list of old tooltips and then a new list, matching each item against the old list. Developers then replace the tooltips in the business code according to this new list. However, this method of developers replacing tooltips one by one according to constantly changing business requirements is labor-intensive and inefficient. Summary of the Invention
[0003] Therefore, it is necessary to provide a method, apparatus, device, storage medium, and program product that can improve the efficiency of prompt replacement in order to address the above-mentioned technical problems.
[0004] Firstly, this application provides a method for replacing prompts, the method comprising:
[0005] Obtain the target code file containing the prompt message;
[0006] The first prompt to be replaced is determined from the prompts contained in the target code file, and a second prompt is determined for the first prompt;
[0007] The target code file is parsed to obtain the abstract syntax tree corresponding to the target code file;
[0008] Find all method call nodes contained in the abstract syntax tree;
[0009] For each method call node, if the calling method in the target code file corresponding to the method call node is a prompt call method, and the prompt in the prompt call method matches the first prompt, then the prompt in the prompt call method is replaced with the second prompt.
[0010] Secondly, this application provides a prompt replacement device, the device comprising:
[0011] The acquisition module is used to acquire the target code file containing the prompt message;
[0012] The determining module is configured to determine a first prompt to be replaced from the prompts contained in the target code file, and to determine a second prompt for the first prompt;
[0013] The parsing module is used to perform syntax parsing on the target code file to obtain the abstract syntax tree corresponding to the target code file;
[0014] The replacement module is used to find all method call nodes contained in the abstract syntax tree; for each method call node, if the calling method in the target code file corresponding to the method call node is a prompt call method, and the prompt in the prompt call method matches the first prompt, then the prompt in the prompt call method is replaced with the second prompt.
[0015] Thirdly, this application provides a computer device, including a memory and a processor, wherein the memory stores a computer program, and the processor executes the computer program to implement the steps in the various method embodiments of this application.
[0016] Fourthly, this application provides a computer-readable storage medium storing a computer program that, when executed by a processor, implements the steps in the various method embodiments of this application.
[0017] Fifthly, this application provides a computer program product, including a computer program that, when executed by a processor, implements the steps in the various method embodiments of this application.
[0018] The aforementioned prompt replacement method, apparatus, device, storage medium, and program product involve: acquiring a target code file containing prompts; determining a first prompt to be replaced from the prompts contained in the target code file, and determining a second prompt corresponding to the first prompt; parsing the target code file to obtain an abstract syntax tree (AST); searching for all method call nodes contained in the AST; and for each method call node, if the calling method in the target code file corresponding to the method call node is a prompt call method, and the prompt in the prompt call method matches the first prompt, then replacing the prompt in the prompt call method with the second prompt. Compared to traditional prompt replacement methods, this application parses the target code file containing prompts into an AST, traverses the AST to find all method call nodes in the AST, and then judges the calling method in each method call node to determine which part of the method call nodes contains the prompt call method from all the found method call nodes. For each method call node containing a prompt message, it is further determined whether the prompt message in these method call nodes is the prompt message that the user needs to replace. This can quickly locate the prompt message that needs to be replaced from the target code file and replace the prompt message that needs to be replaced, thus improving the efficiency of prompt message replacement in the code. Attached Figure Description
[0019] Figure 1 This is a diagram illustrating the application environment of a prompt replacement method in one embodiment;
[0020] Figure 2 This is a flowchart illustrating a prompt replacement method in one embodiment;
[0021] Figure 3 This is a schematic diagram illustrating an example of a prompt in the object code file of one embodiment;
[0022] Figure 4 This is a schematic diagram of the abstract syntax tree of a class in one embodiment;
[0023] Figure 5 This is a schematic diagram of a prompt invocation method in the object code file of one embodiment;
[0024] Figure 6 This is a schematic diagram of a prompt resource file in one embodiment;
[0025] Figure 7 This is a flowchart illustrating the prompt replacement method in another embodiment;
[0026] Figure 8 This is a structural block diagram of a prompt replacement device in one embodiment;
[0027] Figure 9 This is an internal structural diagram of a computer device in one embodiment;
[0028] Figure 10 This is an internal structural diagram of a computer device in one embodiment. Detailed Implementation
[0029] To make the objectives, technical solutions, and advantages of this application clearer, the following detailed description is provided in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative and not intended to limit the scope of this application.
[0030] The prompt replacement method provided in this application can be applied to, for example... Figure 1 In the application environment shown, terminal 102 communicates with server 104 via a network. The data storage system can be set up separately and can store the data that server 104 needs to process. The data storage system can be integrated into server 104 or placed in the cloud or on other servers. Terminal 102 can be, but is not limited to, various desktop computers, laptops, smartphones, tablets, in-vehicle terminals, intelligent voice interaction devices, aircraft, smart home appliances, and portable wearable devices. Smart home appliances can include smart speakers, smart TVs, and smart air conditioners, etc. Portable wearable devices can include smartwatches, smart bracelets, head-mounted devices, etc. Server 104 can be an independent physical server, a server cluster or distributed system composed of multiple physical servers, or a cloud server providing cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communication, middleware services, domain name services, cloud security, host security and other network security services, CDN, and basic cloud computing services such as big data and artificial intelligence platforms. Terminal 102 and server 104 can be directly or indirectly connected via wired or wireless communication, which is not limited herein.
[0031] Server 104 can obtain a target code file containing prompts from terminal 102, determine a first prompt to be replaced from the prompts contained in the target code file, and determine a second prompt corresponding to the first prompt. Server 104 can perform syntax parsing on the target code file to obtain the abstract syntax tree corresponding to the target code file, and search for all method call nodes contained in the abstract syntax tree. For each method call node, if the calling method in the target code file corresponding to the method call node is the prompt call method, and the prompt in the prompt call method matches the first prompt, then server 104 can replace the prompt in the prompt call method with the second prompt.
[0032] It is understood that this embodiment does not limit this aspect. Figure 1The application scenarios shown are for illustrative purposes only and are not limited to these.
[0033] In one embodiment, such as Figure 2 As shown, a method for replacing prompts is provided. This method can be applied to computer devices, which can be terminals or servers. That is, the method can be executed independently by the terminal or server, or it can be implemented through interaction between the terminal and the server. This embodiment uses the application of this method to a computer device as an example for illustration, including the following steps:
[0034] Step 202: Obtain the target code file containing the prompt.
[0035] In one embodiment, a computer device may acquire multiple source code files corresponding to a target project, wherein at least some of the source code files contain a prompt. The computer device may directly use these acquired source code files as the target code file.
[0036] For example, such as Figure 3 As shown, the target code file can contain multiple prompts, such as "Strategy parameter error, request parameter is empty", "Rule engine initialization in progress, the current scenario has entered the initialization queue, please try again later!", "Rule engine initialization in progress, the current scenario is queued for initialization, please try again later!", and "Rule engine initialization in progress, the current scenario is waiting for initialization, insertion into the queue failed, please try again later!".
[0037] Step 204: Determine the first prompt to be replaced from the prompts contained in the target code file, and determine the second prompt corresponding to the first prompt.
[0038] The first prompt is the user-defined part of the prompts included in the target code file that needs to be replaced. It can be understood that the first prompt can be user-defined. The second prompt is the prompt used to replace the first prompt; it can be understood as the new prompt after the replacement.
[0039] Step 206: Perform syntax parsing on the target code file to obtain the abstract syntax tree corresponding to the target code file.
[0040] The abstract syntax tree (AST) is a tree-like structure representing the syntactic structure of the source code in the target code file, obtained after parsing the source code. In one embodiment, such as... Figure 4As shown, the abstract syntax tree can contain nodes such as class definition nodes for defining classes in the source code, import package definition nodes for defining imported packages in the source code, field definition nodes for defining fields in the source code, and method definition nodes for classes. Method definition nodes are used to define methods in the source code. Method definition nodes further contain name definition nodes for defining method names in the source code, parameter definition nodes for defining parameters in the source code, and method body definition nodes for defining method bodies in the source code. Method body definition nodes contain expression definition nodes for defining expressions in the source code, and expression definition nodes contain method call nodes for defining method calls in the source code, which represent calls made by the current class to methods of other classes in the object code file.
[0041] Step 208: Locate all method call nodes contained in the abstract syntax tree.
[0042] Specifically, an abstract syntax tree contains at least one method call node. A computer device can traverse the abstract syntax tree to find all the method call nodes contained within it.
[0043] Step 210: For each method call node, if the method call in the target code file corresponding to the method call node is a prompt call method and the prompt in the prompt call method matches the first prompt, then replace the prompt in the prompt call method with the second prompt.
[0044] The prompt invocation method is a method in the object code file used to invoke prompts from the prompt resource file. The prompt resource file contains at least one prompt.
[0045] Specifically, the abstract syntax tree (AST) is obtained by parsing the target code file. Therefore, the calling methods corresponding to the method call nodes in the AST are also included in the target code file. For each method call node in the AST, if the calling method corresponding to the method call node is a prompt calling method, and the prompt in the prompt calling method matches the first prompt to be replaced, then the prompt in the prompt calling method is replaced with the second prompt.
[0046] In the above-described prompt replacement method, the following steps are taken: First, obtain the target code file containing the prompt; determine the first prompt to be replaced from the prompts contained in the target code file, and determine the second prompt corresponding to the first prompt; perform syntax parsing on the target code file to obtain the corresponding abstract syntax tree; search for all method call nodes contained in the abstract syntax tree; for each method call node, if the calling method in the target code file corresponding to the method call node is the prompt call method, and the prompt in the prompt call method matches the first prompt, then replace the prompt in the prompt call method with the second prompt. Compared to the traditional method of manually replacing prompts, this application parses the target code file containing the prompt into an abstract syntax tree, traverses the abstract syntax tree to find all method call nodes in the abstract syntax tree, and then judges the calling method in each method call node to determine the part of the method call nodes containing the prompt call method from all the found method call nodes. For each method call node containing a prompt message, the method further determines whether the prompt message in these call nodes is the one the user needs to replace. This allows for quick location of the prompt message to be replaced from the target code file, and the replacement is performed, improving the efficiency of prompt message replacement in the code. Furthermore, the prompt message replacement method described in this application avoids incomplete or incorrect replacements due to human error, thus improving the accuracy of prompt message replacement.
[0047] Furthermore, another traditional method for replacing tooltips mainly relies on pre-set keywords in third-party text editing tools to search for matching tooltips in the code. This method has limited functionality, only addressing the modification of specific terms and keywords, and cannot replace all tooltips in the code. Moreover, because it cannot parse the code's syntax, it is prone to incorrect replacements, resulting in low accuracy. Compared to traditional methods using third-party text editing tools, this application parses the target code file containing tooltips into an abstract syntax tree (AST). By traversing the AST, all method call nodes are found, and the method calls within each node are analyzed to identify the method call nodes containing the tooltips. For each method call node containing tooltips, the tooltips within these nodes are further analyzed to determine if they match the tooltips the user needs to replace. This allows for accurate location of the tooltips to be replaced from the target code file, preventing incorrect replacements and improving the accuracy of tooltip replacement in the code.
[0048] In one embodiment, obtaining a target code file containing a prompt includes: obtaining multiple source code files corresponding to a target project; at least some of the multiple source code files contain a prompt; and selecting the target code file containing the prompt from the multiple source code files.
[0049] In one embodiment, at least some of the source code files corresponding to the target project contain a prompt. It is understood that there are also other source code files that do not contain a prompt. The computer device can filter out the source code files containing the prompt from the multiple source code files corresponding to the target project and use this filtered portion of source code files as the target code file.
[0050] In the above embodiments, by first filtering out the target code files containing prompts from multiple original code files corresponding to the target project, the subsequent parsing of only the target code files containing prompts to obtain an abstract syntax tree can improve the efficiency of finding method call nodes, thereby further improving the efficiency of replacing prompts in the code.
[0051] In one embodiment, each source code file containing a prompt contains at least one prompt invocation method; each prompt invocation method contains a prompt, a prompt keyword corresponding to the included prompt, and a resource file identifier of the prompt resource file where the included prompt is located; selecting target code files containing prompts from multiple source code files includes: obtaining at least one prompt resource file referenced by multiple source code files; each prompt resource file contains at least one prompt and a prompt keyword corresponding to each of the at least one prompt; summarizing the at least one prompt resource file to obtain a prompt summary file; the prompt summary file contains multiple prompt term data; each prompt term data contains a prompt, a prompt keyword corresponding to the included prompt, and a resource file identifier of the prompt resource file where the included prompt is located; and selecting target code files containing prompts from multiple source code files based on the prompt keyword and resource file identifier contained in the prompt summary file.
[0052] The prompt keyword is a string used to uniquely identify the prompt. The prompt resource file is used to manage prompts in the code; it can be understood that all prompts in the code originate from the prompt resource file. The resource file identifier is a string used to uniquely identify the prompt resource file; for example, the resource file identifier can be the filename of the prompt resource file.
[0053] In one embodiment, the prompt message included in each prompt message entry data (i.e., the prompt message read from the prompt message resource file) is the first prompt message; if the prompt message included in the prompt message entry data needs to be replaced, the prompt message entry data will also include a second prompt message for that prompt message (i.e., the first prompt message). The computer device can directly determine the first prompt message to be replaced and the second prompt message for that first prompt message from the prompt message summary file.
[0054] In one embodiment, such as Figure 5 As shown, each original code file containing a prompt contains at least one prompt call method (i.e., ResManager.loadKDString); each prompt call method contains a prompt (e.g., Please correct all failed matching basic data), the prompt keyword corresponding to the contained prompt (e.g., PolicyCorrectDataPlugin_1), and the resource file identifier of the prompt resource file where the contained prompt is located (e.g., xxx-business).
[0055] In one embodiment, such as Figure 6 As shown, each prompt resource file contains at least one prompt (e.g., prompt 1, prompt 2, and prompt 3) and at least one prompt keyword corresponding to each prompt (e.g., key1, key2, and key3).
[0056] In the above embodiments, compared to locating prompts from the code by using the prompts themselves as the search basis, this embodiment uses the prompt keywords and resource file identifiers contained in the prompt summary file as the search basis to filter out target code files containing prompts from multiple original code files. This can effectively avoid the interference of comment text in the code, accurately locate prompts from the code, and improve the accuracy of obtaining target code files containing prompts.
[0057] In one embodiment, before step 210, the method further includes: for each method call node, parsing the name definition node under the method call node to obtain the call method name of the call method in the target code file corresponding to the method call node; if the call method name is consistent with the prompt call method name of the predefined prompt call method, then the call method in the target code file corresponding to the method call node is determined to be the prompt call method.
[0058] Specifically, for each method call node in the abstract syntax tree, the computer device can parse the name definition node under the method call node to obtain the method call name in the object code file corresponding to the method call node; if the method call name matches the predefined prompt method call name (i.e., ... Figure 5 If the method call node is consistent with ResManager.loadKDString, then the method call in the target code file corresponding to the method call node is determined to be the prompt call method.
[0059] In the above embodiments, by judging the consistency between the name of the called method and the name of the prompt called method, it can be determined whether the called method in the target code file corresponding to the method call node is the prompt called method, thereby improving the accuracy of judging the prompt called method.
[0060] In one embodiment, each prompt invocation method includes a prompt, a prompt keyword corresponding to the included prompt, and a resource file identifier of the prompt resource file where the included prompt is located; the method further includes: for each method invocation node, if the invocation method in the object code file corresponding to the method invocation node is a prompt invocation method, the prompt keyword in the prompt invocation method is consistent with the prompt keyword corresponding to the second prompt, and the resource file identifier in the prompt invocation method is consistent with the resource file identifier corresponding to the second prompt, then it is determined that the prompt in the prompt invocation method matches the first prompt.
[0061] In the above embodiments, compared to determining whether the prompt in the prompt calling method is the prompt that needs to be replaced by comparing the consistency of the prompt itself, this embodiment determines whether the prompt in the prompt calling method matches the first prompt by judging the consistency between the prompt keyword in the prompt calling method and the prompt keyword corresponding to the second prompt, as well as the consistency between the resource file identifier in the prompt calling method and the resource file identifier corresponding to the second prompt. This can improve the accuracy of prompt replacement.
[0062] In one embodiment, the method further includes: if the keyword parameter in the prompt call method is a prompt keyword, then read the prompt keyword from the prompt call method to obtain the prompt keyword in the prompt call method; if the keyword parameter in the prompt call method is a keyword constant class, then parse the constant attributes in the keyword constant class to obtain the prompt keyword in the prompt call method.
[0063] Specifically, there are two ways to write the value of the keyword parameter in the prompt call method. One way is that the value of the keyword parameter is the prompt keyword itself, expressed directly as a constant. In this case, the computer device can directly read the prompt keyword from the prompt call method. The other way is that the value of the keyword parameter needs to be obtained through a keyword constant class, expressed through a constant class. Specifically, the value of the keyword parameter is defined through the constant attributes of the constant class. In this case, the computer device can parse the constant attributes in the keyword constant class to obtain the prompt keyword in the prompt call method.
[0064] In the above embodiments, by determining the type of the keyword parameter in the prompt call method, the corresponding prompt keyword acquisition method can be adapted. This allows the prompt replacement method of this application to be compatible with various code writing methods and can further improve the accuracy of prompt replacement.
[0065] In one embodiment, the method further includes: if the resource file parameter in the prompt invocation method is a resource file identifier, then read the resource file identifier from the prompt invocation method to obtain the resource file identifier in the prompt invocation method; if the resource file parameter in the prompt invocation method is a resource file constant class, then parse the constant attributes in the resource file constant class to obtain the resource file identifier in the prompt invocation method.
[0066] Specifically, there are two ways to write the value of the resource file parameter in the prompt invocation method. One way is that the value of the resource file parameter is the resource file identifier, which is directly expressed as a constant. In this case, the computer device can directly read the resource file identifier from the prompt invocation method to obtain the resource file identifier. The other way is that the value of the resource file parameter needs to be obtained through a resource file constant class, that is, expressed through a constant class. Specifically, the value of the resource file parameter is defined through the constant attributes in the constant class. In this case, the computer device can parse the constant attributes in the resource file constant class to obtain the resource file identifier in the prompt invocation method.
[0067] In the above embodiments, by determining the type of the resource file parameter in the prompt call method, the corresponding resource file identifier acquisition method can be adapted. This allows the prompt replacement method of this application to be compatible with various code writing methods and can further improve the accuracy of prompt replacement.
[0068] In one embodiment, such as Figure 7As shown, the prompt keywords can be represented by key values. The prompt summary file is an Excel file, and the prompt replacement method logic in this application is deployed in the prompt replacement tool. The computer device can obtain multiple source code files corresponding to the target project; at least some of the source code files contain prompts; each source code file containing a prompt contains at least one prompt call method; each prompt call method contains a prompt, the prompt keyword corresponding to the contained prompt, and the resource file identifier of the prompt resource file where the contained prompt is located. The computer device can obtain at least one prompt resource file referenced by the multiple source code files; each prompt resource file contains at least one prompt and the prompt keyword corresponding to each prompt. The computer device can summarize at least one prompt resource file to obtain a prompt summary file; the prompt summary file contains multiple prompt term data; each prompt term data contains a prompt, the prompt keyword corresponding to the contained prompt, and the resource file identifier of the prompt resource file where the contained prompt is located. A computer device can filter target code files containing prompts from multiple source code files based on prompt keywords and resource file identifiers contained in a prompt summary file. The computer device can determine a first prompt to be replaced from the prompts contained in the target code files, and determine a second prompt corresponding to the first prompt. The computer device can perform syntax parsing on the target code files to obtain the corresponding abstract syntax tree (AST), and find all method call nodes contained in the AST. For each method call node, if the calling method in the target code file corresponding to the method call node is a prompt-based calling method, and the prompt in the prompt-based calling method matches the first prompt, then the computer device can replace the prompt in the prompt-based calling method with the second prompt. Simultaneously, the computer device can also replace the first prompt in the prompt summary file with the second prompt to maintain the prompt summary file, ensuring consistency between the prompt summary file and the prompts in the target code files, so that subsequent replacements of prompts in the target code files can be based on the prompt summary file.
[0069] It should be understood that although the steps in the flowcharts of the above embodiments are shown sequentially, these steps are not necessarily executed in that order. Unless otherwise expressly stated herein, there is no strict order restriction on the execution of these steps, and they can be executed in other orders. Moreover, at least some of the steps in the above embodiments may include multiple sub-steps or multiple stages. These sub-steps or stages are not necessarily completed at the same time, but can be executed at different times. The execution order of these sub-steps or stages is not necessarily sequential, but can be performed alternately or in turn with other steps or at least a portion of the sub-steps or stages of other steps.
[0070] In one embodiment, such as Figure 8 As shown, a prompt replacement device 800 is provided, which specifically includes:
[0071] Module 802 is used to acquire the target code file containing the prompt message;
[0072] The determination module 804 is used to determine the first prompt to be replaced from the prompts contained in the target code file, and to determine the second prompt for the first prompt;
[0073] Parsing module 806 is used to perform syntax parsing on the target code file and obtain the abstract syntax tree corresponding to the target code file;
[0074] Replacement module 808 is used to find all method call nodes contained in the abstract syntax tree; for each method call node, if the calling method in the target code file corresponding to the method call node is a prompt call method, and the prompt in the prompt call method matches the first prompt, then the prompt in the prompt call method is replaced with the second prompt.
[0075] In one embodiment, the acquisition module 802 is further configured to acquire multiple source code files corresponding to the target project; at least some of the source code files contain prompts; and select the target code file containing the prompts from the multiple source code files.
[0076] In one embodiment, each source code file containing a prompt contains at least one prompt invocation method; each prompt invocation method contains a prompt, a prompt keyword corresponding to the included prompt, and a resource file identifier of the prompt resource file where the included prompt is located; the acquisition module 802 is further configured to acquire at least one prompt resource file referenced by multiple source code files; each prompt resource file contains at least one prompt and a prompt keyword corresponding to each of the at least one prompt; the at least one prompt resource file is summarized to obtain a prompt summary file; the prompt summary file contains multiple prompt term data; each prompt term data contains a prompt, a prompt keyword corresponding to the included prompt, and a resource file identifier of the prompt resource file where the included prompt is located; based on the prompt keyword and resource file identifier contained in the prompt summary file, target code files containing prompts are selected from multiple source code files.
[0077] In one embodiment, the replacement module 808 is further configured to parse the name definition node under each method call node to obtain the call method name of the call method in the target code file corresponding to the method call node; if the call method name is consistent with the predefined prompt call method name, then the call method in the target code file corresponding to the method call node is determined to be the prompt call method.
[0078] In one embodiment, each prompt invocation method includes a prompt, a prompt keyword corresponding to the included prompt, and a resource file identifier of the prompt resource file where the included prompt is located; the replacement module 808 is further configured to, for each method invocation node, determine that the prompt in the prompt invocation method matches the first prompt if the invocation method in the object code file corresponding to the method invocation node is a prompt invocation method, the prompt keyword in the prompt invocation method is consistent with the prompt keyword corresponding to the second prompt, and the resource file identifier in the prompt invocation method is consistent with the resource file identifier corresponding to the second prompt.
[0079] In one embodiment, the replacement module 808 is further configured to: if the keyword parameter in the prompt call method is a prompt keyword, then read the prompt keyword from the prompt call method to obtain the prompt keyword in the prompt call method; if the keyword parameter in the prompt call method is a keyword constant class, then parse the constant attributes in the keyword constant class to obtain the prompt keyword in the prompt call method.
[0080] In one embodiment, the replacement module 808 is further configured to: if the resource file parameter in the prompt call method is a resource file identifier, then read the resource file identifier from the prompt call method to obtain the resource file identifier in the prompt call method; if the resource file parameter in the prompt call method is a resource file constant class, then parse the constant attributes in the resource file constant class to obtain the resource file identifier in the prompt call method.
[0081] The aforementioned prompt replacement device obtains a target code file containing prompts; determines a first prompt to be replaced from the prompts contained in the target code file, and determines a second prompt corresponding to the first prompt; performs syntax parsing on the target code file to obtain an abstract syntax tree corresponding to the target code file; searches for all method call nodes contained in the abstract syntax tree; for each method call node, if the calling method in the target code file corresponding to the method call node is the prompt call method, and the prompt in the prompt call method matches the first prompt, then the prompt in the prompt call method is replaced with the second prompt. Compared to traditional prompt replacement methods, this application parses the target code file containing prompts into an abstract syntax tree, traverses the abstract syntax tree to find all method call nodes in the abstract syntax tree, and then judges the calling method in each method call node to determine the part of the method call nodes containing the prompt call method from all the found method call nodes. For each method call node containing a prompt message, it is further determined whether the prompt message in these method call nodes is the prompt message that the user needs to replace. This can quickly locate the prompt message that needs to be replaced from the target code file and replace the prompt message that needs to be replaced, thus improving the efficiency of prompt message replacement in the code.
[0082] Furthermore, another traditional method for replacing tooltips mainly involves searching for matching tooltips in the code using pre-set keywords in third-party text editing tools. This method has limited functionality, only addressing modifications to specific terms and keywords, and cannot replace all tooltips in the code. Moreover, because it cannot parse the code's syntax, it is prone to incorrect replacements, resulting in low accuracy. Compared to traditional methods using third-party text editing tools, this application parses the target code file containing tooltips into an abstract syntax tree (AST). By searching for method call nodes within the AST, it can accurately locate the tooltips to be replaced in the target code file and perform the replacement, thus avoiding incorrect tooltips replacements and improving the accuracy of tooltip replacement in the code.
[0083] The modules in the aforementioned prompt replacement device can be implemented entirely or partially through software, hardware, or a combination thereof. These modules can be embedded in the processor of a computer device in hardware form or independent of it, or stored in the memory of the computer device in software form, so that the processor can call and execute the operations corresponding to each module.
[0084] In one embodiment, a computer device is provided, which may be a server, and its internal structure diagram may be as follows: Figure 9 As shown, this computer device includes a processor, memory, input / output (I / O) interfaces, and a communication interface. The processor, memory, and I / O interfaces are connected via a system bus, and the communication interface is also connected to the system bus via the I / O interfaces. The processor provides computational and control capabilities. The memory includes non-volatile storage media and internal memory. The non-volatile storage media stores the operating system, computer programs, and databases. The internal memory provides the environment for the operating system and computer programs stored in the non-volatile storage media to run. The I / O interfaces are used for exchanging information between the processor and external devices. The communication interface is used for communicating with external terminals via a network connection. When the computer program is executed by the processor, it implements a prompt replacement method.
[0085] In one embodiment, a computer device is provided, which may be a terminal, and its internal structure diagram may be as follows: Figure 10As shown, the computer device includes a processor, memory, input / output interfaces, a communication interface, a display unit, and an input device. The processor, memory, and input / output interfaces are connected via a system bus, and the communication interface, display unit, and input device are also connected to the system bus via the input / output interfaces. The processor provides computing and control capabilities. The memory includes non-volatile storage media and internal memory. The non-volatile storage media stores the operating system and computer programs. The internal memory provides an environment for the operation of the operating system and computer programs stored in the non-volatile storage media. The input / output interfaces are used for exchanging information between the processor and external devices. The communication interface is used for wired or wireless communication with external terminals; wireless communication can be achieved through Wi-Fi, mobile cellular networks, NFC (Near Field Communication), or other technologies. When executed by the processor, the computer program implements a prompt replacement method. The display unit of the computer device is used to form a visually visible image. It can be a display screen, a projection device, or a virtual reality imaging device. The display screen can be an LCD screen or an e-ink screen. The input device of the computer device can be a touch layer covering the display screen, or buttons, trackballs, or touchpads set on the casing of the computer device, or external keyboards, touchpads, or mice, etc.
[0086] Those skilled in the art will understand that Figure 9 and Figure 10 The structure shown is merely a block diagram of a portion of the structure related to the present application and does not constitute a limitation on the computer device to which the present application is applied. Specific computer devices may include more or fewer components than those shown in the figure, or combine certain components, or have different component arrangements.
[0087] In one embodiment, a computer device is also provided, including a memory and a processor, wherein the memory stores a computer program, and the processor executes the computer program to implement the steps in the above method embodiments.
[0088] In one embodiment, a computer-readable storage medium is provided storing a computer program that, when executed by a processor, implements the steps in the above method embodiments.
[0089] In one embodiment, a computer program product is provided, including a computer program that, when executed by a processor, implements the steps in the above method embodiments.
[0090] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, data stored, data displayed, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties, and the collection, use and processing of related data must comply with the relevant laws, regulations and standards of the relevant countries and regions.
[0091] Those skilled in the art will understand that all or part of the processes in the methods of the above embodiments can be implemented by a computer program instructing related hardware. The computer program can be stored in a non-volatile computer-readable storage medium, and when executed, it can include the processes of the embodiments of the methods described above. Any references to memory, storage, databases, or other media used in the embodiments provided in this application can include at least one of non-volatile and volatile memory. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory, or optical storage, etc. Volatile memory can include random access memory (RAM) or external cache memory. By way of illustration and not limitation, RAM can be in various forms, such as static random access memory (SRAM) or dynamic random access memory (DRAM), etc.
[0092] The technical features of the above embodiments can be combined in any way. For the sake of brevity, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.
[0093] The embodiments described above are merely illustrative of several implementation methods of this application, and while the descriptions are relatively specific and detailed, they should not be construed as limiting the scope of the invention patent. It should be noted that those skilled in the art can make various modifications and improvements without departing from the concept of this application, and these all fall within the protection scope of this application. Therefore, the protection scope of this patent application should be determined by the appended claims.
Claims
1. A method for replacing prompts, characterized in that, The method includes: Obtain the target code file containing the prompt message; The first prompt to be replaced is determined from the prompts contained in the target code file, and a second prompt is determined for the first prompt; The target code file is parsed to obtain the abstract syntax tree corresponding to the target code file; Find all method call nodes contained in the abstract syntax tree; For each method call node, if the calling method in the target code file corresponding to the method call node is a prompt call method, and the prompt in the prompt call method matches the first prompt, then the prompt in the prompt call method is replaced with the second prompt.
2. The method according to claim 1, characterized in that, The process of obtaining the target code file containing the prompt includes: Obtain multiple source code files corresponding to the target project; at least some of the source code files contain prompts. Select the target code file containing the prompt from the plurality of source code files.
3. The method according to claim 2, characterized in that, Each of the original code files containing the prompt contains at least one prompt call method; The step of filtering out the target code file containing the prompt from the plurality of original code files includes: Obtain at least one prompt resource file referenced by the plurality of original code files; each prompt resource file contains at least one prompt and a prompt keyword corresponding to each of the at least one prompt. The at least one prompt resource file is aggregated to obtain a prompt summary file; the prompt summary file contains multiple prompt term data; each prompt term data contains a prompt, the prompt keyword corresponding to the included prompt, and the resource file identifier of the prompt resource file where the included prompt is located; Based on the prompt keywords and resource file identifiers contained in the prompt summary file, target code files containing prompts are selected from the multiple original code files.
4. The method according to claim 1, characterized in that, The method further includes: For each method call node, the name definition node under the method call node is parsed to obtain the name of the calling method in the target code file corresponding to the method call node; If the name of the called method is consistent with the name of the predefined prompt call method, then the called method in the target code file corresponding to the method call node is determined to be the prompt call method.
5. The method according to claim 1, characterized in that, Each of the aforementioned prompt invocation methods includes a prompt, a prompt keyword corresponding to the included prompt, and a resource file identifier of the prompt resource file where the included prompt is located; the method further includes: For each method call node, if the calling method in the target code file corresponding to the method call node is a prompt call method, the prompt keyword in the prompt call method is consistent with the prompt keyword corresponding to the second prompt, and the resource file identifier in the prompt call method is consistent with the resource file identifier corresponding to the second prompt, then it is determined that the prompt in the prompt call method matches the first prompt.
6. The method according to claim 5, characterized in that, The method further includes: If the keyword parameter in the prompt invocation method is a prompt keyword, then the prompt keyword is read from the prompt invocation method to obtain the prompt keyword in the prompt invocation method; If the keyword parameter in the prompt invocation method is a keyword constant class, then the constant attributes in the keyword constant class are parsed to obtain the prompt keyword in the prompt invocation method.
7. The method according to claim 5, characterized in that, The method further includes: If the resource file parameter in the prompt invocation method is a resource file identifier, then the resource file identifier is read from the prompt invocation method to obtain the resource file identifier in the prompt invocation method; If the resource file parameter in the prompt invocation method is a resource file constant class, then the constant attributes in the resource file constant class are parsed to obtain the resource file identifier in the prompt invocation method.
8. A prompt replacement device, characterized in that, The device includes: The acquisition module is used to acquire the target code file containing the prompt message; The determining module is configured to determine a first prompt to be replaced from the prompts contained in the target code file, and to determine a second prompt for the first prompt; The parsing module is used to perform syntax parsing on the target code file to obtain the abstract syntax tree corresponding to the target code file; The replacement module is used to find all method call nodes contained in the abstract syntax tree; for each method call node, if the calling method in the target code file corresponding to the method call node is a prompt call method, and the prompt in the prompt call method matches the first prompt, then the prompt in the prompt call method is replaced with the second prompt.
9. A computer device comprising a memory and a processor, wherein the memory stores a computer program, characterized in that, When the processor executes the computer program, it implements the steps of the method according to any one of claims 1 to 7.
10. A computer-readable storage medium storing a computer program, characterized in that, When the computer program is executed by a processor, it implements the steps of the method according to any one of claims 1 to 7.
11. A computer program product, comprising a computer program, characterized in that, When the computer program is executed by a processor, it implements the steps of the method according to any one of claims 1 to 7.
Citation Information
Patent Citations
Function guidance language configuration and display method, system and related equipment
CN114063990A
Code processing method, device and equipment and readable storage medium
CN117234507A