A multi-terminal code mapping and translation method for an Internet medical platform
Through in-depth lexical analysis and abstract syntax tree generation, combined with information entropy value and context correlation weight, multi-terminal code mapping and translation of the Internet medical platform is realized, solving the problems of inefficiency and semantic errors of traditional methods, and improving the code translation Quality and efficiency ensure the correctness and security of the code in a heterogeneous environment.
Patent Information
- Application Number
- CN202411402188.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-10-09
- Publication Date
- 2024-12-31
- Estimated Expiration
- 2044-10-09
AI Technical Summary
In the field of Internet medical care, traditional code translation methods require a large number of manual tuning for each platform, which is inefficient, easy to introduce errors, and difficult to evaluate the contextual relevance of code complexity, resulting in inefficient translation or semantic errors and lack of automation and intelligence.
By obtaining the source code files of the medical platform, lexical analysis is performed to generate an abstract syntax tree, extracting key code snippets, calculating information entropy values and context correlation weights, sorting and mapping and translation, generating target code files, and reverse them on different terminal devices Run to the map.
Improve the quality and efficiency of code translation, ensure the semantic correctness of the code in a heterogeneous environment, reduce errors and security risks, realize flexible code conversion and optimization, reduce development and maintenance costs, and improve the response of medical platforms. Speed and user experience.
Smart Images

