Code translation method, device, equipment and storage medium
By traversing the syntax topology structure and encrypting the target node object, the problem of multilingual support in the prior art requires code reconstruction, and the security of translation is improved.
Patent Information
- Application Number
- CN202110691849.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-06-22
- Publication Date
- 2025-04-22
- Estimated Expiration
- 2041-06-22
AI Technical Summary
When the prior art supports multilingual scenarios, it is necessary to invasively refactor the code of mature products, resulting in low translation security.
By calling the preset traversal algorithm to traverse the node objects in the syntax topology, the target node objects are obtained and encrypted based on the secure hash algorithm.
Improves the security of translation and avoids the risks and complexity brought by code refactoring.
Smart Images

Figure CN113420569B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of traversal query, and in particular to a code translation method, device, equipment and storage medium. Background Art
[0002] With the development of informatization and globalization, more and more products are positioned internationally. When developing pages, it is necessary to consider multi-language versions or preset multi-national application scenarios.
[0003] In the existing technology, for products that are positioned locally, developed regionally and have mature operations, in order to support multilingual scenarios in the future, the project needs to be invasively reconstructed, such as replacing text-related content at the interaction level with variables to dynamically read the values in the mapping under different language configuration scenarios. However, after a mature product has gone through multiple iterative versions, it usually has thousands of lines of code, and the relationship between business processes is very complex, resulting in low translation security. Summary of the invention
[0004] The present invention provides a code translation method, device, equipment and storage medium, which are used to traverse the node objects in the grammatical topology structure by calling a preset traversal algorithm to obtain the target node object, and encrypt the target node object based on a secure hash algorithm, thereby improving the security of the translation.
[0005] A first aspect of the present invention provides a code translation method, comprising: obtaining a code to be translated, performing conversion processing on the code to be translated based on a preset grammatical structure to obtain a grammatical topological structure; calling a preset traversal algorithm to traverse all node objects in the grammatical topological structure to obtain an initial node object, and determining the initial node object that meets a preset condition as a target node object; converting and encrypting the target node object to obtain an encrypted string, and comparing the encrypted string with a string in a preset database to obtain a comparison result, and determining an initial translation result according to the comparison result; inspecting and filtering the initial translation result to obtain an intermediate translation result, judging whether the intermediate translation result meets a preset translation standard, and generating a target translation result if the intermediate translation result meets the preset translation standard.
[0006] Optionally, in a first implementation method of the first aspect of the present invention, obtaining the code to be translated, performing conversion processing on the code to be translated based on a preset grammatical structure, and obtaining a grammatical topology structure includes: calling a preset operating platform, reading the code to be translated, the code to be translated is stored in a preset code file, and the code to be translated is a code containing a preset code format; performing conversion processing on the code to be translated through a preset grammatical structure to obtain multiple grammatical blocks, and determining the logical relationship between the multiple grammatical blocks through a preset data structure processing algorithm to obtain a code logical relationship; according to the code logical relationship, connecting the multiple grammatical blocks in sequence to obtain a grammatical topology structure.
[0007] Optionally, in a second implementation method of the first aspect of the present invention, calling a preset traversal algorithm, traversing all node objects in the grammatical topology structure, obtaining an initial node object, and determining the initial node object that meets preset conditions as a target node object includes: obtaining the starting position information and the ending position information of the grammatical topology structure, calling a preset traversal algorithm, and traversing the grammatical topology structure based on the starting position information and the ending position information to obtain the initial node object; reading the parameter value, node type, and link information of the initial node object, and judging whether the initial node object meets the preset condition according to the parameter value, node type, and link information of the initial node object to obtain a judgment result, wherein the preset condition is preset language information, and the link information is used to indicate a code logical relationship; if the judgment result is that the preset language information exists in the initial node object, then the initial node object is identified to obtain the target node object.
[0008] Optionally, in a third implementation of the first aspect of the present invention, if the judgment result is that the preset language information exists in the initial node object, the initial node object is marked, and obtaining the target node object includes: if the judgment result is that the preset language information exists in the initial node object, a non-empty subset is returned, and the non-empty subset is used to indicate the location information of the target node object. The initial node object corresponding to the non-empty subset is marked to obtain a marked node object; and the marked node object is determined as the target node object.
[0009] Optionally, in a fourth implementation method of the first aspect of the present invention, the target node object is converted and encrypted to obtain an encrypted string, and the encrypted string is compared with a string in a preset database to obtain a comparison result, and an initial translation result is determined based on the comparison result, including: reading the target node object, converting the target node object into an initial string through a preset regular expression; determining whether the initial string conforms to a preset grammatical specification to obtain a grammatical determination result; encrypting the initial string according to the grammatical determination result to obtain an encrypted string, and calling a preset string comparison algorithm to compare the encrypted string with a string in a preset database to obtain a comparison result, and determining the initial translation result based on the comparison result.
[0010] Optionally, in a fifth implementation manner of the first aspect of the present invention, the initial string is encrypted according to the grammar determination result to obtain an encrypted string, and a preset string comparison algorithm is called to compare the encrypted string with a string in a preset database to obtain a comparison result, and the initial translation result is determined according to the comparison result, including: if the grammar determination result is that the initial string conforms to a preset grammar specification, calling a preset secure hash algorithm to preprocess and perform logical operations on the initial string to obtain an encrypted string; calling a preset string comparison algorithm to compare the encrypted string with a string in a preset database to obtain a comparison result; if the comparison result is that the encrypted string is consistent in length with the string in the preset database, determining the encrypted string as the initial translation result.
[0011] Optionally, in a sixth implementation manner of the first aspect of the present invention, the checking and filtering the initial translation result to obtain an intermediate translation result, judging whether the intermediate translation result meets a preset translation standard, and if the intermediate translation result meets the preset translation standard, generating a target translation result includes: calling a preset detection tool to detect repeated values in the initial translation result to obtain a detection result, filtering repeated values in the initial translation result according to the detection result to obtain an intermediate translation result; creating flag information, judging whether the intermediate translation result meets the preset translation standard based on the flag information, and if the intermediate translation result meets the preset translation standard, determining the intermediate translation result as the target translation result, and the flag information is a binary number containing a preset number of bits.
[0012] The second aspect of the present invention provides a code translation device, including: an acquisition module, used to acquire a code to be translated, and perform conversion processing on the code to be translated based on a preset grammatical structure to obtain a grammatical topological structure; a traversal module, used to call a preset traversal algorithm, traverse all node objects in the grammatical topological structure, obtain an initial node object, and determine the initial node object that meets a preset condition as a target node object; an encryption module, used to convert and encrypt the target node object to obtain an encrypted string, and compare the encrypted string with a string in a preset database to obtain a comparison result, and determine an initial translation result according to the comparison result; a generation module, used to check and filter the initial translation result to obtain an intermediate translation result, judge whether the intermediate translation result meets the preset translation standard, and if the intermediate translation result meets the preset translation standard, generate a target translation result.
[0013] Optionally, in a first implementation method of the second aspect of the present invention, the acquisition module includes: a reading unit, used to call a preset operating platform, read the code to be translated, the code to be translated is stored in a preset code file, and the code to be translated is a code containing a preset code format; a determination unit, used to convert the code to be translated through a preset grammatical structure to obtain multiple grammatical blocks, and determine the logical relationship between the multiple grammatical blocks through a preset data structure processing algorithm to obtain a code logical relationship; a connection unit, used to connect the multiple grammatical blocks in sequence according to the code logical relationship to obtain a grammatical topology structure.
[0014] Optionally, in a second implementation of the second aspect of the present invention, the traversal module includes: a traversal unit, used to obtain the starting position information and the ending position information of the grammatical topology structure, call a preset traversal algorithm, and traverse the grammatical topology structure based on the starting position information and the ending position information to obtain an initial node object; a first judgment unit, used to read the parameter value, node type, and link information of the initial node object, and judge whether the initial node object meets a preset condition according to the parameter value, node type, and link information of the initial node object to obtain a judgment result, wherein the preset condition is preset language information, and the link information is used to indicate a code logical relationship; an identification unit, used to identify the initial node object if the judgment result is that the preset language information exists in the initial node object, and obtain a target node object.
[0015] Optionally, in a third implementation of the second aspect of the present invention, the identification unit is specifically used to: if the judgment result is that the preset language information exists in the initial node object, return a non-empty subset, and the non-empty subset is used to indicate the location information of the target node object. Mark the initial node object corresponding to the non-empty subset to obtain a marked node object; and determine the marked node object as the target node object.
[0016] Optionally, in a fourth implementation of the second aspect of the present invention, the encryption module includes: a conversion unit, used to read the target node object, and convert the target node object into an initial string through a preset regular expression; a second judgment unit, used to judge whether the initial string conforms to a preset grammatical specification, and obtain a grammatical judgment result; an encryption unit, used to encrypt the initial string according to the grammatical judgment result to obtain an encrypted string, and call a preset string comparison algorithm to compare the encrypted string with a string in a preset database to obtain a comparison result, and determine the initial translation result according to the comparison result.
[0017] Optionally, in a fifth implementation of the second aspect of the present invention, the encryption unit is specifically used to: if the grammar determination result is that the initial character string conforms to a preset grammar specification, call a preset secure hash algorithm to perform preprocessing and logical operations on the initial character string to obtain an encrypted character string; call a preset string comparison algorithm to compare the encrypted character string with a character string in a preset database to obtain a comparison result; if the comparison result is that the encrypted character string is consistent in length with the character string in the preset database, determine the encrypted character string as the initial translation result.
[0018] Optionally, in a sixth implementation manner of the second aspect of the present invention, the generation module includes: a detection unit, used to call a preset detection tool, detect repeated values in the initial translation result, obtain a detection result, and filter the repeated values in the initial translation result according to the detection result to obtain an intermediate translation result; a generation unit, used to create flag information, and determine whether the intermediate translation result meets a preset translation standard based on the flag information; if the intermediate translation result meets the preset translation standard, determine the intermediate translation result as a target translation result, and the flag information is a binary number containing a preset number of bits.
[0019] A third aspect of the present invention provides a code translation device, comprising: a memory and at least one processor, wherein the memory stores instructions; the at least one processor calls the instructions in the memory so that the code translation device executes the above-mentioned code translation method.
[0020] A fourth aspect of the present invention provides a computer-readable storage medium, wherein the computer-readable storage medium stores instructions, which, when executed on a computer, enable the computer to execute the above-mentioned code translation method.
[0021] In the technical solution provided by the present invention, a code to be translated is obtained, and a conversion process based on a preset grammatical structure is performed on the code to be translated to obtain a grammatical topological structure; a preset traversal algorithm is called to traverse all node objects in the grammatical topological structure to obtain an initial node object, and the initial node object that meets the preset conditions is determined as a target node object; the target node object is converted and encrypted to obtain an encrypted string, and the encrypted string is compared with a string in a preset database to obtain a comparison result, and an initial translation result is determined according to the comparison result; the initial translation result is checked and filtered to obtain an intermediate translation result, and it is determined whether the intermediate translation result meets the preset translation standard. If the intermediate translation result meets the preset translation standard, a target translation result is generated. In the embodiment of the present invention, the preset traversal algorithm is called to traverse the node objects in the grammatical topological structure to obtain a target node object, and the target node object is encrypted based on a secure hash algorithm, thereby improving the security of translation. BRIEF DESCRIPTION OF THE DRAWINGS
[0022] Figure 1 A schematic diagram of an embodiment of a code translation method in an embodiment of the present invention;
[0023] Figure 2 A schematic diagram of another embodiment of the code translation method in an embodiment of the present invention;
[0024] Figure 3 A schematic diagram of an embodiment of a code translation device in an embodiment of the present invention;
[0025] Figure 4 A schematic diagram of another embodiment of a code translation device in an embodiment of the present invention;
[0026] Figure 5 FIG. 1 is a schematic diagram of an embodiment of a code translation device in an embodiment of the present invention. DETAILED DESCRIPTION
[0027] The embodiments of the present invention provide a code translation method, apparatus, device and storage medium, which are used to traverse the node objects in the grammatical topology structure by calling a preset traversal algorithm to obtain the target node object, and encrypt the target node object based on a secure hash algorithm, thereby improving the security of the translation.
[0028] The terms "first", "second", "third", "fourth", etc. (if any) in the specification and claims of the present invention and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchanged where appropriate, so that the embodiments described herein can be implemented in an order other than that illustrated or described herein. In addition, the terms "including" or "having" and any variations thereof are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device that includes a series of steps or units is not necessarily limited to those steps or units that are clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.
[0029] For ease of understanding, the specific process of the embodiment of the present invention is described below. Figure 1 , an embodiment of the code translation method in the embodiment of the present invention includes:
[0030] 101. Obtain a code to be translated, and perform conversion processing on the code to be translated based on a preset grammatical structure to obtain a grammatical topological structure.
[0031] It is understandable that the execution subject of the present invention may be a code translation device, or a terminal or a server, which is not limited here. The embodiment of the present invention is described by taking a server as the execution subject as an example.
[0032] The server obtains the code to be translated, performs conversion processing on the code to be translated based on a preset grammatical structure, and obtains a grammatical topology structure. The code to be translated is stored in a preset code file, and the format of the code to be translated is JavaScript. The server converts the code to be translated into a backward-compatible JavaScript grammatical structure by calling a preset compiler Babel, obtains multiple grammatical blocks, so that it can run in current and old versions of browsers or other environments, and determines the code logical relationship between multiple grammatical blocks, and finally obtains a grammatical topology structure. The grammatical topology structure is to abstract the entities of the code to be translated into points that are independent of their size and shape, and abstract the lines connecting the entities into lines. Each node in the grammatical topology structure represents a structure in the source code. The shape of the grammatical topology structure in this embodiment includes but is not limited to star, mesh and tree.
[0033] 102. Call a preset traversal algorithm to traverse all node objects in the grammatical topology structure to obtain an initial node object, and determine the initial node object that meets a preset condition as a target node object.
[0034] The server calls a preset traversal algorithm to traverse all node objects in the grammatical topology structure to obtain an initial node object, and determines the initial node object that meets the preset conditions as the target node object. After the server obtains the starting position information and the ending position information of the grammatical topology structure, it loops through all node objects in the abstract syntax tree through the preset traversal algorithm to obtain the initial node object. The loop traversal process includes but is not limited to at least one of pre-order traversal, in-order traversal and post-order traversal. The server reads the parameter value, node type and link information of the initial node object, and determines whether each initial node object contains the preset language information (i.e., the preset condition). If the initial node object contains the preset language information, the initial node object is identified to obtain the target node object. When the target node object exists, the server returns a non-empty subset, and the non-empty subset is used to indicate the position information of the target node object; if the initial node object does not contain the preset language information, the target node object does not exist, and the server returns an empty set.
[0035] 103. Convert and encrypt the target node object to obtain an encrypted string, compare the encrypted string with a string in a preset database to obtain a comparison result, and determine an initial translation result based on the comparison result.
[0036] The server converts and encrypts the target node object to obtain an encrypted string, and compares the encrypted string with the string in the preset database to obtain a comparison result, and determines the initial translation result based on the comparison result. The server reads the target node object, converts the target node object into a corresponding string through a regular expression, obtains an initial string, and encrypts the initial string if the initial string meets the preset grammatical specifications. The grammatical specifications include but are not limited to at least one of naming specifications, annotation specifications, development specifications and design, declaration specifications, transaction specifications, constant specifications, log specifications, script specifications, and exception handling specifications. After obtaining the encrypted string, the server calls the preset string comparison algorithm to compare the encrypted string with the string in the preset database, and determines the encrypted string that is consistent with the string length in the preset database as the initial translation result. If the initial string does not meet the grammatical specifications, this operation is skipped and a failure message is returned to the user end.
[0037] 104. Check and filter the initial translation result to obtain an intermediate translation result, and determine whether the intermediate translation result meets the preset translation standard. If the intermediate translation result meets the preset translation standard, generate a target translation result.
[0038] The server checks and filters the initial translation result to obtain an intermediate translation result, and determines whether the intermediate translation result meets the preset translation standard. If the intermediate translation result meets the preset translation standard, the target translation result is generated. The server calls a preset detection tool to detect the repeated values in the initial translation result to obtain a detection result. The preset detection tool includes but is not limited to jprofiler. jprofiler is a full-featured java analysis tool for checking and tracking. According to the detection result, the repeated values in the initial translation result are filtered to obtain the intermediate translation result. After the intermediate translation result is generated, the server automatically creates a 32-bit binary number flag information and returns the flag information to the user end. If the i-th bit is 1, it is determined that the translation of the i+1th node is normal. i is an integer greater than or equal to 0 and less than 32, that is, the intermediate translation result meets the preset translation standard, and the intermediate translation result is determined as the target translation result. If the i-th bit is 0, it is determined that the translation of the i+1th node is abnormal. The code line number, translation information and flag information are combined in a preset format to generate a notification and return it to the user end.
[0039] In the embodiment of the present invention, a preset traversal algorithm is called to traverse the node objects in the grammatical topology structure to obtain a target node object, and encryption processing based on a secure hash algorithm is performed on the target node object, thereby improving the security of translation.
[0040] See also Figure 2 Another embodiment of the code translation method in the embodiment of the present invention includes:
[0041] 201. Obtain the code to be translated, and perform conversion processing on the code to be translated based on a preset grammatical structure to obtain a grammatical topological structure.
[0042] The server obtains the code to be translated, performs conversion processing on the code to be translated based on a preset grammatical structure, and obtains a grammatical topological structure. Specifically, the server calls a preset operating platform, reads the code to be translated, and the code to be translated is stored in a preset code file, and the code to be translated is a code containing a preset code format; the server performs conversion processing on the code to be translated using the preset grammatical structure to obtain multiple grammatical blocks, and determines the logical relationship between the multiple grammatical blocks using a preset data structure processing algorithm to obtain a code logical relationship; the server connects the multiple grammatical blocks in sequence according to the code logical relationship to obtain a grammatical topological structure.
[0043] The server reads the code to be translated in the preset code file by calling the preset running platform node.js. The format of the code to be translated is javascript. node.js is a development platform that allows javascript to run on the server. The underlying architecture is javascript and the file suffix is .js. The server converts the code to be translated into a backward-compatible javascript syntax structure by calling the preset compiler babel to obtain multiple syntax blocks so that it can run in current and old versions of browsers or other environments. After obtaining multiple syntax blocks, the logical relationship between the multiple syntax blocks is determined by the preset data structure processing algorithm parser to obtain the code logical relationship. The server obtains the page jump keyword of the code to be translated, and determines the logical order of the code to be translated based on the page jump keyword through the data structure processing algorithm parser. The logical relationship between the multiple syntax blocks is determined according to the logical order of the code to be translated. The logical relationship includes at least one of a sequential step relationship, a judgment relationship and a subordinate relationship, and multiple syntax blocks are connected in sequence according to the code logical relationship to finally obtain a syntax topology structure. Parser generally refers to the process of converting text or strings in a certain format into a specific data structure.
[0044] 202. Call a preset traversal algorithm to traverse all node objects in the grammatical topology structure to obtain an initial node object, and determine the initial node object that meets a preset condition as a target node object.
[0045] The server calls a preset traversal algorithm, traverses all node objects in the grammatical topology structure, obtains an initial node object, and determines the initial node object that meets the preset conditions as the target node object. Specifically, the server obtains the starting position information and the ending position information of the grammatical topology structure, calls the preset traversal algorithm, and traverses the grammatical topology structure based on the starting position information and the ending position information to obtain the initial node object; the server reads the parameter value, node type and link information of the initial node object, and judges whether the initial node object meets the preset conditions according to the parameter value, node type and link information of the initial node object, and obtains the judgment result, the preset condition is the preset language information, and the link information is used to indicate the code logic relationship; if the judgment result of the server is that the preset language information exists in the initial node object, the initial node object is identified to obtain the target node object.
[0046] The server queries the starting position information and the ending position information of the grammatical topology structure. After obtaining the starting position information and the ending position information of the grammatical topology structure, the server traverses all the node objects in the abstract syntax tree through a preset traversal algorithm to obtain an initial node object. The traversal process includes but is not limited to at least one of pre-order traversal, in-order traversal and post-order traversal. The server reads the parameter value, node type and link information of the initial node object and identifies whether each initial node object contains preset language information. The node type includes value type, function type and variable type, etc. The link corresponding to the link information is used to connect multiple initial node objects. The link information is used to indicate the logical relationship of the code. For the initial node object containing the preset language information (the preset language information includes the node type and parameter value 1, and the node type is function or text), it is marked to obtain the target Node object, for example: the code corresponding to a function or the code corresponding to the text that the user wants to read needs to be translated, that is, the code to be translated, all objects in the grammatical topology structure are traversed according to the starting position and the ending position, and the initial node objects corresponding to all functions and text types are found. Assume that the starting position is 200 lines and the ending position is 510 lines. Within this range, 300 lines of node objects (300 lines of node objects are the initial node objects corresponding to 300 lines) are taken as an example to obtain the parameter value and node type of the 300 lines of node objects in the grammatical topology structure, and determine whether the node type is a function (or text) and whether the parameter value is 1. If the node type is a function (or text) and the parameter value is 1, the 300 lines of node objects are identified to obtain the target node object. If the node type is not a function (or text) or the parameter value is 0, an empty set is returned.
[0047] 203. Read the target node object, and convert the target node object into an initial string using a preset regular expression.
[0048] The server reads the target node object and converts the target node object into an initial string using a preset regular expression. A regular expression, also known as a rule expression, is used to retrieve and replace text that conforms to preset rules. A regular expression is a logical formula for string operations, and uses specific characters and combinations of these specific characters to form an initial string. In this embodiment, after the server reads the target node object, it converts the type of the target node object into a string type using a regular expression to obtain an initial string, thereby realizing the recognition and replacement of simplified and traditional Chinese characters and Chinese and English. The above method saves the reconstruction cost of javascript.
[0049] 204. Determine whether the initial character string conforms to a preset grammar specification and obtain a grammar determination result.
[0050] The server determines whether the initial string conforms to the preset grammatical specification and obtains a grammatical determination result. The server determines whether the initial string conforms to the preset grammatical specification, and the grammatical specification includes but is not limited to at least one of the naming specification, the comment specification, the development specification and design, the declaration specification, the transaction specification, the constant specification, the log specification, the script specification and the exception handling specification.
[0051] 205. Encrypt the initial string according to the grammar identification result to obtain an encrypted string, call a preset string comparison algorithm to compare the encrypted string with a string in a preset database to obtain a comparison result, and determine an initial translation result according to the comparison result.
[0052] The server encrypts the initial string according to the grammar identification result to obtain an encrypted string, and calls a preset string comparison algorithm to compare the encrypted string with the string in the preset database to obtain a comparison result, and determines the initial translation result according to the comparison result. Specifically, if the grammar identification result is that the initial string meets the preset grammar specification, the server calls the preset secure hash algorithm to preprocess and perform logical operations on the initial string to obtain an encrypted string; the server calls the preset string comparison algorithm to compare the encrypted string with the string in the preset database to obtain a comparison result; if the comparison result is that the encrypted string is consistent in length with the string in the preset database, the server determines the encrypted string as the initial translation result.
[0053] If the initial string meets the preset syntax specification, the server calls the secure hash algorithm to encrypt the initial string. The encryption algorithm called in this embodiment is the secure hash algorithm 2 (Secure Hash Algorithm 2, SHA-2) is divided into SHA256 algorithm, SHA-2 can be further divided into six different algorithm standards. Except for some minor differences in the length of the generated digest and the number of loop runs, the basic structure of these variants is basically the same. For a string of any length, the SHA256 algorithm will generate a 256-bit hash value, called a message digest. This digest is equivalent to an array of 32 bytes in length, usually represented by a hexadecimal string of 64 in length. The process of preprocessing the initial string includes adding padding bits and adding length values. The encrypted string is obtained by calling a preset logic function to perform logic bit operations. The preset string comparison algorithm is equalsIgnoreCase, which is used to compare whether two strings are equal. The server compares the length of the encrypted string with the length of the string in the preset database through the preset string comparison algorithm to obtain a comparison result. If the comparison result is that the length of the encrypted string is consistent with that of the string in the preset database, the encrypted string is determined as the initial translation result. If the comparison result is that the length of the encrypted string is inconsistent with that of the string in the preset database, this operation is skipped and a failure message is returned to the user end.
[0054] 206. Check and filter the initial translation result to obtain an intermediate translation result, and determine whether the intermediate translation result meets the preset translation standard. If the intermediate translation result meets the preset translation standard, generate a target translation result.
[0055] The server verifies and filters the initial translation result to obtain an intermediate translation result, and determines whether the intermediate translation result meets the preset translation standard. If the intermediate translation result meets the preset translation standard, the target translation result is generated. Specifically, the server calls a preset detection tool to detect the repeated values in the initial translation result to obtain the detection result, and filters the repeated values in the initial translation result according to the detection result to obtain the intermediate translation result; the server creates flag information, and determines whether the intermediate translation result meets the preset translation standard based on the flag information. If the intermediate translation result meets the preset translation standard, the intermediate translation result is determined as the target translation result, and the flag information is a binary number containing a preset number of bits.
[0056] The server verifies and filters the initial translation result to obtain an intermediate translation result, and determines whether the intermediate translation result meets the preset translation standard. If the intermediate translation result meets the preset translation standard, a target translation result is generated. The server calls a preset detection tool to detect duplicate values in the initial translation result to obtain a detection result, and the detection result is used to indicate whether there are duplicate values in the initial translation result. The preset detection tool includes but is not limited to jprofiler. jprofiler is a full-featured java profiling tool used for checking and tracking. If the detection result is that the initial translation result contains duplicate values, the unique value is retained and other duplicate values are deleted. If the detection result is that the initial translation result does not contain duplicate values, no processing is performed to obtain an intermediate translation result. After the intermediate translation result is generated, the server automatically creates a 32-bit binary number flag information and returns the flag information to the user end. If the i-th bit is 1, it is determined that the translation of the i+1-th node is normal, i is an integer greater than or equal to 0 and less than 32, that is, the intermediate translation result meets the preset translation standard, and the intermediate translation result is determined as the target translation result. If the i-th bit is 0, it is determined that the translation of the i+1-th node is abnormal, and the code line number, translation information and flag information are combined in a preset format to generate a notification and return it to the user end.
[0057] In the embodiment of the present invention, a preset traversal algorithm is called to traverse the node objects in the grammatical topology structure to obtain a target node object, and the target node object is encrypted based on a secure hash algorithm, thereby improving the security of translation.
[0058] The above describes the code translation method in the embodiment of the present invention. The following describes the code translation device in the embodiment of the present invention. Figure 3 , an embodiment of the code translation device in the embodiment of the present invention includes:
[0059] An acquisition module 301 is used to acquire the code to be translated, and perform conversion processing on the code to be translated based on a preset grammatical structure to obtain a grammatical topological structure;
[0060] The traversal module 302 is used to call a preset traversal algorithm to traverse all node objects in the grammatical topology structure to obtain an initial node object, and determine the initial node object that meets the preset conditions as the target node object;
[0061] The encryption module 303 is used to convert and encrypt the target node object to obtain an encrypted string, compare the encrypted string with the string in the preset database to obtain a comparison result, and determine the initial translation result according to the comparison result;
[0062] The generation module 304 is used to check and filter the initial translation result to obtain an intermediate translation result, determine whether the intermediate translation result meets the preset translation standard, and generate a target translation result if the intermediate translation result meets the preset translation standard.
[0063] In the embodiment of the present invention, a preset traversal algorithm is called to traverse the node objects in the grammatical topology structure to obtain a target node object, and the target node object is encrypted based on a secure hash algorithm, thereby improving the security of translation.
[0064] See also Figure 4 Another embodiment of the code translation device in the embodiment of the present invention includes:
[0065] An acquisition module 301 is used to acquire the code to be translated, and perform conversion processing on the code to be translated based on a preset grammatical structure to obtain a grammatical topological structure;
[0066] The traversal module 302 is used to call a preset traversal algorithm to traverse all node objects in the grammatical topology structure to obtain an initial node object, and determine the initial node object that meets the preset conditions as the target node object;
[0067] The encryption module 303 is used to convert and encrypt the target node object to obtain an encrypted string, compare the encrypted string with the string in the preset database to obtain a comparison result, and determine the initial translation result according to the comparison result;
[0068] The encryption module 303 specifically includes:
[0069] The conversion unit 3031 is used to read the target node object and convert the target node object into an initial string through a preset regular expression;
[0070] The second judgment unit 3032 is used to judge whether the initial character string conforms to a preset grammar specification and obtain a grammar judgment result;
[0071] The encryption unit 3033 is used to encrypt the initial string according to the grammar identification result to obtain an encrypted string, and call a preset string comparison algorithm to compare the encrypted string with the string in the preset database to obtain a comparison result, and determine the initial translation result according to the comparison result;
[0072] The generation module 304 is used to check and filter the initial translation result to obtain an intermediate translation result, determine whether the intermediate translation result meets the preset translation standard, and generate a target translation result if the intermediate translation result meets the preset translation standard.
[0073] Optionally, the acquisition module 301 includes:
[0074] The reading unit 3011 is used to call a preset operation platform and read the code to be translated, where the code to be translated is stored in a preset code file and is a code containing a preset code format;
[0075] A determination unit 3012 is used to convert the code to be translated through a preset grammatical structure to obtain multiple grammatical blocks, and to determine the logical relationship between the multiple grammatical blocks through a preset data structure processing algorithm to obtain a code logical relationship;
[0076] The connection unit 3013 is used to connect multiple grammar blocks in sequence according to the code logic relationship to obtain a grammar topology structure.
[0077] Optionally, the traversal module 302 includes:
[0078] The traversal unit 3021 is used to obtain the starting position information and the ending position information of the grammatical topological structure, call the preset traversal algorithm, and traverse the grammatical topological structure based on the starting position information and the ending position information to obtain the initial node object;
[0079] The first judgment unit 3022 is used to read the parameter value, node type and link information of the initial node object, and judge whether the initial node object meets the preset condition according to the parameter value, node type and link information of the initial node object, and obtain a judgment result, where the preset condition is preset language information, and the link information is used to indicate the code logic relationship;
[0080] The identification unit 3023 is used to identify the initial node object to obtain the target node object if the judgment result is that the preset language information exists in the initial node object.
[0081] Optionally, the identification unit 3023 may also be specifically used for:
[0082] If the judgment result is that the preset language information exists in the initial node object, a non-empty subset is returned, and the non-empty subset is used to indicate the location information of the target node object. The initial node object corresponding to the non-empty subset is marked to obtain the marked node object; the marked node object is determined as the target node object.
[0083] Optionally, the encryption unit 3033 may also be specifically used for:
[0084] If the grammatical judgment result is that the initial string conforms to the preset grammatical specifications, the preset secure hash algorithm is called to preprocess and perform logical operations on the initial string to obtain an encrypted string; the preset string comparison algorithm is called to compare the encrypted string with the string in the preset database to obtain a comparison result; if the comparison result is that the encrypted string is consistent with the string in the preset database in length, the encrypted string is determined as the initial translation result.
[0085] Optionally, the generating module 304 includes:
[0086] The detection unit 3041 is used to call a preset detection tool to detect the repeated values in the initial translation result to obtain a detection result, and filter the repeated values in the initial translation result according to the detection result to obtain an intermediate translation result;
[0087] The generating unit 3042 is used to create flag information and determine whether the intermediate translation result meets the preset translation standard based on the flag information. If the intermediate translation result meets the preset translation standard, the intermediate translation result is determined as the target translation result. The flag information is a binary number containing a preset number of bits.
[0088] In the embodiment of the present invention, a preset traversal algorithm is called to traverse the node objects in the grammatical topology structure to obtain a target node object, and encryption processing based on a secure hash algorithm is performed on the target node object, thereby improving the security of translation.
[0089] above Figure 3 and Figure 4 The code translation apparatus in the embodiment of the present invention is described in detail from the perspective of modular functional entities. The code translation device in the embodiment of the present invention is described in detail from the perspective of hardware processing.
[0090] Figure 5 1 is a schematic diagram of the structure of a code translation device provided by an embodiment of the present invention. The code translation device 500 may have relatively large differences due to different configurations or performances, and may include one or more processors (central processing units, CPU) 510 (for example, one or more processors) and a memory 520, and one or more storage media 530 (for example, one or more mass storage devices) storing application programs 533 or data 532. Among them, the memory 520 and the storage medium 530 may be temporary storage or permanent storage. The program stored in the storage medium 530 may include one or more modules (not shown in the figure), and each module may include a series of instruction operations in the code translation device 500. Furthermore, the processor 510 may be configured to communicate with the storage medium 530 to execute a series of instruction operations in the storage medium 530 on the code translation device 500.
[0091] The code translation device 500 may also include one or more power supplies 540, one or more wired or wireless network interfaces 550, one or more input and output interfaces 560, and / or one or more operating systems 531, such as Windows Serve, Mac OS X, Unix, Linux, FreeBSD, etc. It will be appreciated by those skilled in the art that Figure 5 The structure of the code translation device shown does not constitute a limitation on the code translation device, and the code translation device may include more or less components than shown in the figure, or combine some components, or arrange the components differently.
[0092] The present invention also provides a code translation device, the computer device includes a memory and a processor, the memory stores computer-readable instructions, and when the computer-readable instructions are executed by the processor, the processor executes the steps of the code translation method in the above embodiments.
[0093] The present invention also provides a computer-readable storage medium, which may be a non-volatile computer-readable storage medium or a volatile computer-readable storage medium. Instructions are stored in the computer-readable storage medium. When the instructions are executed on a computer, the computer executes the steps of the code translation method.
[0094] The blockchain referred to in this invention is a new application mode of computer technologies such as distributed data storage, peer-to-peer transmission, consensus mechanism, encryption algorithm, etc. Blockchain is essentially a decentralized database, a string of data blocks generated by cryptographic methods. Each data block contains a batch of network transaction information, which is used to verify the validity of its information (anti-counterfeiting) and generate the next block. Blockchain can include the underlying blockchain platform, platform product service layer, and application service layer.
[0095] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working processes of the systems, devices and units described above can refer to the corresponding processes in the aforementioned method embodiments and will not be repeated here.
[0096] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention is essentially or the part that contributes to the prior art or all or part of the technical solution can be embodied in the form of a software product. The computer software product is stored in a storage medium, including several instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present invention. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM), random access memory (RAM), disk or optical disk and other media that can store program codes.
[0097] As described above, the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit the same. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that the technical solutions described in the aforementioned embodiments may still be modified, or some of the technical features thereof may be replaced by equivalents. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present invention.
Claims
1. A code translation method, characterized in that: The code translation method comprises: Obtaining a code to be translated, and performing conversion processing on the code to be translated based on a preset grammatical structure to obtain a grammatical topological structure; Calling a preset traversal algorithm to traverse all node objects in the grammatical topology structure to obtain an initial node object, and determining the initial node object that meets a preset condition as a target node object; Converting and encrypting the target node object to obtain an encrypted string, comparing the encrypted string with a string in a preset database to obtain a comparison result, and determining an initial translation result according to the comparison result; The converting and encrypting the target node object to obtain an encrypted string, and comparing the encrypted string with a string in a preset database to obtain a comparison result, and determining the initial translation result according to the comparison result includes: Read the target node object, and convert the target node object into an initial string using a preset regular expression; Determine whether the initial character string conforms to a preset grammar specification, and obtain a grammar determination result; Encrypting the initial character string according to the grammar discrimination result to obtain an encrypted character string, calling a preset character string comparison algorithm to compare the encrypted character string with a character string in a preset database to obtain a comparison result, and determining an initial translation result according to the comparison result; Performing inspection and filtering on the initial translation result to obtain an intermediate translation result, determining whether the intermediate translation result meets a preset translation standard, and generating a target translation result if the intermediate translation result meets the preset translation standard; The encrypting process is performed on the initial character string according to the grammar identification result to obtain an encrypted character string, and a preset character string comparison algorithm is called to compare the encrypted character string with a character string in a preset database to obtain a comparison result, and the initial translation result is determined according to the comparison result, including: If the grammar determination result is that the initial character string conforms to the preset grammar specification, then calling a preset secure hash algorithm to perform preprocessing and logical operations on the initial character string to obtain an encrypted character string; Calling a preset string comparison algorithm to compare the encrypted string with the string in a preset database to obtain a comparison result; If the comparison result is that the length of the encrypted string is consistent with the string in the preset database, the encrypted string is determined as the initial translation result; The checking and filtering of the initial translation result to obtain an intermediate translation result, and judging whether the intermediate translation result meets a preset translation standard, and if the intermediate translation result meets the preset translation standard, generating a target translation result comprises: Calling a preset detection tool to detect duplicate values in the initial translation result to obtain a detection result, and filtering duplicate values in the initial translation result according to the detection result to obtain an intermediate translation result; Create flag information, and determine whether the intermediate translation result meets the preset translation standard based on the flag information. If the intermediate translation result meets the preset translation standard, determine the intermediate translation result as the target translation result, and the flag information is a binary number containing a preset number of bits.
2. The code translation method according to claim 1, characterized in that: The obtaining of the code to be translated and the conversion processing of the code to be translated based on a preset grammatical structure to obtain a grammatical topological structure include: Calling a preset operation platform to read a code to be translated, wherein the code to be translated is stored in a preset code file and is a code including a preset code format; The code to be translated is converted by a preset grammatical structure to obtain a plurality of grammatical blocks, and a logical relationship between the plurality of grammatical blocks is determined by a preset data structure processing algorithm to obtain a code logical relationship; According to the code logic relationship, the multiple grammar blocks are connected in sequence to obtain a grammar topology structure.
3. The code translation method according to claim 1, characterized in that: The calling of a preset traversal algorithm, traversing all node objects in the grammatical topology structure, obtaining an initial node object, and determining the initial node object that meets a preset condition as a target node object comprises: Obtaining the starting position information and the ending position information of the grammatical topological structure, calling a preset traversal algorithm, and traversing the grammatical topological structure based on the starting position information and the ending position information to obtain an initial node object; Reading the parameter value, node type and link information of the initial node object, judging whether the initial node object meets a preset condition according to the parameter value, node type and link information of the initial node object, and obtaining a judgment result, wherein the preset condition is preset language information, and the link information is used to indicate a code logic relationship; If the judgment result is that the preset language information exists in the initial node object, the initial node object is identified to obtain a target node object.
4. The code translation method according to claim 3, characterized in that: If the judgment result is that the preset language information exists in the initial node object, the initial node object is identified to obtain the target node object, including: If the judgment result is that the preset language information exists in the initial node object, a non-empty subset is returned, and the non-empty subset is used to indicate the position information of the target node object; Marking the initial node object corresponding to the non-empty subset to obtain a marked node object; The marked node object is determined as the target node object.
5. A code translation device, executing the code translation method according to any one of claims 1 to 4, characterized in that: The code translation device comprises: An acquisition module is used to acquire the code to be translated, and perform conversion processing on the code to be translated based on a preset grammatical structure to obtain a grammatical topological structure; A traversal module is used to call a preset traversal algorithm to traverse all node objects in the grammatical topology structure to obtain an initial node object, and determine the initial node object that meets the preset conditions as the target node object; An encryption module, used for converting and encrypting the target node object to obtain an encrypted string, and comparing the encrypted string with a string in a preset database to obtain a comparison result, and determining an initial translation result according to the comparison result; The generating module is used to check and filter the initial translation result to obtain an intermediate translation result, determine whether the intermediate translation result meets the preset translation standard, and generate a target translation result if the intermediate translation result meets the preset translation standard.
6. A code translation device, characterized in that: The code translation device comprises: A memory and at least one processor, wherein instructions are stored in the memory; The at least one processor calls the instructions in the memory to enable the code translation device to execute the code translation method according to any one of claims 1 to 4.
7. A computer-readable storage medium having instructions stored thereon, characterized in that: When the instructions are executed by a processor, the code translation method as described in any one of claims 1 to 4 is implemented.
Citation Information
Patent Citations
Code segment translation method and device, computer equipment and storage medium
CN110134397A
JavaScript code translation method and device, computer equipment and storage medium
CN112015430A