Prompt word replacement method and device, equipment, storage medium and program product
By parsing the code file into an abstract syntax tree and finding the method call node, the prompts in the business code are implemented quickly, solving the problem of low efficiency of traditional replacement methods and improving the replacement efficiency and accuracy.
Patent Information
- Application Number
- CN202411712582.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-26
- Publication Date
- 2025-04-15
- Estimated Expiration
- 2044-11-26
AI Technical Summary
During the process of project product development or on-site delivery, prompts in the business code need to be modified frequently, and traditional replacement methods are inefficient and have a large workload.
By obtaining the object code file, parsing it into an abstract syntax tree, finding the method call node, judging and replacing matching prompts, improving replacement efficiency.
Quickly locate and replace prompts in the code to improve replacement efficiency, avoid mistaken replacement, and improve accuracy.
Smart Images

Figure CN119829061A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer technology, and in particular to a prompt word replacement method, device, equipment, storage medium and program product. Background Art
[0002] During the process of project product development or on-site delivery, there is often a situation where prompts in business codes are frequently modified. The prompts in business codes are written in various ways. When business requirements change, developers need to quickly replace the prompts according to the new business requirements. In traditional technology, the main way to replace prompts in the code is to first sort out an old prompt list, then sort out a new prompt list, and match the new prompt list with the old prompt list one by one. The developer will replace the prompts in the business code with this new prompt list. However, it is a large workload for developers to replace the prompts in the code one by one according to business requirements that may change at any time, and the efficiency of prompt replacement is low. Summary of the invention
[0003] Based on this, it is necessary to provide a prompt word replacement method, device, equipment, storage medium and program product that can improve the efficiency of prompt word replacement in response to the above technical problems.
[0004] In a first aspect, the present application provides a prompt word replacement method, the method comprising:
[0005] Get the object code file containing the prompt;
[0006] Determine a first prompt word to be replaced from the prompt words included in the target code file, and determine a second prompt word for the first prompt word;
[0007] Performing syntax analysis on the target code file to obtain an abstract syntax tree corresponding to the target code file;
[0008] Find all method call nodes contained in the abstract syntax tree;
[0009] For each of the method call nodes, if the calling method in the target code file corresponding to the method call node is a prompt calling method, and the prompt in the prompt calling method matches the first prompt, the prompt in the prompt calling method is replaced with the second prompt.
[0010] In a second aspect, the present application provides a prompt word replacement device, the device comprising:
[0011] An acquisition module is used to acquire a target code file containing prompt words;
[0012] A determination module, configured to determine a first prompt word to be replaced from the prompt words included in the target code file, and determine a second prompt word for the first prompt word;
[0013] A parsing module, used to perform syntax parsing on the target code file to obtain an abstract syntax tree corresponding to the target code file;
[0014] A replacement module is used to 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 a prompt calling method, and the prompt in the prompt calling method matches the first prompt, then the prompt in the prompt calling method is replaced with the second prompt.
[0015] In a third aspect, the present application provides a computer device including a memory and a processor, wherein a computer program is stored in the memory, and when the processor executes the computer program, the steps in the method embodiments of the present application are implemented.
[0016] In a fourth aspect, the present application provides a computer-readable storage medium storing a computer program, which, when executed by a processor, implements the steps in the method embodiments of the present application.
[0017] In a fifth aspect, the present application provides a computer program product, including a computer program, which implements the steps in the method embodiments of the present application when the computer program is executed by a processor.
[0018] The above-mentioned prompt replacement method, device, equipment, storage medium and program product obtain a target code file containing prompts; determine the first prompt to be replaced from the prompts contained in the target code file, and determine the second prompt for the first prompt; perform syntax analysis on the target code file to obtain an abstract syntax tree corresponding to the target code file; 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 a prompt calling method, and the prompt in the prompt calling method matches the first prompt, then replace the prompt in the prompt calling method with the second prompt. Compared with the traditional prompt replacement method, the present 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, so as to determine the part of method call nodes containing the prompt calling method from all the found method call nodes. For each method call node that contains a prompt calling method, it is further determined whether the prompts in these method call nodes are the prompts that the user needs to replace. This allows the prompts that need to be replaced to be quickly located from the target code file, and the prompts that need to be replaced can be replaced, thereby improving the efficiency of replacing prompts in the code. BRIEF DESCRIPTION OF THE DRAWINGS
[0019] Figure 1 A diagram of an application environment of a prompt word replacement method in an embodiment;
[0020] Figure 2 A schematic diagram of a process of replacing a prompt in one embodiment;
[0021] Figure 3 A schematic diagram of an example of a prompt in an object code file in an embodiment;
[0022] Figure 4 A schematic diagram of an abstract syntax tree of a class in one embodiment;
[0023] Figure 5 A schematic diagram of a prompt calling method in an object code file in one embodiment;
[0024] Figure 6 A schematic diagram of a prompt resource file in an embodiment;
[0025] Figure 7 A schematic diagram of a flowchart of a prompt word replacement method in another embodiment;
[0026] Figure 8 is a structural block diagram of a prompt word replacement device in an embodiment;
[0027] Fig. 9 is an internal structure diagram of a computer device in one embodiment;
[0028] Fig.10 FIG. 4 is a diagram showing the internal structure of a computer device in one embodiment. DETAILED DESCRIPTION
[0029] In order to make the purpose, technical solution and advantages of the present application more clearly understood, the present application is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.
[0030] The prompt word replacement method provided in this application can be applied to Figure 1 In the application environment shown. Among them, the terminal 102 communicates with the server 104 through the network. The data storage system can be set up separately and can store the data that the server 104 needs to process. The data storage system can be integrated on the server 104, or it can be placed on the cloud or other servers. Among them, the terminal 102 can be, but is not limited to, various desktop computers, laptops, smart phones, tablet computers, vehicle-mounted terminals, intelligent voice interaction devices, aircraft, smart home appliances and portable wearable devices. Smart home appliances can be smart speakers, smart TVs and smart air conditioners. Portable wearable devices can be smart watches, smart bracelets, head-mounted devices, etc. The server 104 can be an independent physical server, or a server cluster or distributed system composed of multiple physical servers, or a cloud server that provides cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, 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. The terminal 102 and the server 104 can be directly or indirectly connected by wired or wireless communication, and this application is not limited here.
[0031] The server 104 may obtain the target code file containing the prompt from the terminal 102, and determine the first prompt to be replaced from the prompt contained in the target code file, and determine the second prompt for the first prompt. The server 104 may perform syntax analysis on the target code file, 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 a prompt call method, and the prompt in the prompt call method matches the first prompt, the server 104 may replace the prompt in the prompt call method with the second prompt.
[0032] It is understood that this embodiment does not limit this. It is understood that Figure 1The application scenarios are only for illustration and are not limited to this.
[0033] In one embodiment, Figure 2 As shown, a prompt replacement method is provided, which can be applied to a computer device, which can be a terminal or a server, that is, the method can be executed by the terminal or the server alone, or can be implemented through interaction between the terminal and the server. This embodiment takes the method applied to a computer device as an example for explanation, and includes the following steps:
[0034] Step 202, obtaining a target code file containing prompts.
[0035] In one embodiment, the computer device may obtain multiple original code files corresponding to the target project, wherein at least some of the multiple original code files contain prompts. The computer device may directly use the obtained multiple original code files as the target code files.
[0036] For example, Figure 3 As shown, the target code file may contain multiple prompts, such as, "Strategy parameter error, request parameter is empty", "The rule engine is initializing, the current scene enters the initialization queue, please try again later!", "The rule engine is initializing, the current scene is queued for initialization in the queue, please try again later!", and "The rule engine is initializing, the current scene is waiting for initialization, the insertion into the queue failed, please try again later!".
[0037] Step 204: determine a first prompt word to be replaced from the prompt words included in the target code file, and determine a second prompt word for the first prompt word.
[0038] The first prompt is the part of the prompt contained in the target code file that is preset by the user and needs to be replaced. It is understood that the first prompt can be customized by the user. The second prompt is a prompt used to replace the first prompt. It is understood that the second prompt is a new prompt after the replacement.
[0039] Step 206: perform syntax analysis on the target code file to obtain an abstract syntax tree corresponding to the target code file.
[0040] The abstract syntax tree is a tree structure obtained by parsing the source code in the target code file and used to represent the syntax structure of the source code. Figure 4As shown, the abstract syntax tree may include a class definition node for defining a class in the source code, an import package definition node for defining an import package in the source code, a field definition node for defining a field in the source code, and several method definition nodes contained in the class, wherein the method definition node is used to define the method in the source code. The method definition node further includes a name definition node for defining the method name in the source code, a parameter definition node for defining the parameter in the source code, and a method body definition node for defining the method body in the source code. The method body definition node includes an expression definition node for defining an expression in the source code, and the expression definition node includes a method call node for defining a method call in the source code, which represents the call of the current class in the target code file to the method of other classes.
[0041] Step 208: Find all method call nodes included in the abstract syntax tree.
[0042] Specifically, the abstract syntax tree includes at least one method call node. The computer device can traverse the abstract syntax tree to find all method call nodes included in the abstract syntax tree.
[0043] Step 210, 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.
[0044] The prompt calling method is a method in the target code file for calling a prompt from a prompt resource file. The prompt resource file contains at least one prompt.
[0045] Specifically, the abstract syntax tree is obtained by parsing the target code file, so the calling method corresponding to the method calling node in the abstract syntax tree is also included in the target code file. For each method calling node in the abstract syntax tree, if the calling method corresponding to the method calling node is a prompt calling method, and the prompt in the prompt calling method matches the first prompt to be replaced, the prompt in the prompt calling method is replaced with the second prompt.
[0046] In the above prompt replacement method, a target code file containing prompts is obtained; a first prompt to be replaced is determined from the prompts contained in the target code file, and a second prompt for the first prompt is determined; the target code file is parsed to obtain an abstract syntax tree corresponding to the target code file; all method call nodes contained in the abstract syntax tree are searched; for each method call node, if the calling method in the target code file corresponding to the method call node is a prompt calling method, and the prompt in the prompt calling method matches the first prompt, then the prompt in the prompt calling method is replaced with the second prompt. Compared with the traditional method of manually replacing prompts, the present 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, so as to determine the part of method call nodes containing the prompt calling method from all the found method call nodes. For each method call node containing a prompt call method, it is further determined whether the prompt in these method call nodes is the prompt that the user needs to replace, so that the prompt that needs to be replaced can be quickly located from the target code file, and the prompt that needs to be replaced can be replaced, thereby improving the efficiency of replacing prompts in the code. At the same time, the prompt replacement method of the present application can also avoid the problem of incomplete replacement or replacement error caused by human replacement omissions, thereby improving the replacement accuracy of prompts.
[0047] In addition, another traditional prompt replacement method mainly searches for the prompts in the matching code through the keywords pre-set in the third-party text editing tool. The function is limited and can only solve the modification of specific terms and keywords, but cannot solve the replacement and modification of all prompts in the code. Moreover, because it cannot parse the syntax of the code, it is easy to make wrong replacements during the replacement process, resulting in a low replacement accuracy of the prompts. Compared with the traditional method of replacing prompts through a third-party text editing tool, the present 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 calling method from all the method call nodes found. For each method call node containing the prompt calling method, it is further judged whether the prompts in these method call nodes are the prompts that the user needs to replace, so that the prompts that need to be replaced can be accurately located from the target code file, and the prompts that need to be replaced are replaced, which can avoid the wrong replacement of the prompts, thereby improving the replacement accuracy of the prompts in the code.
[0048] In one embodiment, obtaining a target code file containing a prompt includes: obtaining multiple original code files corresponding to the target project; at least some of the multiple original code files contain the prompt; and filtering out the target code file containing the prompt from the multiple original code files.
[0049] In one embodiment, at least some of the multiple original code files corresponding to the target project contain prompts. It is understandable that there are another part of the multiple original code files corresponding to the target project that do not contain prompts. The computer device can filter out the part of the original code files containing prompts from the multiple original code files corresponding to the target project, and use the filtered part of the original code files as the target code files.
[0050] In the above embodiment, the target code files containing prompts are first screened out from the multiple original code files corresponding to the target project. In this way, only the part of the target code files containing the prompts is subsequently parsed to obtain the abstract syntax tree, which can improve the search efficiency of the method call nodes, thereby further improving the replacement efficiency of the prompts in the code.
[0051] In one embodiment, each original code file containing a prompt contains at least one prompt calling method; each prompt calling method contains a prompt, a prompt keyword corresponding to the contained prompt, and a resource file identifier of a prompt resource file where the contained prompt is located; filtering out a target code file containing a prompt from multiple original code files includes: obtaining at least one prompt resource file referenced by multiple 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; aggregating at least one prompt resource file to obtain a prompt summary file; the prompt summary file contains multiple prompt word entry data; each prompt word entry data contains a prompt, a prompt keyword corresponding to the contained prompt, and a resource file identifier of a prompt resource file where the contained prompt is located; based on the prompt keyword and the resource file identifier contained in the prompt summary file, filtering out a target code file containing a prompt from multiple original code files.
[0052] The prompt keyword is a string used to uniquely identify the prompt. The prompt resource file is a file used to manage the prompts in the code. It can be understood that all the prompts in the code come 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 file name of the prompt resource file.
[0053] In one embodiment, the prompt included in each prompt word data (i.e., the prompt read from the prompt word resource file) is the first prompt; if the prompt included in the prompt word data needs to be replaced, the prompt word data will also include a second prompt for the prompt (i.e., the first prompt). The computer device can directly determine the first prompt to be replaced and the second prompt for the first prompt from the prompt word summary file.
[0054] In one embodiment, Figure 5 As shown, each original code file containing prompts contains at least one prompt calling method (i.e., ResManager.loadKDString); each prompt calling method contains a prompt (e.g., Please correct all basic information data that fail to match), a prompt keyword corresponding to the included prompt (e.g., PolicyCorrectDataPlugin_1), and a resource file identifier of the prompt resource file where the included prompt is located (e.g., xxx-business).
[0055] In one embodiment, Figure 6 As shown, each prompt resource file includes at least one prompt (eg, prompt 1, prompt 2, and prompt 3), and at least one prompt keyword corresponding to each prompt (eg, key1, key2, and key3).
[0056] In the above embodiment, compared with the method of locating prompts from the code by taking 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 screen out target code files containing prompts from multiple original code files, which can effectively avoid the interference of comment text in the code, can accurately locate the prompts from the code, and improve the accuracy of obtaining the 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 calling method name of the calling method in the target code file corresponding to the method call node; if the calling method name is consistent with the prompt calling method name of the pre-defined prompt calling method, then determining that the calling method in the target code file corresponding to the method call node is a prompt calling method.
[0058] Specifically, for each method call node in the abstract syntax tree, the computer device may parse the name definition node under the method call node to obtain the calling method name of the calling method in the target code file corresponding to the method call node; if the calling method name is consistent with the prompt calling method name of the predefined prompt calling method (i.e., Figure 5 If the calling method in the target code file corresponding to the method calling node is consistent with ResManager.loadKDString in the method calling node, the calling method in the target code file corresponding to the method calling node is determined to be the prompt calling method.
[0059] In the above embodiment, by judging the consistency between the calling method name and the prompt calling method name of the prompt calling method, it is possible to judge whether the calling method in the target code file corresponding to the method calling node is the prompt calling method, thereby improving the judgment accuracy of the prompt calling method.
[0060] In one embodiment, each prompt calling method includes a prompt, a prompt keyword corresponding to the included prompt, and a resource file identifier of a prompt resource file where the included prompt is located; the method also includes: for each method calling node, if the calling method in the target code file corresponding to the method calling node is a prompt calling method, the prompt keyword in the prompt calling method is consistent with the prompt keyword corresponding to the second prompt, and the resource file identifier in the prompt calling method is consistent with the resource file identifier corresponding to the second prompt, then it is determined that the prompt in the prompt calling method matches the first prompt.
[0061] In the above embodiment, compared with the method of judging 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 judges 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, and the consistency between the resource file identifier in the prompt calling method and the resource file identifier corresponding to the second prompt, thereby improving the accuracy of prompt replacement.
[0062] In one embodiment, the method also includes: if the keyword parameter in the prompt calling method is a prompt keyword, then the prompt keyword is read from the prompt calling method to obtain the prompt keyword in the prompt calling method; if the keyword parameter in the prompt calling 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 calling method.
[0063] Specifically, there are two ways to write the code for the value of the keyword parameter in the prompt calling method. One is that the value of the keyword parameter is the prompt keyword, that is, it is directly expressed by a constant. At this time, the computer device can directly read the prompt keyword from the prompt calling method to obtain the prompt keyword in the prompt calling method. The other is that the value of the keyword parameter needs to be obtained through a keyword constant class, that is, it is expressed through a constant class, and specifically, the value of the keyword parameter is defined by the constant attribute in the constant class. At this time, the computer device can parse the constant attribute in the keyword constant class to obtain the prompt keyword in the prompt calling method.
[0064] In the above embodiment, by determining the type of the keyword parameter in the prompt calling method, the corresponding prompt keyword acquisition method is adapted. In this way, the prompt replacement method of the present application can be compatible with various code writing methods and the prompt replacement accuracy can be further improved.
[0065] In one embodiment, the method also includes: if the resource file parameter in the prompt calling method is a resource file identifier, then the resource file identifier is read from the prompt calling method to obtain the resource file identifier in the prompt calling method; if the resource file parameter in the prompt calling 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 calling method.
[0066] Specifically, there are two ways to code the value of the resource file parameter in the prompt calling method. One is that the value of the resource file parameter is the resource file identifier, that is, it is directly expressed by a constant. In this case, the computer device can directly read the resource file identifier from the prompt calling method to obtain the resource file identifier in the prompt calling method. The other is that the value of the resource file parameter needs to be obtained through the resource file constant class, that is, it is expressed through a constant class. Specifically, the value of the resource file parameter is defined by the constant attribute in the constant class. In this case, the computer device can parse the constant attribute in the resource file constant class to obtain the resource file identifier in the prompt calling method.
[0067] In the above embodiment, by determining the type of the resource file parameter in the prompt calling method, the corresponding resource file identifier acquisition method is adapted. In this way, the prompt replacement method of the present application can be compatible with various code writing methods and the prompt replacement accuracy can be further improved.
[0068] In one embodiment, Figure 7As shown, the prompt keyword can be represented by a key value, 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 original code files corresponding to the target project; at least some of the multiple original code files contain prompts; each original code file containing prompts contains at least one prompt calling method; each prompt calling 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 computer device can obtain at least one prompt resource file referenced by multiple original code files; each prompt resource file contains at least one prompt, and at least one 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 word entry data; each prompt word entry 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. The computer device can filter out the target code file containing the prompt from multiple original code files based on the prompt keywords and resource file identifiers contained in the prompt summary file. The computer device can determine the first prompt to be replaced from the prompt contained in the target code file, and determine the second prompt for the first prompt. The computer device can perform syntax analysis on the target code file, obtain the abstract syntax tree corresponding to the target code file, and 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, the computer device can replace the prompt in the prompt call method with the second prompt. At the same time, the computer device can also replace the first prompt in the prompt summary file with the second prompt to achieve maintenance of the prompt summary file, so that the prompt summary file is consistent with the prompt in the target code file, so that the prompt in the target code file can be replaced based on the prompt summary file later.
[0069] It should be understood that, although each step in the flow chart of the above-mentioned embodiments is shown in order, these steps are not necessarily performed in order. Unless there is a clear explanation in this article, the execution of these steps does not have strict order restrictions, and these steps can be performed in other orders. Moreover, at least a portion of the steps in the above-mentioned embodiments may include a plurality of sub-steps or a plurality of stages, and these sub-steps or stages are not necessarily performed at the same time, but can be performed at different times, and the execution order of these sub-steps or stages is not necessarily performed in order, but can be performed in turn or alternately with at least a portion of other steps or sub-steps or stages of other steps.
[0070] In one embodiment, Figure 8 As shown, a prompt word replacement device 800 is provided, and the device specifically includes:
[0071] An acquisition module 802 is used to acquire a target code file containing a prompt;
[0072] A determination module 804 is used to determine a first prompt word to be replaced from the prompt words included in the target code file, and determine a second prompt word for the first prompt word;
[0073] The parsing module 806 is used to perform syntax analysis on the target code file to obtain an abstract syntax tree corresponding to the target code file;
[0074] The replacement module 808 is used to 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 a prompt calling method, and the prompt in the prompt calling method matches the first prompt, then the prompt in the prompt calling method is replaced with the second prompt.
[0075] In one embodiment, the acquisition module 802 is further used to acquire multiple original code files corresponding to the target project; at least some of the multiple original code files contain prompts; and the target code file containing the prompt is filtered out from the multiple original code files.
[0076] In one embodiment, each original code file containing a prompt contains at least one prompt calling method; each prompt calling method contains a prompt, a prompt keyword corresponding to the contained prompt, and a resource file identifier of a prompt resource file where the contained prompt is located; the acquisition module 802 is also used to obtain at least one prompt resource file referenced by multiple original code files; each prompt resource file contains at least one prompt and a prompt keyword corresponding to at least one prompt; at least one prompt resource file is aggregated to obtain a prompt aggregate file; the prompt aggregate file contains multiple prompt entry data; each prompt entry data contains a prompt, a prompt keyword corresponding to the contained prompt, and a resource file identifier of a prompt resource file where the contained prompt is located; based on the prompt keyword and the resource file identifier contained in the prompt aggregate file, a target code file containing a prompt is screened out from multiple original code files.
[0077] In one embodiment, the replacement module 808 is also used to parse the name definition node under each method call node to obtain the calling method name of the calling method in the target code file corresponding to the method call node; if the calling method name is consistent with the prompt calling method name of the pre-defined prompt calling method, then the calling method in the target code file corresponding to the method call node is determined to be the prompt calling method.
[0078] In one embodiment, each prompt calling 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 also used to, for each method calling node, determine that the prompt in the prompt calling method matches the first prompt if the calling method in the target code file corresponding to the method calling node is a prompt calling method, the prompt keyword in the prompt calling method is consistent with the prompt keyword corresponding to the second prompt, and the resource file identifier in the prompt calling method is consistent with the resource file identifier corresponding to the second prompt.
[0079] In one embodiment, the replacement module 808 is also used to read the prompt keyword from the prompt calling method to obtain the prompt keyword in the prompt calling method if the keyword parameter in the prompt calling method is a prompt keyword; if the keyword parameter in the prompt calling method is a keyword constant class, parse the constant attributes in the keyword constant class to obtain the prompt keyword in the prompt calling method.
[0080] In one embodiment, the replacement module 808 is also used to read the resource file identifier from the prompt calling method to obtain the resource file identifier in the prompt calling method if the resource file parameter in the prompt calling method is a resource file identifier; if the resource file parameter in the prompt calling method is a resource file constant class, parse the constant attributes in the resource file constant class to obtain the resource file identifier in the prompt calling method.
[0081] The above-mentioned prompt replacing device obtains a target code file containing prompts; determines the first prompt to be replaced from the prompts contained in the target code file, and determines the second prompt for the first prompt; performs syntax analysis 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 a prompt calling method, and the prompt in the prompt calling method matches the first prompt, then replaces the prompt in the prompt calling method with the second prompt. Compared with the traditional prompt replacing method, the present 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, so as to determine the part of method call nodes containing the prompt calling method from all the found method call nodes. For each method call node that contains a prompt calling method, it is further determined whether the prompts in these method call nodes are the prompts that the user needs to replace. This allows the prompts that need to be replaced to be quickly located from the target code file, and the prompts that need to be replaced can be replaced, thereby improving the efficiency of replacing prompts in the code.
[0082] In addition, another traditional prompt replacement method mainly searches for matching prompts in the code through pre-set keywords in a third-party text editing tool. It has limited functions and can only solve the modification of specific terms and keywords, but cannot solve the replacement and modification of all prompts in the code. Moreover, since it cannot parse the syntax of the code, it is easy to make wrong replacements during the replacement process, resulting in a low accuracy rate of prompt replacement. Compared with the traditional method of replacing prompts through a third-party text editing tool, the present application parses the target code file containing prompts into an abstract syntax tree, and searches for method call nodes in the abstract syntax tree, so as to accurately locate the prompts that need to be replaced from the target code file, and replace the prompts that need to be replaced, which can avoid wrong replacement of prompts, thereby improving the accuracy rate of prompt replacement in the code.
[0083] Each module in the above prompt replacement device can be implemented in whole or in part by software, hardware or a combination thereof. Each module can be embedded in or independent of a processor in a computer device in the form of hardware, or can be stored in a memory in a computer device in the form of software, so that the processor can call and execute operations corresponding to each module.
[0084] In one embodiment, a computer device is provided. The computer device may be a server, and its internal structure diagram may be as follows: Fig. 9 As shown. The computer device includes a processor, a memory, an input / output interface (Input / Output, referred to as I / O) and a communication interface. The processor, the memory and the input / output interface are connected through a system bus, and the communication interface is connected to the system bus through the input / output interface. The processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system, a computer program and a database. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The input / output interface of the computer device is used to exchange information between the processor and an external device. The communication interface of the computer device is used to communicate with an external terminal through a network connection. When the computer program is executed by the processor, a prompt replacement method is implemented.
[0085] In one embodiment, a computer device is provided. The computer device may be a terminal, and its internal structure diagram may be as follows: Fig.10As shown. The computer device includes a processor, a memory, an input / output interface, a communication interface, a display unit and an input device. The processor, the memory and the input / output interface are connected through a system bus, and the communication interface, the display unit and the input device are connected to the system bus through the input / output interface. The processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system and a computer program. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The input / output interface of the computer device is used to exchange information between the processor and an external device. The communication interface of the computer device is used to communicate with an external terminal in a wired or wireless manner, and the wireless manner can be implemented through WIFI, a mobile cellular network, NFC (near field communication) or other technologies. When the computer program is executed by the processor, a prompt replacement method is implemented. The display unit of the computer device is used to form a visually visible image, and can be a display screen, a projection device or a virtual reality imaging device. The display screen can be a liquid crystal display screen or an electronic ink display screen. The input device of the computer device can be a touch layer covered on the display screen, or a button, trackball or touchpad set on the computer device casing, or an external keyboard, touchpad or mouse, etc.
[0086] Those skilled in the art will understand that Fig. 9 and Fig.10 The structure shown in the figure is only a block diagram of a part of the structure related to the solution of the present application, and does not constitute a limitation on the computer device to which the solution of the present application is applied. The specific computer device may include more or fewer components than those shown in the figure, or combine certain components, or have a different arrangement of components.
[0087] In one embodiment, a computer device is further provided, including a memory and a processor, wherein a computer program is stored in the memory, and the processor implements the steps in the above method embodiments when executing the computer program.
[0088] In one embodiment, a computer-readable storage medium is provided, storing a computer program, which implements the steps in the above method embodiments when executed by a processor.
[0089] In one embodiment, a computer program product is provided, including a computer program, and when the computer program is executed by a processor, the steps in the above method embodiments are implemented.
[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, stored data, displayed data, 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 relevant data must comply with relevant laws, regulations and standards of relevant countries and regions.
[0091] Those of ordinary skill in the art can understand that all or part of the processes in the above-mentioned embodiment methods can be completed by instructing the relevant hardware through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to memory, storage, database or other media used in the embodiments provided in this application can include at least one of non-volatile and volatile memory. Non-volatile memory can include read-only memory (ROM), tape, floppy disk, flash memory or optical memory, etc. Volatile memory can include random access memory (RAM) or external cache memory. As an illustration and not limitation, RAM can be in various forms, such as static random access memory (SRAM) or dynamic random access memory (DRAM).
[0092] The technical features of the above embodiments may be combined arbitrarily. To make the description concise, 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 above-mentioned embodiments only express several implementation methods of the present application, and the descriptions thereof are relatively specific and detailed, but they cannot be understood as limiting the scope of the invention patent. It should be pointed out that, for a person of ordinary skill in the art, several variations and improvements can be made without departing from the concept of the present application, and these all belong to the protection scope of the present application. Therefore, the protection scope of the patent of the present application shall be subject to the attached claims.
Claims
1. A prompt word replacement method, characterized in that: The method comprises: Get the object code file containing the prompt; Determine a first prompt word to be replaced from the prompt words included in the target code file, and determine a second prompt word for the first prompt word; Performing syntax analysis on the target code file to obtain an abstract syntax tree corresponding to the target code file; Find all method call nodes contained in the abstract syntax tree; For each of the method call nodes, if the calling method in the target code file corresponding to the method call node is a prompt calling method, and the prompt in the prompt calling method matches the first prompt, the prompt in the prompt calling method is replaced with the second prompt.
2. The method according to claim 1, characterized in that The step of obtaining the target code file containing the prompt includes: Acquire multiple original code files corresponding to the target project; at least some of the multiple original code files contain prompts; The target code file containing the prompt words is screened out from the plurality of original code files.
3. The method according to claim 2, characterized in that Each of the original code files containing prompts contains at least one prompt calling method; The step of selecting the target code file containing the prompt from the plurality of original code files comprises: Acquire at least one prompt resource file referenced by the plurality of original code files; each of the prompt resource files contains at least one prompt and a prompt keyword corresponding to each of the at least one prompt; Aggregating the at least one prompt resource file to obtain a prompt summary file; the prompt summary file includes a plurality of prompt word entry data; each of the prompt word entry data includes a prompt word, a prompt word keyword corresponding to the included prompt word, and a resource file identifier of the prompt word resource file where the included prompt word is located; Based on the prompt keyword and the resource file identifier contained in the prompt summary file, the target code file containing the prompt is screened out from the multiple original code files.
4. The method according to claim 1, characterized in that: The method further comprises: For each of the method call nodes, parsing the name definition node under the method call node to obtain the calling method name of the calling method in the target code file corresponding to the method call node; If the calling method name is consistent with a predefined prompt calling method name, then the calling method in the target code file corresponding to the method calling node is determined to be a prompt calling method.
5. The method according to claim 1, characterized in that Each of the prompt calling methods includes a prompt, a prompt keyword corresponding to the prompt, and a resource file identifier of a prompt resource file where the prompt is located; the method also includes: For each of the method calling nodes, if the calling method in the target code file corresponding to the method calling node is a prompt calling method, the prompt keyword in the prompt calling method is consistent with the prompt keyword corresponding to the second prompt, and the resource file identifier in the prompt calling method is consistent with the resource file identifier corresponding to the second prompt, then it is determined that the prompt in the prompt calling method matches the first prompt.
6. The method according to claim 5, characterized in that The method further comprises: If the keyword parameter in the prompt calling method is a prompt keyword, reading the prompt keyword from the prompt calling method to obtain the prompt keyword in the prompt calling method; If the keyword parameter in the prompt calling method is a keyword constant class, the constant attributes in the keyword constant class are parsed to obtain the prompt keyword in the prompt calling method.
7. The method according to claim 5, characterized in that The method further comprises: If the resource file parameter in the prompt calling method is a resource file identifier, then reading the resource file identifier from the prompt calling method to obtain the resource file identifier in the prompt calling method; If the resource file parameter in the prompt calling method is a resource file constant class, the constant attributes in the resource file constant class are parsed to obtain the resource file identifier in the prompt calling method.
8. A prompt word replacement device, characterized in that: The device comprises: An acquisition module is used to acquire a target code file containing prompt words; A determination module, used to determine a first prompt word to be replaced from the prompt words included in the target code file, and determine a second prompt word for the first prompt word; A parsing module, used to perform syntax parsing on the target code file to obtain an abstract syntax tree corresponding to the target code file; A replacement module is used to 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 a prompt calling method, and the prompt in the prompt calling method matches the first prompt, then the prompt in the prompt calling method is replaced with the second prompt.
9. A computer device comprising a memory and a processor, wherein the memory stores a computer program, wherein: When the processor executes the computer program, the steps of the method according to any one of claims 1 to 7 are implemented.
10. A computer-readable storage medium storing a computer program, characterized in that: When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 7 are implemented.
11. A computer program product, comprising a computer program, characterized in that When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 7 are implemented.
Citation Information
Patent Citations
Function guidance language configuration and display method, system and related equipment
CN114063990A
Code processing method and device, computer equipment and storage medium
CN114579136A
Code processing method, device and equipment and readable storage medium
CN117234507A
Code content repairing method and device, equipment, storage medium and program product
CN118626126A
Methods for detecting plagiarism in software code and devices thereof
US20140053285A1