Figure CN118916031B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of terminal code technology, and more specifically, to a multi-terminal code mapping and translation method for an Internet medical platform. Background Art
[0002] The patent with application publication number CN104360850A discloses a business code processing method and device, including: receiving a request for obtaining a code description sent by an external application, the request containing associated information of the code description, the associated information including a code type and a code value; determining whether the code type has been loaded in a pre-generated code translation mapping relationship table, and if so, obtaining a code description corresponding to the code value from the code translation mapping relationship table; sending the code description corresponding to the code value obtained from the code translation mapping relationship table to the external application, which can reduce the memory overhead and redundancy of the application, and realize efficient and convenient translation of business codes and synchronous sharing of code translation mapping relationships.
[0003] However, in the field of Internet medicine, due to the huge differences in the hardware architecture and operating systems of terminal medical devices, traditional code translation methods often require a lot of manual tuning for each platform system, which is inefficient and prone to errors; the efficiency of its control code running on different devices varies, which will seriously affect accuracy and security; on the other hand, existing code translation methods often find it difficult to accurately evaluate the complexity and context relevance of the code, resulting in inefficiency or semantic errors in the translation results; in addition, the traditional code translation process lacks automation and intelligence, and requires a lot of manual intervention and coding, which is not only inefficient but also prone to human errors.
[0004] In view of this, the present invention proposes a multi-terminal code mapping and translation method for an Internet medical platform to solve the above-mentioned problem. Summary of the invention
[0005] In order to overcome the above defects of the prior art and to achieve the above objectives, the present invention provides the following technical solutions: A multi-terminal code mapping and translation method for an Internet medical platform, comprising: S1, obtaining a source code file to be translated of a medical platform, the source code file comprising n code segments, performing lexical analysis on the source code file, and generating an abstract syntax tree;
[0006] S2, traverse the abstract syntax tree, extract key code snippets, and calculate the information entropy value and context relevance weight of each key code snippet;
[0007] S3, sorting each key code snippet according to the corresponding information entropy value and context relevance weight to obtain an ordered code snippet sequence;
[0008] S4, mapping and translating the ordered code fragment sequence to generate a target code file;
[0009] S5. Distribute the target code file to different terminal medical devices, and the different terminal medical devices reversely map and run the target code file.
[0010] Furthermore, the method of generating an abstract syntax tree includes:
[0011] Convert the source code file into a character stream, extract lexical units from the character stream, and generate a lexical unit sequence; perform grammatical analysis on the lexical unit sequence, build a syntax tree, preprocess the syntax tree, and reorganize the hierarchical structure of the nodes in the syntax tree to obtain an abstract syntax tree.
[0012] Furthermore, the method of generating a lexical unit sequence includes:
[0013] Initialize an empty sequence shell, read the characters in the character stream one by one, and use a pointer to record the current reading position in real time;
[0014] Define the lexical unit type and build a corresponding prefix tree for each lexical unit type; starting from the current read position, try to match the prefix tree corresponding to each lexical unit type in turn; if the prefix tree successfully matches the current character, extract the corresponding lexical unit;
[0015] Determine the type and value of the lexical unit according to the corresponding prefix tree, and record the position information of the lexical unit in the source code file. Based on the type, value and position information of the lexical unit, construct a lexical unit instance and add it to the sequence shell. Move the pointer to the end position of the lexical unit extracted this time, and repeat until the character stream is read; the final sequence shell is the lexical unit sequence.
[0016] Furthermore, the method of converting the source code file into a character stream includes:
[0017] Initially define an initial memory buffer with a size of , use file I / O operation to open the source code file, obtain the file stream object, read the file stream object byte by byte, obtain m file blocks, store the m file blocks in the memory buffer in sequence, and dynamically adjust the size of the memory buffer to ;
[0018] ;in, is the total size of m file blocks, is the size of the file block that has been read, is the total memory size, is the currently used memory, The upper limit of the preset memory buffer size. and is the regulating factor, and is the exponential factor; is the adjustment function, is the I / O throughput, is the CPU utilization, is the degree of memory fragmentation;
[0019] Adjustment function ;in, is the throughput adjustment factor, is the utilization adjustment coefficient, is the memory fragmentation adjustment factor;
[0020] The file blocks in the memory buffer are preprocessed to obtain preprocessed file blocks, and the preprocessed file blocks are converted into character streams; that is, characters in the preprocessed file blocks are read one by one and form a character sequence, namely, a character stream.
[0021] Furthermore, the method of preprocessing the file blocks in the memory buffer includes:
[0022] Define a quintuple ,in, is the state set, To input the alphabet, is the state transfer function, is the initial state, and ; is a set of terminal states, and ;
[0023] State transfer function ,in, is the current state, is the input character, For the new state;
[0024] Based on m file blocks, define the state set and input alphabet ;
[0025] Read characters one by one from the file block in the memory buffer , according to the current state and the characters read , the new state is obtained by calculating the state transfer function If the new state belong , then perform the corresponding preprocessing operations; update the current state to , repeat until all characters in the file block in the memory buffer are read; that is, the preprocessed file block is obtained.
[0026] Furthermore, the method of performing grammatical analysis on the lexical unit sequence includes:
[0027] Define grammar rules, that is, analyze the grammar of the programming language; based on the defined grammar rules, initialize a grammar tree, create a root node, extract lexical units from the lexical unit sequence, match them with the grammar rules, and create a new node as the left child of the root node; match the first lexical unit, make it the child of the newly created left child node, match the operator, and create a new node as the right child of the root node; continue matching according to the written production rule, create a new node as the right child node te of the right child node of the root node, match the second lexical unit, make it the right child node of the newly created te, match the operator, create a new node as the left child node tw of the right child node te; continue matching the third lexical unit according to the written production rule, create a new node as the right child node of tw, and repeat until the extraction of lexical units in the lexical unit sequence is completed; that is, the construction of the grammar tree is completed.
[0028] Furthermore, the method of reorganizing the hierarchical structure of the nodes in the syntax tree includes:
[0029] The tree reconstruction rules are defined as a set of pattern matching rules, each of which consists of a matching pattern and a reconstruction action;
[0030] There are m2 matching modes, which define the structure of the subtree that needs to be reconstructed; the reconstruction actions include node promotion, node merging, and node splitting;
[0031] For each pattern matching rule Assign a priority weight ; For any two pattern matching rules and , which match the syntax tree Subtree in and ; If the matching patterns they match have a nested relationship, calculate the nested value between them ;
[0032] like , then reconstruct first ;like , then reconstruct first ;like , then compare and Their respective weights, the one with higher weight will be reconstructed first;
[0033] ;
[0034] in, , and is the adjustment coefficient, for and The nearest common ancestor node, for The root node of for and The size difference, for and the degree of overlap; For syntax tree middle The depth of For syntax tree middle Depth
[0035] The reconstruction process includes:
[0036] Construct a priority queue Q. Initially, put all pattern matching rules into the priority queue Q in descending order of priority. When traversing to a node n', take out the pattern matching rule corresponding to the highest priority from Q. , match the matching pattern in the subtree with n' as the root. If the match is successful, perform the reconstruction action to obtain the reconstructed subtree, and adjust other pattern matching rules in Q according to the reconstruction action;
[0037] If the match fails, continue to match the pattern matching rule corresponding to the next priority until all pattern matching rules are traversed and all reconstructed subtrees replace the original syntax tree, thus completing the generation of the abstract syntax tree.
[0038] Furthermore, the information entropy value and context relevance weight of each key code snippet are calculated in the following manner:
[0039] Represent each key code snippet as a corresponding sequence of tokens, where each token is a keyword, identifier, or literal;
[0040] Count each unique token In the key code snippet Frequency of occurrence ; Based on frequency Calculate the key code snippet Information entropy value ;
[0041] ,
[0042] in, for The complexity of the code snippet is for The data flow complexity of and is the information adjustment coefficient;
[0043] ;in, for The cyclomatic complexity of for The branch complexity of for Length; , and is the weight adjustment parameter;
[0044] Cyclomatic complexity refers to the number of nested loops in a key code snippet and the number of branch complexities.
[0045] Complexity refers to the number and conditional branch statements in a code snippet;
[0046] ;in, for The scope complexity of for The dependency complexity, for The number of variables in the code; scope complexity refers to the sum of the nesting levels of variable scopes in key code snippets;
[0047] ;in, It is The weight coefficient of the variable, For the The dependency depth of each variable, Adjust parameters for dependencies; For the A control over the complexity of dependencies;
[0048] The key code snippet and its context are converted into vector representations, and the cosine similarity between them is calculated as the semantic similarity ;
[0049] Calculate key code snippets The mean structural similarity with other key code snippets ; Use the n-gram model to calculate statistical similarity ;
[0050] Based on semantic similarity , structural similarity and statistical similarity , calculate the key code snippet The contextual relevance weight ,
[0051] ;in, is the first adjustment coefficient; is the second adjustment coefficient.
[0052] Furthermore, the calculation method of the structural similarity mean includes:
[0053] Traverse the abstract syntax tree and extract the subtree corresponding to each key code fragment according to the location information of the extracted key code fragment.
[0054] Define tree editing operations including node renaming, node deletion and node insertion, and assign a cost value to each of node renaming, node deletion and node insertion;
[0055] for The corresponding subtree and any subtree , the calculation will Convert to The minimum edit cost of ;
[0056] The calculation method of the minimum editing cost includes:
[0057] Initialize a two-dimensional table with rows and columns corresponding to and The nodes in the table calculate the value of each cell in the two-dimensional table from bottom to top, indicating that The subtree is converted to The minimum editing cost of the subtree of ;
[0058] but ;in, is the number of all subtrees, and Respectively and The number of nodes;
[0059] The method of obtaining the ordered code snippet sequence includes:
[0060] The information entropy value and context relevance weight of each key code snippet are weighted and summed to obtain a comprehensive score value of each key code snippet; all key code snippets are arranged in descending order according to the size of the comprehensive score value to obtain an ordered code snippet sequence;
[0061] The object code file is obtained by:
[0062] Traversing the ordered code snippet sequence, mapping each key code snippet to an equivalent code snippet in the target language, and merging the mapped target code snippets according to the context information of the key code snippet in the source code file to obtain a target code file;
[0063] The reverse mapping method is to convert the target code file into machine code or intermediate code that is directly executed by the terminal medical device.
[0064] A multi-terminal code mapping and translation system for an Internet medical platform, which is used to implement a multi-terminal code mapping and translation method for an Internet medical platform, comprises: a source code acquisition and analysis module, which is used to acquire a source code file to be translated of a medical platform, the source code file comprising n code segments, perform lexical analysis on the source code file, and generate an abstract syntax tree;
[0065] The fragment extraction and analysis module is used to traverse the abstract syntax tree, extract key code fragments, and calculate the information entropy value and context relevance weight of each key code fragment;
[0066] A fragment sorting module is used to sort each key code fragment according to the corresponding information entropy value and context relevance weight to obtain an ordered code fragment sequence;
[0067] A code mapping and translation module is used to map and translate the ordered code snippet sequence to generate a target code file;
[0068] The distribution mapping module is used to distribute the target code file to different terminal medical devices, and the different terminal medical devices reversely map and run the running target code file.
[0069] The technical effects and advantages of the multi-terminal code mapping and translation method for an Internet medical platform of the present invention are as follows:
[0070] The present invention improves the quality and efficiency of code translation through in-depth lexical analysis and abstract syntax tree generation. Different terminal medical devices can efficiently execute the target code after translation optimization, thereby improving the performance and reliability of the medical information system; the introduced information entropy value and context relevance weight calculation mechanism generates higher-quality and more efficient target code, which not only helps to improve the operating speed of the system, but also ensures the semantic correctness of the code in various heterogeneous environments, thereby reducing potential errors and safety hazards, realizing flexible code conversion and optimization, and significantly reducing development and maintenance costs; the automation and intelligence of the code translation process greatly reduces the workload of manual intervention and coding, improves translation efficiency and accuracy, and effectively improves the response speed and user experience of the medical platform. BRIEF DESCRIPTION OF THE DRAWINGS
[0071] Figure 1 A schematic diagram of a multi-terminal code mapping and translation method for an Internet medical platform according to the present invention;
[0072] Figure 2 The present invention is a schematic diagram of a multi-terminal code mapping and translation system for an Internet medical platform. DETAILED DESCRIPTION
[0073] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0074] Example 1
[0075] See also Figure 1 As shown, the multi-terminal code mapping and translation method for an Internet medical platform described in this embodiment includes:
[0076] S1. Obtain a source code file to be translated of a medical platform, the source code file includes n code segments, perform lexical analysis on the source code file, and generate an abstract syntax tree;
[0077] S2, traverse the abstract syntax tree, extract key code snippets, and calculate the information entropy value and context relevance weight of each key code snippet;
[0078] S3, sorting each key code snippet according to the corresponding information entropy value and context relevance weight to obtain an ordered code snippet sequence;
[0079] S4, mapping and translating the ordered code fragment sequence to generate a target code file;
[0080] S5. Distribute the target code file to different terminal medical devices. Different terminal medical devices reversely map and run the target code file; realize cross-platform code translation and improve the running efficiency of the code in a heterogeneous environment.
[0081] Furthermore, the method of generating an abstract syntax tree includes:
[0082] Convert a source code file into a character stream (a sequence of characters organized in sequence), extract tokens from the character stream, and generate a sequence of tokens.
[0083] Specifically, an empty sequence shell is initialized, characters in the character stream are read one by one, and a pointer is used to record the current reading position in real time.
[0084] Define lexical unit types (such as keywords, identifiers, numbers, etc.), and build a corresponding prefix tree for each lexical unit type (organize and store string sets according to the string's prefix path); for each lexical unit type, store all possible strings it contains (such as a keyword list) in a prefix tree.
[0085] Starting from the current read position, try to match the prefix tree corresponding to each lexical unit type in turn; if the prefix tree matches the current character successfully, the corresponding lexical unit is extracted.
[0086] Determine the type and value of the lexical unit according to the corresponding prefix tree, and record the position information of the lexical unit in the source code file (such as line number, column number, etc.). Based on the type, value and position information of the lexical unit, construct a lexical unit instance and add it to the sequence shell. Move the pointer to the end position of the lexical unit extracted this time, and repeat until the character stream is read; the final sequence shell is the lexical unit sequence.
[0087] The method of converting the source code file into a character stream includes:
[0088] Initially define an initial memory buffer with a size of (The initial memory buffer size can be set to a smaller value, for example, 4KB or 8KB), use file I / O operations to open the source code file, obtain the file stream object, read the file stream object byte by byte, obtain m file blocks (the source code file is divided into multiple small blocks of data), store the m file blocks in the memory buffer in sequence, and dynamically adjust the size of the memory buffer to .
[0089] ;in, is the total size of m file blocks, is the size of the file block that has been read, is the total memory size (the total memory of the system), is the currently used memory, The upper limit of the preset memory buffer size. and is an adjustment factor used to control the ratio between the new buffer size and the remaining file size and the current available memory. and is an exponential factor used to adjust the impact of the remaining file size and the current available memory on the buffer size; is the adjustment function, is the I / O throughput, is the CPU utilization, The degree of memory fragmentation.
[0090] The degree of memory fragmentation is 1 minus the size of the largest contiguous free block in available memory divided by the total available memory size.
[0091] Adjustment function ;in, is the throughput adjustment factor, is the utilization adjustment coefficient, It is the memory fragmentation adjustment coefficient, which is used to control the influence of various factors on the buffer size.
[0092] The file blocks in the memory buffer are preprocessed to obtain preprocessed file blocks, and the preprocessed file blocks are converted into character streams.
[0093] The method of preprocessing the file blocks in the memory buffer includes:
[0094] Define a quintuple ,in, is the state set, To input the alphabet, is the state transfer function, is the initial state, and ; is a set of terminal states, and .
[0095] State transfer function ,in, is the current state, is the input character, To the new state.
[0096] Based on m file blocks, define the state set and input alphabet ; Specifically, initialize the state set to be an empty set; initialize the input alphabet to be empty; traverse m file blocks and perform the following operations on each file block:
[0097] Scan each character w in the file block. If w appears for the first time, add it to the input alphabet. According to the type of w (such as letter, number, special character, etc.), add its corresponding state to the state set. For example, if w is a letter, it may correspond to the identifier start state; if w is a number, it may correspond to the numeric start state, etc. For each new state, define its subsequent possible state transitions according to the lexical rules of the language. After traversing all file blocks, the state set and input alphabet are constructed.
[0098] Read characters one by one from the file block in the memory buffer , according to the current state and the characters read , the new state is obtained by calculating the state transfer function If the new state belong , then perform the corresponding preprocessing operations (delete comments, delete whitespace characters, whitespace characters include spaces, tabs, and newlines).
[0099] Update the current status to , repeat until all characters in the file block in the memory buffer are read; that is, the preprocessed file block is obtained.
[0100] The preprocessed file block is converted into a character stream, that is, the characters in the preprocessed file block are read one by one and form a character sequence, namely, a character stream.
[0101] Perform grammatical analysis on the lexical unit sequence and construct a syntax tree to represent the grammatical structure of the source code;
[0102] Specifically, define grammar rules, that is, analyze the grammar of the programming language (terminal symbols, non-terminal symbols, and write production rules).
[0103] Based on the defined grammar rules, a grammar tree is initialized, a root node is created, lexical units are extracted from the lexical unit sequence, and matched with the grammar rules, and a new node is created as the left child node of the root node; the first lexical unit matched is used as the child node of the newly created left child node, the operator (terminal symbol, non-terminal symbol and other operators) is matched, and a new node is created as the right child node of the root node; according to the written production rule, the matching continues, and a new node is created as the right child node te of the right child node of the root node; the second lexical unit is matched, and it is used as the right child node of the newly created te, and the operator is matched, and a new node is created as the left child node tw of the right child node te; according to the written production rule, the third lexical unit is continued to be matched, and a new node is created as the right child node of tw, and the extraction of lexical units in the lexical unit sequence is completed; that is, the construction of the grammar tree is completed.
[0104] During the construction process, each time a written production is matched, a corresponding node is created in the syntax tree, and the child nodes are correctly connected to the parent nodes, with the terminal symbols (lexical units) as leaf nodes and the non-terminal symbols as internal nodes.
[0105] At the same time, it should be noted that if any of the written productions cannot be matched, it indicates a grammatical error. For ambiguous grammars, there may be multiple syntax trees, which need to be resolved according to the language priority and associativity rules.
[0106] Based on the syntax tree, an abstract syntax tree is generated; specifically, the syntax tree is preprocessed, that is, each node in the syntax tree is traversed and meaningless nodes such as comments and blank characters are removed.
[0107] And reorganize the hierarchical structure of the nodes in the syntax tree to make the structure of the abstract syntax tree flatter; specifically, define the tree reconstruction rules as a set of pattern matching rules to guide the adjustment of the node hierarchical structure of the abstract syntax tree, and each pattern matching rule consists of a matching pattern and a reconstruction action.
[0108] There are m2 types of matching patterns, which define the structure of the subtree that needs to be reconstructed. For example, the matching pattern BinaryExpr(op, Literal, Literal) represents a binary operation expression, and both of its operands are literals.
[0109] Reconstruction actions include node promotion, node merging, and node splitting; for each pattern matching rule Assign a priority weight , the higher the priority, the earlier the reconstruction will be performed.
[0110] Specifically, a basic weight is assigned to each pattern matching rule, which can range from 1 to 100. This basic weight reflects the basic importance of the rule in the reconstruction process and is adjusted in real time according to the complexity of the pattern.
[0111] For any two pattern matching rules and , which match the syntax tree Subtree in and ; If the matching patterns they match have a nested relationship, calculate the nested value between them ;
[0112] like , then reconstruct first ;like , then reconstruct first ;like , then compare and The weights of each are determined, and the ones with higher weights are reconstructed first.
[0113] ;in, , and is the adjustment coefficient, which is used to control the influence of various factors on the nesting depth. Its value range is [0, 1]. for and The nearest common ancestor node, for The root node of for and The size difference is expressed as the difference in the number of nodes or subtree heights. for and The degree of overlap is expressed as the ratio of their overlapping nodes to the total number of nodes; For syntax tree middle The depth of the root node is 0. For syntax tree middle Depth.
[0114] The reconstruction process includes:
[0115] Construct a priority queue Q. Initially, all pattern matching rules are placed in the priority queue Q in descending order according to their priorities (based on the nesting value). Each time a node n' is traversed, the pattern matching rule corresponding to the highest priority is taken out from Q. , match the matching pattern in the subtree with n' as the root. If the match is successful, perform the reconstruction action to obtain the reconstructed subtree, and adjust other pattern matching rules in Q according to the reconstruction action (if the reconstruction action destroys the matching pattern of other pattern matching rules, these pattern matching rules need to be put back into the queue).
[0116] If the match fails, continue to match the pattern matching rule corresponding to the next priority until all pattern matching rules are traversed and all reconstructed subtrees replace the original syntax tree, thus completing the generation of the abstract syntax tree.
[0117] Furthermore, the method of extracting key code snippets includes:
[0118] Key code snippets include the content of the code snippet (in string form), the type of the code snippet (function definition, loop statement, conditional statement, etc.), the location information of the code snippet in the source code (file name, line number, column number range), and the parent node information of the code snippet (used to determine the context).
[0119] Use depth-first traversal or breadth-first traversal algorithm to traverse each node of the abstract syntax tree. For each node, identify the key parts of the code according to predefined rules, such as function definition, function call, variable assignment, control flow statement, etc. These key parts usually correspond to specific node types or node combination patterns in the abstract syntax tree.
[0120] For the identified key code snippets, the corresponding source code text is extracted (the corresponding source code position and range can be traced back from the syntax tree node, and the corresponding code text is extracted).
[0121] The information entropy value and context relevance weight of each key code snippet are calculated as follows:
[0122] Represent each key code snippet as a corresponding sequence of tokens, where each token is a keyword, identifier, or literal.
[0123] Count each unique token In the key code snippet Frequency of occurrence ; Based on frequency Calculate the key code snippet Information entropy value ;
[0124] ,in, for The complexity of the code snippet is for The data flow complexity of and is the information adjustment coefficient, which is used to control the influence of code snippet complexity and data flow complexity on the information entropy value.
[0125] ;in, for The cyclomatic complexity of for The branch complexity of for The length of (total number of tokens); , and It is a weight adjustment parameter to control the impact of each variable on the complexity of the code snippet.
[0126] Cyclomatic complexity refers to the sum of the number of nested loops in the key code snippet; branch complexity refers to the sum of the number of conditional branch statements in the code snippet.
[0127] ;in, for The scope complexity of for The dependency complexity, for The number of variables in .
[0128] It needs to be explained that in the abstract syntax subtree, all identifier nodes that are leaf nodes correspond to variables. Specifically, traverse the abstract syntax subtree corresponding to the key code snippet to find all leaf nodes. These leaf nodes are either constant values or identifiers (variable names). For leaf nodes that are identifiers, obtain the variable name of the identifier and count the total number of these variable names.
[0129] Scope complexity refers to the sum of the nesting levels of variable scopes in key code snippets, and dependency complexity refers to the complexity of data dependencies between variables in key code snippets.
[0130] ;in, It is The weight coefficient of a variable reflects the importance of the variable in the key code snippet. For the The dependency depth of a variable is the number of other variables that the variable depends on. Adjust parameters for dependencies to control the degree to which dependencies affect dependency complexity; For the The complexity of each control dependency (such as conditional statements, loop statements, etc.) in the key code snippet is calculated. ,The complexity of control dependencies is weighted and evaluated according to their nesting levels and the number of branches.
[0131] The key code snippet and its context are converted into vector representations, and the cosine similarity between them is calculated as the semantic similarity .
[0132] Calculate key code snippets The mean structural similarity with other key code snippets ; Use n-gram model or other statistical models to calculate statistical similarity .
[0133] The calculation method of the mean structural similarity includes:
[0134] Traverse the abstract syntax tree and extract the subtree corresponding to each key code fragment according to the location information of the extracted key code fragment.
[0135] The tree editing operations are defined to include node renaming, node deletion and node insertion, and a cost value is assigned to each of node renaming, node deletion and node insertion; the cost value can be fixed or dynamically calculated based on factors such as node type and subtree size.
[0136] for The corresponding subtree and any subtree , the calculation will Convert to The minimum edit cost of .
[0137] The calculation method of the minimum editing cost includes:
[0138] Initialize a two-dimensional table with rows and columns corresponding to and The nodes in the table calculate the value of each cell in the two-dimensional table from bottom to top, indicating that The subtree is converted to The minimum editing cost of the subtree of ;
[0139] but ;in, is the number of all subtrees, and Respectively and The number of nodes.
[0140] Based on semantic similarity , structural similarity and statistical similarity , calculate the key code snippet The contextual relevance weight ;
[0141] ;in, is the first adjustment coefficient, which is used to control the influence of semantic similarity on the context relevance weight; is the second adjustment coefficient, which is used to control the influence of structural similarity and statistical similarity on the context relevance weight.
[0142] By adjusting the first adjustment coefficient and the second adjustment coefficient, the influence of semantic similarity, structural similarity and statistical similarity on the context relevance weight is adjusted, and the correlation between the code snippet and its context at the semantic, structural and statistical feature levels is taken into account. The degree of association between the code snippet and its context can be more comprehensively evaluated, thereby providing more accurate results for the calculation of the context relevance weight.
[0143] The methods for obtaining ordered code snippet sequences include:
[0144] The information entropy value and context relevance weight of each key code snippet are weighted and summed to obtain a comprehensive score for each key code snippet; all key code snippets are arranged in descending order according to the size of the comprehensive score to obtain an ordered code snippet sequence.
[0145] The object code file is obtained by:
[0146] Traverse the ordered code snippet sequence, map each key code snippet to an equivalent code snippet in the target language, and merge the mapped target code snippets according to the context information of the key code snippet in the source code file (such as variable scope, function call relationship, etc.) to obtain the target code file.
[0147] Specifically, for each key code snippet, it is mapped to an equivalent target language code snippet (equivalent code snippet) according to the syntax and API of the target language (for each medical device). It should be noted that this process needs to take into account the differences between languages, such as grammatical structure, keywords, data types, and built-in functions; for key code snippets that cannot be directly mapped, use equivalent alternative implementations, or insert necessary auxiliary code (such as type conversion, function packaging, etc.).
[0148] The specific methods of fusing the mapped target code fragments include:
[0149] According to the scope of variables, correctly declare and reference variables; according to the function call relationship, insert function declaration, parameter passing and return value processing code; according to the class inheritance relationship, generate class definition, method overriding and other codes; according to control flow structures such as conditional statements and loop statements, organize code snippets.
[0150] Furthermore, the reverse mapping method is to convert the target code file into machine code or intermediate code that is directly executed by the terminal medical device.
[0151] Different terminal medical devices can reverse map and execute the mapped target code files to achieve cross-platform code translation and operation. It should be noted that due to the large differences in the hardware and software environments of different devices, the reverse mapping and execution process may need to be optimized and adjusted in a targeted manner to ensure the efficient operation of the code in various heterogeneous environments.
[0152] This embodiment improves the quality and efficiency of code translation through in-depth lexical analysis and abstract syntax tree generation. Different terminal medical devices can efficiently execute the optimized target code after translation, thereby improving the performance and reliability of the medical information system. The introduced information entropy value and context relevance weight calculation mechanism generates higher quality and more efficient target code, which not only helps to improve the system's operating speed, but also ensures the semantic correctness of the code in various heterogeneous environments, thereby reducing potential errors and safety hazards, achieving flexible code conversion and optimization, and significantly reducing development and maintenance costs. The automation and intelligence of the code translation process greatly reduces the workload of manual intervention and coding, improves translation efficiency and accuracy, and effectively improves the response speed and user experience of the medical platform.
[0153] Example 2
[0154] See also Figure 2 As shown, the part not described in detail in this embodiment is described in Example 1, which provides a multi-terminal code mapping and translation system for an Internet medical platform, including:
[0155] The source code acquisition and analysis module is used to acquire the source code file to be translated of the medical platform. The source code file includes n code segments, performs lexical analysis on the source code file, and generates an abstract syntax tree;
[0156] The fragment extraction and analysis module is used to traverse the abstract syntax tree, extract key code fragments, and calculate the information entropy value and context relevance weight of each key code fragment;
[0157] A fragment sorting module is used to sort each key code fragment according to the corresponding information entropy value and context relevance weight to obtain an ordered code fragment sequence;
[0158] A code mapping and translation module is used to map and translate the ordered code snippet sequence to generate a target code file;
[0159] The distribution mapping module is used to distribute the target code file to different terminal medical devices, and the different terminal medical devices reversely map and run the running target code file; each module is connected by wired and / or wireless means to realize data transmission between modules.
[0160] Example 3
[0161] This embodiment discloses an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, the operation mode of the multi-terminal code mapping and translation method for an Internet medical platform provided above is implemented.
[0162] Since the electronic device introduced in this embodiment is an electronic device used to implement a multi-terminal code mapping and translation method for an Internet medical platform in the embodiment of this application, based on the multi-terminal code mapping and translation method for an Internet medical platform introduced in the embodiment of this application, a person skilled in the art can understand the specific implementation of the electronic device of this embodiment and its various variations, so how the electronic device implements the method in the embodiment of this application is not described in detail here. As long as a person skilled in the art implements an electronic device used in a multi-terminal code mapping and translation method for an Internet medical platform in the embodiment of this application, it belongs to the scope of protection of this application.
[0163] The above formulas are all dimensionless and numerical calculations. The formula is a formula for the most recent real situation obtained by collecting a large amount of data and performing software simulation. The preset parameters and thresholds in the formula are set by technicians in this field according to actual conditions.
[0164] The above is only a preferred embodiment of the present invention, and the protection scope of the present invention is not limited to the above embodiments. All technical solutions under the concept of the present invention belong to the protection scope of the present invention. It should be pointed out that for ordinary technical users in this technical field, some improvements and modifications without departing from the principle of the present invention should also be regarded as the protection scope of the present invention.
Claims
1. A multi-terminal code mapping and translation method for an Internet medical platform, characterized in that: include: S1. Obtain a source code file to be translated of a medical platform, the source code file includes n code segments, perform lexical analysis on the source code file, and generate an abstract syntax tree; S2, traverse the abstract syntax tree, extract key code snippets, and calculate the information entropy value and context relevance weight of each key code snippet; S3, sorting each key code snippet according to the corresponding information entropy value and context relevance weight to obtain an ordered code snippet sequence; S4, mapping and translating the ordered code fragment sequence to generate a target code file; S5. Distribute the target code file to different terminal medical devices, and the different terminal medical devices reversely map and run the target code file; The information entropy value and context relevance weight of each key code snippet are calculated as follows: Represent each key code snippet as a corresponding sequence of tokens, where each token is a keyword, identifier, or literal; Count each unique token In the key code snippet Frequency of occurrence ; Based on frequency Calculate the key code snippet Information entropy value ; ,in, for The complexity of the code snippet is for The data flow complexity of and is the information adjustment coefficient; ;in, for The cyclomatic complexity of for The branch complexity of for Length; , and is the weight adjustment parameter; Cyclomatic complexity refers to the sum of the number of nested loops in the key code snippet; branch complexity refers to the sum of the number of conditional branch statements in the code snippet; ;in, for The scope complexity of for The dependency complexity, for The number of variables in the code; scope complexity refers to the sum of the nesting levels of variable scopes in key code snippets; ;in, It is The weight coefficient of the variable, For the The dependency depth of each variable, Adjust parameters for dependencies; For the A control over the complexity of dependencies; The key code snippet and its context are converted into vector representations, and the cosine similarity between them is calculated as the semantic similarity ; Calculate key code snippets The mean structural similarity with other key code snippets ; Use the n-gram model to calculate statistical similarity ; Based on semantic similarity , mean structural similarity and statistical similarity , calculate the key code snippet The contextual relevance weight , ;in, is the first adjustment coefficient; is the second adjustment coefficient; The calculation method of the structural similarity mean includes: Traverse the abstract syntax tree and extract the subtree corresponding to each key code fragment according to the location information of the extracted key code fragment; Define tree editing operations including node renaming, node deletion and node insertion, and assign a cost value to each of node renaming, node deletion and node insertion; for The corresponding subtree and any subtree , the calculation will Convert to The minimum edit cost of ; The calculation method of the minimum editing cost includes: Initialize a two-dimensional table with rows and columns corresponding to and The nodes in the table calculate the value of each cell in the two-dimensional table from bottom to top, indicating that The subtree is converted to The minimum editing cost of the subtree of ; but ;in, is the number of all subtrees, and Respectively and The number of nodes; The method of obtaining the ordered code snippet sequence includes: The information entropy value and context relevance weight of each key code snippet are weighted and summed to obtain a comprehensive score value of each key code snippet; all key code snippets are arranged in descending order according to the size of the comprehensive score value to obtain an ordered code snippet sequence; The object code file is obtained by: Traversing the ordered code snippet sequence, mapping each key code snippet to an equivalent code snippet in the target language, and merging the mapped target code snippets according to the context information of the key code snippet in the source code file to obtain a target code file; The reverse mapping method is to convert the target code file into machine code or intermediate code that is directly executed by the terminal medical device.
2. According to claim 1, a multi-terminal code mapping and translation method for an Internet medical platform is characterized in that: The method of generating an abstract syntax tree includes: Convert the source code file into a character stream, extract lexical units from the character stream, and generate a lexical unit sequence; perform grammatical analysis on the lexical unit sequence, build a syntax tree, preprocess the syntax tree, and reorganize the hierarchical structure of the nodes in the syntax tree to obtain an abstract syntax tree.
3. A multi-terminal code mapping and translation method for an Internet medical platform according to claim 2, characterized in that: The method of generating a lexical unit sequence includes: Initialize an empty sequence shell, read the characters in the character stream one by one, and use a pointer to record the current reading position in real time; Define the lexical unit type and build a corresponding prefix tree for each lexical unit type; starting from the current read position, try to match the prefix tree corresponding to each lexical unit type in turn; if the prefix tree successfully matches the current character, extract the corresponding lexical unit; Determine the type and value of the lexical unit according to the corresponding prefix tree, and record the position information of the lexical unit in the source code file. Based on the type, value and position information of the lexical unit, construct a lexical unit instance and add it to the sequence shell. Move the pointer to the end position of the lexical unit extracted this time, and repeat until the character stream is read; the final sequence shell is the lexical unit sequence.
4. According to claim 3, a multi-terminal code mapping and translation method for an Internet medical platform is characterized in that: The method of converting the source code file into a character stream includes: Initially define an initial memory buffer with a size of , use file I / O operation to open the source code file, obtain the file stream object, read the file stream object byte by byte, obtain m file blocks, store the m file blocks in the memory buffer in sequence, and dynamically adjust the size of the memory buffer to ; ;in, is the total size of m file blocks, is the size of the file block that has been read, is the total memory size, is the currently used memory, The upper limit of the preset memory buffer size. and is the regulating factor, and is the exponential factor; is the adjustment function, is the I / O throughput, is the CPU utilization, is the degree of memory fragmentation; Adjustment function ;in, is the throughput adjustment factor, is the utilization adjustment coefficient, It is the memory fragmentation adjustment factor; The file blocks in the memory buffer are preprocessed to obtain preprocessed file blocks, and the preprocessed file blocks are converted into character streams; that is, characters in the preprocessed file blocks are read one by one and form a character sequence, namely, a character stream.
5. A multi-terminal code mapping and translation method for an Internet medical platform according to claim 4, characterized in that: The method of preprocessing the file blocks in the memory buffer includes: Define a quintuple ,in, is the state set, To input the alphabet, is the state transfer function, is the initial state, and ; is a set of terminal states, and ; State transfer function ,in, is the current state, is the input character, For the new state; Based on m file blocks, define the state set and input alphabet ; Read characters one by one from the file block in the memory buffer , according to the current state and the characters read , the new state is obtained by calculating the state transfer function If the new state belong , then perform the corresponding preprocessing operations; update the current state to , repeat until all characters in the file block in the memory buffer are read; that is, the preprocessed file block is obtained.
6. A multi-terminal code mapping and translation method for an Internet medical platform according to claim 5, characterized in that: The method of performing grammatical analysis on the lexical unit sequence includes: Define grammar rules, that is, analyze the grammar of the programming language; based on the defined grammar rules, initialize a grammar tree, create a root node, extract lexical units from the lexical unit sequence, match them with the grammar rules, and create a new node as the left child of the root node; match the first lexical unit, make it the child of the newly created left child node, match the operator, and create a new node as the right child of the root node; continue matching according to the written production rule, create a new node as the right child node te of the right child node of the root node, match the second lexical unit, make it the right child node of the newly created te, match the operator, create a new node as the left child node tw of the right child node te; continue matching the third lexical unit according to the written production rule, create a new node as the right child node of tw, and repeat until the extraction of lexical units in the lexical unit sequence is completed; that is, the construction of the grammar tree is completed.
7. A multi-terminal code mapping and translation method for an Internet medical platform according to claim 6, characterized in that: The method of reorganizing the hierarchical structure of nodes in the syntax tree includes: The tree reconstruction rules are defined as a set of pattern matching rules, each of which consists of a matching pattern and a reconstruction action; There are m2 matching modes, which define the structure of the subtree that needs to be reconstructed; the reconstruction actions include node promotion, node merging, and node splitting; For each pattern matching rule Assign a priority weight ; For any two pattern matching rules and , which match the syntax tree Subtree in and ; If the matching patterns they match have a nested relationship, calculate the nested value between them ; like , then reconstruct first ;like , then reconstruct first ;like , then compare and Their respective weights, the one with higher weight will be reconstructed first; ;in, , and is the adjustment coefficient, for and The nearest common ancestor node, for The root node of for and The size difference, for and the degree of overlap; For syntax tree middle The depth of For syntax tree middle Depth The reconstruction process includes: Construct a priority queue Q. Initially, put all pattern matching rules into the priority queue Q in descending order of priority. When traversing to a node n', take out the pattern matching rule corresponding to the highest priority from Q. , match the matching pattern in the subtree with n' as the root. If the match is successful, perform the reconstruction action to obtain the reconstructed subtree, and adjust other pattern matching rules in Q according to the reconstruction action; If the match fails, continue to match the pattern matching rule corresponding to the next priority until all pattern matching rules are traversed and all reconstructed subtrees replace the original syntax tree, thus completing the generation of the abstract syntax tree.
8. A multi-terminal code mapping and translation system for an Internet medical platform, which is used to implement a multi-terminal code mapping and translation method for an Internet medical platform as described in any one of claims 1 to 7, characterized in that: include: The source code acquisition and analysis module is used to acquire the source code file to be translated of the medical platform. The source code file includes n code segments, performs lexical analysis on the source code file, and generates an abstract syntax tree; The fragment extraction and analysis module is used to traverse the abstract syntax tree, extract key code fragments, and calculate the information entropy value and context relevance weight of each key code fragment; A fragment sorting module is used to sort each key code fragment according to the corresponding information entropy value and context relevance weight to obtain an ordered code fragment sequence; A code mapping and translation module is used to map and translate the ordered code snippet sequence to generate a target code file; The distribution mapping module is used to distribute the target code file to different terminal medical devices, and the different terminal medical devices reversely map and run the target code file.