Method for determining code prompt information, method for determining data set, and electronic device
By obtaining the SQL statements to be completed and the preset feature data set, determining the current node and its features, and generating a completion prompt item, the problem of low SQL programming efficiency is solved, and more accurate and efficient code completion is achieved.
Patent Information
- Application Number
- CN202210314942.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-03-28
- Publication Date
- 2025-03-11
- Estimated Expiration
- 2042-03-28
AI Technical Summary
When programming in SQL language, users need to enter code verbatim, resulting in low programming efficiency.
By obtaining the SQL statement to be completed and the preset feature data set, determine the current node to be edited and its node characteristics, and generate a completion prompt item based on the node characteristics and preset features to display the node type and node values.
Improves the programming efficiency of SQL statements, and reduces the number of user inputs and error rates through accurate completion prompts.
Smart Images

Figure CN114676155B_ABST
Abstract
Description
Technical Field
[0001] The present disclosure relates to database technology, and in particular to a method for determining code prompt information, a method for determining a data set, and an electronic device. Background Art
[0002] SQL (Structured Query Language) is a language used for database query and programming. It can access data as well as query, update and manage relational database systems.
[0003] When programming using the SQL language, users are usually required to enter codes word by word in the programming software, so the programming efficiency is low. Summary of the invention
[0004] The present disclosure provides a method for determining code prompt information, a method for determining a data set, and an electronic device to prompt the programming efficiency of SQL language.
[0005] A first aspect of the present disclosure is to provide a method for determining code prompt information, comprising:
[0006] Acquire the SQL statement to be completed and a preset feature data set; the feature data set includes a completion prompt item and a preset feature corresponding to the completion prompt item, and the completion prompt item includes a node type and a node value;
[0007] Determining a current node to be edited in the SQL statement, and determining a node feature of the current node according to the SQL statement;
[0008] According to the node feature and the preset feature, a completion prompt item for completing the current node is determined, and the node type and node value included in the completion prompt item are displayed.
[0009] A second aspect of the present disclosure is to provide a method for determining a feature data set, comprising:
[0010] Get the document including SQL statements;
[0011] Determine a plurality of nodes in the SQL statement, and determine node features of the nodes according to the SQL statement;
[0012] A completion prompt item is determined according to the node, and the feature data set is generated according to the completion prompt item and the node feature of the node; wherein the feature data set includes the completion prompt item and the node feature corresponding to the completion prompt item.
[0013] A third aspect of the present disclosure is to provide a device for determining code prompt information, comprising:
[0014] An acquisition unit, used to acquire the SQL statement to be completed and a preset feature data set; the feature data set includes a completion prompt item and a preset feature corresponding to the completion prompt item, and the completion prompt item includes a node type and a node value;
[0015] A determination unit, configured to determine a current node to be edited in the SQL statement, and determine a node feature of the current node according to the SQL statement;
[0016] A prompt unit is used to determine a completion prompt item for completing the current node according to the node feature and the preset feature, and display the node type and node value included in the completion prompt item.
[0017] A fourth aspect of the present disclosure is to provide a device for determining a feature data set, comprising:
[0018] A document acquisition unit, used for acquiring a document including an SQL statement;
[0019] A feature extraction unit, used to determine a plurality of nodes in the SQL statement, and determine node features of the nodes according to the SQL statement;
[0020] A set generation unit is used to determine a completion prompt item according to the node, and generate the feature data set according to the completion prompt item and the node feature of the node; wherein the feature data set includes the completion prompt item and the node feature corresponding to the completion prompt item.
[0021] A fourth aspect of the present disclosure is to provide an electronic device, comprising:
[0022] Memory;
[0023] Processor; and
[0024] Computer programs;
[0025] The computer program is stored in the memory and is configured to be executed by the processor to implement the method for determining the code prompt information as described in the first aspect or the method for determining the feature data set as described in the second aspect.
[0026] Another aspect of the present disclosure is to provide a computer-readable storage medium having a computer program stored thereon, wherein the computer program is executed by a processor to implement the method for determining the code prompt information as described in the first aspect or the method for determining the feature data set as described in the second aspect.
[0027] Another aspect of the present disclosure is to provide a computer program product, including a computer program, which, when executed by a processor, implements the method for determining the code prompt information as described in the first aspect or the method for determining the feature data set as described in the second aspect.
[0028] The method for determining code prompt information, the method for determining a data set, and the electronic device provided by the present disclosure include: obtaining a SQL statement to be completed and a preset feature data set; the feature data set includes a completion prompt item and a preset feature corresponding to the completion prompt item, and the completion prompt item includes a node type and a node value; determining a current node to be edited in the SQL statement, and determining the node feature of the current node according to the SQL statement; determining a completion prompt item for completing the current node according to the node feature and the preset feature, and displaying the node type and the node value included in the completion prompt item. The method for determining code prompt information, the method for determining a data set, and the electronic device provided by the present disclosure can determine and display the prompt item to be completed of the SQL statement in combination with the preset feature data set and the content of the SQL statement to be completed, so that a relatively accurate prompt item to be completed can be determined to improve the programming efficiency of the user. BRIEF DESCRIPTION OF THE DRAWINGS
[0029] Figure 1 This is a flow chart of a method for determining code prompt information shown in an exemplary embodiment of the present disclosure;
[0030] Figure 2 This is a schematic diagram of an interface showing an exemplary embodiment of the present disclosure;
[0031] Figure 3 A flowchart of a method for determining code prompt information shown in another exemplary embodiment of the present disclosure;
[0032] Figure 4 A flowchart of a method for determining a feature data set is shown as an exemplary embodiment of the present disclosure;
[0033] Figure 5 A flowchart of a method for determining a feature data set is shown as another exemplary embodiment of the present disclosure;
[0034] Figure 6 A schematic diagram of the structure of an abstract syntax tree is shown as an exemplary embodiment;
[0035] Figure 7 This is a structural diagram of a device for determining code prompt information shown in an exemplary embodiment of the present disclosure;
[0036] Figure 8 A structural diagram of a device for determining code prompt information shown in another exemplary embodiment of the present disclosure;
[0037] Fig. 9A structural diagram of a device for determining a feature data set shown as an exemplary embodiment of the present disclosure;
[0038] Fig.10 A structural diagram of a device for determining a feature data set shown in another exemplary embodiment of the present disclosure;
[0039] Fig.11 The present invention is a structural diagram of an electronic device according to an exemplary embodiment of the present invention. DETAILED DESCRIPTION
[0040] SQL (Structured Query Language) is a language used for database query and programming. It can access data as well as query, update and manage relational database systems.
[0041] In many application scenarios, SQL language is required for programming, especially when database management is required. SQL language is a frequently used programming language. When programming, users need to enter the code content word by word. In order to improve programming efficiency, the context of the code and SQL syntax rules can be combined to predict the code content that the user needs next, and display these contents to achieve automatic code completion.
[0042] However, the context of the code language is highly logical, and only the context of the code and the SQL syntax rules cannot accurately predict the code content that the user needs to enter. In order to solve this technical problem, the method provided by the present disclosure uses a large number of existing SQL codes to extract a feature data set. The data included in the feature data set is extracted based on real SQL codes and can reflect the context logic between SQL codes. Therefore, the code content that the user needs to enter is predicted based on the feature data set to improve the accuracy of code completion.
[0043] Figure 1 The present invention is a flowchart of a method for determining code prompt information according to an exemplary embodiment of the present invention.
[0044] like Figure 1 As shown, the method for determining the code prompt information provided in this embodiment includes:
[0045] Step 101, obtaining a SQL statement to be completed and a preset feature data set; the feature data set includes a completion prompt item and preset features corresponding to the completion prompt item, and the completion prompt item includes a node type and a node value.
[0046] The method provided in the present disclosure may be executed by an electronic device with computing capabilities, such as a server or a user terminal.
[0047] Specifically, the user can write SQL code in the user terminal, and the user terminal can determine the code prompt information based on the method provided by the present disclosure, or the user can upload the SQL code being written by the user to the server, and the server determines the code prompt information based on the method provided by the present disclosure.
[0048] Furthermore, the electronic device may obtain the SQL statement to be completed and a preset feature data set.
[0049] Among them, the SQL statement refers to a statement in the SQL code file, for example, the content between two semicolons in the SQL file is an SQL statement. The SQL statement to be completed refers to an SQL statement that has not been completed. For example, when the user enters a semicolon, it can be considered that the SQL statement is completed. If the user is entering characters, it can be considered that the user is writing an SQL statement, which is the SQL statement to be completed. Based on the solution provided by the present disclosure, it is possible to predict the content that the user wants to enter at the end of the SQL statement to be completed, and then display these contents for the user to select.
[0050] Specifically, the preset feature data set can be obtained by processing existing complete SQL statements. For example, a large number of SQL code files can be prepared in advance, and these files can be written by different people. The features of each SQL statement included in these SQL code files can be extracted to obtain a feature data set. For each SQL statement, several features can be extracted and then put into the feature data set.
[0051] Furthermore, an SQL statement includes multiple nodes, and an abstract syntax tree can be constructed based on the SQL statement to determine each node in the SQL statement. The features of each node can be extracted in advance, and then the node can be stored in the feature data set as a completion prompt item, and the node features can be used as preset features of the completion prompt item.
[0052] In actual application, the content of a node includes the node type and the node value. Correspondingly, the completion prompt item corresponding to the node also has the corresponding node type and node value. For example, the node type may be a keyword, function, variable, string, number, etc., and the node value is the value corresponding to the node type. For example, when the node type is a variable, the node value can be a specific variable value.
[0053] Step 102, determining a current node to be edited in the SQL statement, and determining a node feature of the current node according to the SQL statement.
[0054] Among them, for the SQL statement to be completed, the electronic device can determine the current node to be edited. The current node refers to a node that has not been edited. It can be a node that has been partially edited or a node that has not been edited at all. For example, it can be the node corresponding to the position where the user is entering characters, or it can be the node corresponding to the position after the user has completed entering the characters.
[0055] In an optional implementation, an abstract syntax tree can be constructed according to the SQL statement, and then the current node to be edited can be determined in the abstract syntax tree. Specifically, a leaf node corresponding to the content being edited or to be edited can be determined in the abstract syntax tree, and the leaf node can be used as the current node.
[0056] For example, when inputting an SQL statement, the character that the user wants to input is "ABC", then when the user inputs "A", the node is the current node to be edited. For another example, after inputting "ABC", the user also wants to input other characters, then the next position of "ABC" is the current node to be edited.
[0057] Specifically, the characters included in a node may be the smallest component unit in the SQL language, for example, lingdao_test_table.
[0058] Furthermore, the electronic device can determine the node characteristics of the current node to be edited in combination with the SQL statement to be completed. Specifically, the node characteristics of the current node can be determined according to the position of the current node in the SQL statement and the existing content in the SQL statement to be completed.
[0059] In actual application, the node before the current node can be determined according to the character sequence in the SQL statement to be completed, so as to determine the characteristics of the current node based on the previous node. For example, if the content before the current node in the SQL statement to be completed is "ABC", the characteristics of the current node can be determined based on "A BC".
[0060] For another example, an abstract syntax tree may be constructed according to the SQL statement to be completed, and then the feature of the current node may be determined according to the parent node of the current node in the abstract syntax tree.
[0061] Step 103: Determine a completion prompt item for completing the current node according to the node characteristics and the preset characteristics, and display the node type and node value included in the completion prompt item.
[0062] Among them, the method provided by the present invention not only determines the completion prompt items of the SQL statement based on the SQL statement itself, but also determines the completion prompt items of the SQL statement based on a preset feature data set. The preset feature data set is extracted from the existing complete SQL statement. Therefore, the existing complete SQL statement can be used to determine the current completion prompt item to improve the accuracy of the determined completion prompt item.
[0063] Specifically, the preset feature data set includes a completion prompt item and a preset feature corresponding to the completion prompt item. The node feature of the current node can be compared with each preset feature in the preset feature data set to determine K preset features that are similar to the node feature. K is a positive integer, such as 5, 10, etc.
[0064] Furthermore, the completion prompt item corresponding to the preset feature can be determined as the completion prompt item of the current node. For example, based on the node feature of the current node, five similar preset features 1, feature 2, feature 3, feature 4, and feature 5 are determined in the preset feature data set. In the preset feature data set, prompt item 1 corresponds to preset feature 1, prompt item 2 corresponds to preset feature 2, prompt item 3 corresponds to preset feature 3, prompt item 4 corresponds to preset feature 4, and prompt item 5 corresponds to preset feature 5. Then prompt item 1, prompt item 2, prompt item 3, prompt item 4, and prompt item 5 can be determined as the completion prompt item of the current node.
[0065] In actual application, the electronic device can also display the completion prompt item of the current node in the code editing interface, and specifically can display the node type and node value included in the completion prompt item. For example, if the node type of the completion prompt item is table and the value is table, then "table" or "table" can be displayed.
[0066] In an optional implementation, the node type may be displayed as a corresponding icon.
[0067] Figure 2 This is a schematic diagram of an interface showing an exemplary embodiment of the present disclosure.
[0068] like Figure 2 As shown, the user can enter the SQL code in the interface, and a prompt box 21 can be displayed at the location of the node to be edited, and the completion prompt item determined by the electronic device can be displayed in the prompt box 21. Specifically, an icon 211 corresponding to the node type can be displayed, and the value 212 of the node can also be displayed.
[0069] Optionally, the user can click on the value of any node, and the electronic device can display the value at the location of the current node, thereby improving the user's programming speed.
[0070] The method for determining code prompt information provided by the present disclosure includes: obtaining a SQL statement to be completed and a preset feature data set; the feature data set includes a completion prompt item and a preset feature corresponding to the completion prompt item, and the completion prompt item includes a node type and a node value; determining a current node to be edited in the SQL statement, and determining the node feature of the current node according to the SQL statement; determining a completion prompt item for completing the current node according to the node feature and the preset feature, and displaying the node type and the node value included in the completion prompt item. The method provided by the present disclosure can determine and display the prompt item to be completed of the SQL statement in combination with the preset feature data set and the content of the SQL statement to be completed, so that a relatively accurate prompt item to be completed can be determined to improve the programming efficiency of the user.
[0071] Figure 3 The present invention is a flowchart of a method for determining code prompt information shown in another exemplary embodiment of the present invention.
[0072] like Figure 3 As shown, the method for determining code prompt information provided by the present disclosure includes:
[0073] Step 301, obtaining a SQL statement to be completed and a preset feature data set; the feature data set includes a completion prompt item and preset features corresponding to the completion prompt item, and the completion prompt item includes a node type and a node value.
[0074] The implementation of step 301 is similar to that of step 101 and will not be described in detail.
[0075] Step 302: Generate an abstract syntax tree corresponding to the SQL statement.
[0076] AST (Abstract Syntax Tree) is an abstract representation of the syntax structure of the source code. It represents the syntax structure of the programming language in a tree form, and each node on the tree represents a structure in the source code. The abstract syntax tree can be used to determine the relationship between the nodes in the SQL statement, so that more comprehensive and accurate node features can be extracted using the abstract syntax tree.
[0077] The method of generating the abstract syntax tree may adopt the existing solution in the prior art.
[0078] Step 303: determine the current node to be edited in the SQL statement.
[0079] Step 303 is similar to the method of determining the current node in step 102, and will not be described in detail.
[0080] Step 304: Determine the node feature of the current node according to the abstract syntax tree of the SQL statement.
[0081] Specifically, the abstract syntax tree includes multiple nodes, including the current node. Since the current node refers to a node that has not been edited, the content of the current node in the abstract syntax tree can be empty or partially edited.
[0082] Furthermore, each node in the abstract syntax tree has a parent-child relationship, and the feature of the current node can be extracted based on the parent node of the current node, and the feature of the current node can also be extracted based on the parent node of the parent node.
[0083] In actual application, the electronic device can determine the first information of the parent node of the current node based on the abstract syntax tree of the SQL statement; and / or determine the second information of the parallel node parallel to the parent node based on the abstract syntax tree of the SQL statement; and / or determine the third information of the root node of the abstract syntax tree of the SQL statement.
[0084] The node characteristics of the current node include at least one of the following:
[0085] First information, second information, third information.
[0086] Specifically, the abstract syntax tree can be used to determine the parent node of the current node, and the parent node of the parent node. In the solution provided by the present disclosure, the parent node in the abstract syntax tree can be used to infer the child node. When the child node is the current node, the parent node of the current node can be used to predict the content of the current node.
[0087] In an optional implementation, the electronic device may determine the first information of the parent node of the current node according to the abstract syntax tree of the SQL statement, so that the content of the current node can be predicted using the information of the parent node.
[0088] The first information may include at least one of the following: the type of the parent node of the current node; the ranking of the current node in the parent node; and the ranking of the parent node in its parent node.
[0089] For example, there is a current node Token i, which has a parent node Token j. The type of Token j can be used as the first information of Token j, and the order of Token i in Token j can also be used as the first information of Token j. If the parent node Token j also has a parent node Token k, the order of Token j in Token k can also be determined as the first information of Token j.
[0090] In an optional implementation, the electronic device may also determine the second information of the parallel node parallel to the parent node according to the abstract syntax tree of the SQL statement, so that the content of the current node can be predicted using the information of the parallel node parallel to the parent node.
[0091] The second information includes at least one of the following: the type of the left node in parallel with the parent node; the value of the left node in parallel with the parent node; the type of the right node in parallel with the parent node; the value of the right node in parallel with the parent node.
[0092] The abstract syntax tree may include parallel nodes, and the child nodes belonging to the same parent node are parallel nodes. For example, if node A has two child nodes A1 and A2, then A1 and A2 are parallel nodes. By extracting the information of parallel nodes, the content of the current node can be predicted using the information of the nodes that are parallel to the parent node of the current node.
[0093] For example, there is a current node Token i, which has a parent node Token j, and the parent node Token j has a parallel left node Token left and Token right. Then, the information of Token left and Token right can be determined respectively and used as the second information of the parallel node parallel to the parent node.
[0094] In an optional implementation, the electronic device may also determine third information of a root node of an abstract syntax tree of the SQL statement.
[0095] In actual application, the abstract syntax tree includes multiple nodes, and an abstract syntax tree has a root node. For example, the parent nodes of the nodes can be traversed one by one in the abstract syntax tree, and finally the root node without a parent node is determined.
[0096] The third information includes the type of the root node and / or the value of the root node. By extracting the information of the root node, the content of the current node can be predicted using the information of the root node of the current node.
[0097] Specifically, the solution provided by the present disclosure can obtain the first information, the second information, and the third information, thereby using the information of each node that is closely associated with the current node to accurately determine the node characteristics of the current node.
[0098] Step 305, determining the node type of the previous node of the current node and the value of the previous node of the current node according to the SQL statement; wherein the node characteristics of the current node include the node type of the previous node and the value of the previous node.
[0099] In actual application, the SQL statement includes multiple nodes, and each node has a contextual relationship. For example, in the SQL statement "select * from table t where t.p_code = 'A'", multiple strings are included, and each string has a contextual relationship. Therefore, the node characteristics of the current node can also be determined based on the content of other nodes before the current node.
[0100] The node features extracted in this way may include the node type of the previous node and the value of the previous node. For example, the type of the previous node of the current node may be a table, and the value may be a table.
[0101] It should be noted that the parent node of the current node is determined based on the abstract syntax tree, and the previous node of the current node is determined according to the sequence of strings in the SQL statement to be completed. The previous node and parent node of the same current node are not necessarily the same.
[0102] Step 304 and step 305 may be executed simultaneously, and there is no restriction on the execution order of the two.
[0103] Step 306: determine K preset features similar to the node feature in the feature data set.
[0104] Furthermore, the feature data set includes completion prompt items and preset features thereof. The electronic device can compare the node feature of the current node with the preset features in the feature data set, and determine K preset features that are closest to the node feature.
[0105] In practical applications, the similarity between the node feature and each preset feature can be calculated, so as to select the K preset features with the highest similarity.
[0106] For example, the node feature of the current node extracted may be an N-dimensional vector, and correspondingly, the preset feature in the feature data set is also an N-dimensional vector. The similarity between the node feature and each preset feature may be determined based on the KNN (K-NearestNeighbor) algorithm, and then K preset features similar to the node feature may be screened out.
[0107] Step 307: determine the completion prompt items corresponding to the K preset features as the completion prompt items for completing the current node, and display the node type and node value included in the completion prompt item of the current node.
[0108] Among them, the completion prompt items in the feature data set have a corresponding relationship with the preset features. After screening out K preset features, the electronic device can determine the completion prompt items corresponding to these preset features as the completion prompt items of the current node.
[0109] Specifically, the filtered preset features are relatively close to the node features. Therefore, it can be considered that the content of the completion prompt item corresponding to the preset features is also relatively close to the content of the current node that the user wants to input. Therefore, the completion prompt item corresponding to the filtered preset features can be used as the completion prompt item of the current node.
[0110] Furthermore, the node type and node value included in the completion prompt item of the current node can be displayed to facilitate the user to select any completion prompt item, so that the electronic device can display the value included in the completion prompt item in the interface to improve the user's programming efficiency.
[0111] Figure 4 The present invention is a flowchart of a method for determining a feature data set according to an exemplary embodiment of the present invention.
[0112] like Figure 4 As shown, the method for determining a feature data set provided by the present disclosure includes:
[0113] Step 401, obtaining a document including SQL statements.
[0114] Existing SQL files can be integrated to obtain documents including a large number of SQL statements, and then the documents including a large number of SQL statements are processed to extract the features of each SQL statement, thereby obtaining a feature data set.
[0115] Among them, these SQL files can be written by different people. For each SQL statement, several features can be extracted and then put into the feature data set.
[0116] Step 402, determining a plurality of nodes in the SQL statement, and determining node features of the nodes according to the SQL statement.
[0117] The SQL statements in the document are complete statements, and each SQL statement includes multiple nodes.
[0118] For example, an abstract syntax tree can be constructed based on the SQL statement to determine each node in the SQL statement. The features of each node can be extracted based on the SQL statement, and specifically, the features of each leaf node in the SQL statement can be extracted.
[0119] For example, the node feature of a node may be determined based on other nodes before the node. For another example, the node feature of the node may be determined based on the parent node of the node in the abstract syntax tree.
[0120] Step 403, determining a completion prompt item according to the node, and generating a feature data set according to the completion prompt item and the node features of the node; wherein the feature data set includes the completion prompt item and the node features corresponding to the completion prompt item.
[0121] In actual application, the content of the node can be used as a completion prompt item, and correspondingly, the node feature of the node can be used as a feature corresponding to the completion prompt item.
[0122] The content of a node includes the node type and the node value. Correspondingly, the completion prompt item corresponding to the node also has the corresponding node type and node value. For example, the node type may be a keyword, function, variable, string, number, etc. The node value is the value corresponding to the node type. For example, when the node type is a variable, the node value can be a specific variable value.
[0123] A node has a node feature, and accordingly, a completion prompt item may also have the node feature. Therefore, in this way, a feature data set including the completion prompt item and its features can be constructed.
[0124] In an optional implementation, the feature data set determined by the present disclosure can be applied to Figure 1-3 In the solution shown, completion prompt information is provided when the user is programming based on the SQL language, so as to improve the user's programming efficiency.
[0125] Figure 5 The present invention is a flowchart of a method for determining a feature data set according to another exemplary embodiment of the present invention.
[0126] like Figure 5 As shown, the method for determining a feature data set provided by the present disclosure includes:
[0127] Step 501: Obtain a document including SQL statements.
[0128] The implementation of step 501 is similar to that of step 401 and will not be described in detail.
[0129] Step 502: Generate an abstract syntax tree corresponding to the SQL statement.
[0130] AST (Abstract Syntax Tree) is an abstract representation of the syntax structure of the source code. It represents the syntax structure of the programming language in a tree form, and each node on the tree represents a structure in the source code. The abstract syntax tree can be used to determine the relationship between the nodes in the SQL statement, so that more comprehensive and accurate node features can be extracted using the abstract syntax tree.
[0131] The method of generating the abstract syntax tree may adopt the existing solution in the prior art.
[0132] Step 503: determine a plurality of leaf nodes in the abstract syntax tree of the SQL statement.
[0133] AST includes multiple nodes, including leaf nodes. Leaf nodes can represent specific variables operated in SQL statements, so the node characteristics of leaf nodes in the abstract syntax tree can be determined.
[0134] A leaf node refers to a node at the end of each fork in the abstract syntax tree. Each node in the abstract syntax tree has a parent-child relationship, but a leaf node does not have a child node.
[0135] Figure 6 The figure is a schematic diagram of the structure of an abstract syntax tree according to an exemplary embodiment.
[0136] like Figure 6 As shown, the abstract syntax tree includes multiple branches, and the node at the end of each branch is a leaf node, for example, nodes 61, 62, and 63 are leaf nodes.
[0137] The leaf nodes in the abstract syntax tree can be traversed one by one to extract the node features of each leaf node. For example, a node can be randomly obtained in the AST, and the child nodes of the node can be determined, and the child nodes can be determined again until a leaf node with no child nodes is determined.
[0138] For each leaf node in the AST, the corresponding node features can be determined.
[0139] Step 504: determine the node features of the leaf nodes according to the abstract syntax tree of the SQL statement.
[0140] Furthermore, each node in the abstract syntax tree has a parent-child relationship, and the features of the leaf node can be extracted based on the parent node of the leaf node, and the features of the leaf node can also be extracted based on the parent node of the parent node.
[0141] Optionally, first information of the parent node of the leaf node can be determined based on the abstract syntax tree of the SQL statement; and / or second information of the parallel node parallel to the parent node can be determined based on the abstract syntax tree of the SQL statement; and / or third information of the root node of the abstract syntax tree of the SQL statement can be determined.
[0142] The node characteristics of the leaf node include any of the following:
[0143] First information, second information, third information.
[0144] Specifically, the abstract syntax tree can be used to determine the parent node of a leaf node, and the parent node of the parent node. In the solution provided by the present disclosure, the parent node of a leaf node in the abstract syntax tree can be used to determine the node characteristics of the leaf node.
[0145] In an optional implementation, the electronic device may determine the first information of the parent node of a leaf node according to the abstract syntax tree of the SQL statement, so that the characteristics of the leaf node may be determined by using the content of the parent node.
[0146] Optionally, the first information includes at least one of the following: the type of the parent node of the leaf node; the order of the leaf node in the parent node; and the order of the parent node in its parent node.
[0147] For example, there is a leaf node Token i in the abstract syntax tree, which has a parent node Token j. The type of Token j can be used as the first information of Token j, and the order of Token i in Token j can also be used as the first information of Token j. If the parent node Token j also has a parent node Token k, the order of Token j in Token k can also be determined as the first information of Token j.
[0148] Optionally, the electronic device may also determine the second information of the parallel node parallel to the parent node of the leaf node according to the abstract syntax tree of the SQL statement, so that the characteristics of the leaf node can be determined by using the parallel node parallel to the parent node.
[0149] The second information includes at least one of the following: the type of the left node in parallel with the parent node; the value of the left node in parallel with the parent node; the type of the right node in parallel with the parent node; the value of the right node in parallel with the parent node.
[0150] The abstract syntax tree may include parallel nodes, and the child nodes belonging to the same parent node are parallel nodes. For example, if node A has two child nodes A1 and A2, then A1 and A2 are parallel nodes. The node characteristics of the leaf node can be determined by the nodes that are parallel to the parent node of the leaf node.
[0151] For example, there is a node Token i in the abstract syntax tree, which has a parent node Token j. The parent node Token j has a parallel left node Token left and Token right. Then, the information of Token left and Token right can be determined respectively and used as the second information of the parallel node parallel to the parent node.
[0152] Optionally, third information of the root node of the abstract syntax tree of the SQL statement may also be determined.
[0153] In actual application, the abstract syntax tree includes multiple nodes, and an abstract syntax tree has a root node. For example, the parent nodes of the nodes can be traversed one by one in the abstract syntax tree, and finally the root node without a parent node is determined.
[0154] The third information includes the type of the root node and / or the value of the root node. The characteristics of the leaf node can be determined through the root node of the leaf node.
[0155] Specifically, the solution provided by the present disclosure can obtain the first information, the second information, and the third information, so as to determine the node characteristics of the leaf nodes in the abstract syntax tree by using the nodes that are closely associated with the leaf nodes.
[0156] Step 505, according to the character sequence in the SQL statement, determine the node type of the previous node of the leaf node and the value of the previous leaf node of the leaf node; wherein the node characteristics of the leaf node include the node type of the previous leaf node and the value of the previous leaf node.
[0157] In another implementation, the node characteristics of the leaf node may also be determined based on the character string included in the SQL statement.
[0158] The SQL statement includes multiple nodes, and each node has a front-to-back position relationship. For example, in the SQL statement "select * from table t where t.p_code = 'A'", multiple strings are included, and each string has a front-to-back relationship. Therefore, according to the position of the leaf node in the SQL statement, the content of other leaf nodes before the leaf node can be determined, and the node characteristics of the leaf node can be determined.
[0159] In an optional implementation, the leaf node can be determined in the AST, and the leaf node corresponding to the character content before the leaf node in the AST can be determined according to the character order in the SQL statement, thereby obtaining another leaf node before a leaf node.
[0160] The node features extracted in this way may include the node type of the previous leaf node and the value of the previous leaf node. For example, the type of the previous leaf node of a leaf node may be a table, and the value may be table.
[0161] It should be noted that the parent node of a leaf node is determined based on the parent-child relationship between nodes in the abstract syntax tree, and the previous node of a leaf node is determined based on the order of characters in the SQL statement. The previous node of the same node may not be the same as the parent node.
[0162] Step 504 and step 505 may be executed simultaneously, and there is no restriction on the execution order of the two.
[0163] Step 506: determine the type and value of the node as a completion prompt item.
[0164] Step 507: Generate a feature data set according to the completion prompt item and the node features of the node; wherein the feature data set includes the completion prompt item and the node features of the completion prompt item.
[0165] After extracting the features of the node, the type and value of the node can be determined as a completion prompt item, and the node features of the node can be used as preset features corresponding to the completion prompt item. The completion prompt item and its preset features can also be stored in a feature data set.
[0166] Through this implementation, a feature data set including the completion prompt item and the node features of the completion prompt item can be obtained.
[0167] Figure 7 The present invention is a structural diagram of a device for determining code prompt information according to an exemplary embodiment of the present invention.
[0168] like Figure 7 As shown, the device 700 for determining code prompt information provided in this embodiment includes:
[0169] The acquisition unit 710 is used to acquire the SQL statement to be completed and a preset feature data set; the feature data set includes a completion prompt item and a preset feature corresponding to the completion prompt item, and the completion prompt item includes a node type and a node value;
[0170] A determination unit 720, configured to determine a current node to be edited in the SQL statement, and determine a node feature of the current node according to the SQL statement;
[0171] The prompt unit 730 is used to determine a completion prompt item for completing the current node according to the node feature and the preset feature, and display the node type and node value included in the completion prompt item.
[0172] The device for determining code prompt information provided by the present disclosure can determine and display the prompt items to be completed of the SQL statement in combination with a preset feature data set and the content of the SQL statement to be completed, thereby being able to determine more accurate prompt items to be completed to improve the user's programming efficiency.
[0173] Figure 8 This is a structural diagram of a device for determining code prompt information shown in another exemplary embodiment of the present disclosure.
[0174] like Figure 8 As shown, the device 800 for determining code hint information provided in this embodiment further includes a tree generation unit 740, which is used to generate an abstract syntax tree corresponding to the SQL statement;
[0175] The determining unit 720 includes:
[0176] The first determination module 721 is used to determine the node feature of the current node according to the abstract syntax tree of the SQL statement.
[0177] Optionally, the determining unit 720 includes:
[0178] The second determination module 722 is used to determine the node type of the previous node of the current node and the value of the previous node of the current node according to the SQL statement; wherein the node characteristics of the current node include the node type of the previous node and the value of the previous node.
[0179] Optionally, the first determining module 721 is specifically configured to:
[0180] Determine first information of a parent node of the current node according to the abstract syntax tree of the SQL statement;
[0181] and / or, determining, according to the abstract syntax tree of the SQL statement, second information of a parallel node that is parallel to the parent node;
[0182] and / or, determining third information of a root node of the abstract syntax tree of the SQL statement;
[0183] The node feature of the current node includes at least one of the following:
[0184] First information, second information, third information.
[0185] Optionally, the first information includes at least one of the following:
[0186] The type of the parent node of the current node;
[0187] The order of the current node in the parent node;
[0188] The order of the parent node in its parent node;
[0189] The second information includes at least one of the following:
[0190] the type of the left node that is parallel to the parent node;
[0191] the value of the left node that is parallel to the parent node;
[0192] the type of the right node that is parallel to the parent node;
[0193] the value of the right node that is parallel to the parent node;
[0194] The third information includes the type of the root node and / or the value of the root node.
[0195] Optionally, the prompt unit 730 includes:
[0196] A screening module 731 is used to determine K preset features similar to the node feature in the feature data set;
[0197] The prompt module 732 is used to determine the completion prompt items corresponding to the K preset features as the completion prompt items for completing the current node.
[0198] Fig. 9 The present invention is a structural diagram of a device for determining a feature data set according to an exemplary embodiment of the present invention.
[0199] like Fig. 9 As shown, the device 900 for determining code prompt information provided in this embodiment includes:
[0200] A document acquisition unit 910, configured to acquire a document including an SQL statement;
[0201] A feature extraction unit 920, configured to determine a plurality of nodes in the SQL statement, and determine node features of the nodes according to the SQL statement;
[0202] The set generation unit 930 is used to determine a completion prompt item according to the node, and generate the feature data set according to the completion prompt item and the node feature of the node; wherein the feature data set includes the completion prompt item and the node feature corresponding to the completion prompt item.
[0203] Fig.10 This is a structural diagram of a device for determining a feature data set according to another exemplary embodiment of the present disclosure.
[0204] like Fig.10 As shown, in the device 1000 for determining code prompt information provided by this embodiment, the node is a leaf node;
[0205] The apparatus further includes a tree generation unit 940, configured to:
[0206] Generate an abstract syntax tree corresponding to the SQL statement;
[0207] The feature extraction unit 920 includes:
[0208] A node determination module 921, configured to determine a plurality of leaf nodes in the abstract syntax tree of the SQL statement;
[0209] The first feature extraction module 922 is used to determine the node feature of the leaf node according to the abstract syntax tree of the SQL statement.
[0210] Optionally, the node includes a leaf node in an abstract syntax tree corresponding to the SQL statement;
[0211] The feature extraction unit 920 includes a second feature extraction module 923:
[0212] According to the character sequence in the SQL statement, determine the node type of the previous leaf node of the leaf node and the value of the previous leaf node of the leaf node; wherein the node characteristics of the leaf node include the node type of the previous leaf node and the value of the previous leaf node.
[0213] The optional first feature extraction module 922 is specifically used for:
[0214] Determine first information of a parent node of the leaf node according to the abstract syntax tree of the SQL statement;
[0215] and / or, determining, according to the abstract syntax tree of the SQL statement, second information of a parallel node that is parallel to the parent node;
[0216] and / or, determining third information of a root node of the abstract syntax tree of the SQL statement;
[0217] The node features of the leaf nodes include any of the following:
[0218] First information, second information, third information.
[0219] Optionally, the first information includes at least one of the following:
[0220] The type of the parent node of the leaf node;
[0221] The order of the leaf nodes in the parent node;
[0222] The order of the parent node in its parent node;
[0223] The second information includes at least one of the following:
[0224] the type of the left node that is parallel to the parent node;
[0225] the value of the left node that is parallel to the parent node;
[0226] the type of the right node that is parallel to the parent node;
[0227] the value of the right node that is parallel to the parent node;
[0228] The third information includes the type of the root node and / or the value of the root node.
[0229] Optionally, the set generating unit 930 is specifically configured to determine the type and value of the node as the content of the completion prompt item.
[0230] Fig.11 The present invention is a structural diagram of an electronic device according to an exemplary embodiment of the present invention.
[0231] like Fig.11 As shown, the electronic device provided in this embodiment includes:
[0232] Memory 111;
[0233] Processor 112; and
[0234] Computer programs;
[0235] The computer program is stored in the memory 111 and is configured to be executed by the processor 112 to implement any one of the methods for determining code prompt information or the method for determining a feature data set as described above.
[0236] This embodiment also provides a computer-readable storage medium having a computer program stored thereon.
[0237] The computer program is executed by a processor to implement any one of the methods for determining code prompt information or the method for determining a feature data set as described above.
[0238] This embodiment further provides a computer program, including program code. When a computer runs the computer program, the program code executes any one of the methods for determining code prompt information or the methods for determining a feature data set as described above.
[0239] Those skilled in the art can understand that all or part of the steps of implementing the above-mentioned method embodiments can be completed by hardware related to program instructions. The aforementioned program can be stored in a computer-readable storage medium. When the program is executed, the steps of the above-mentioned method embodiments are executed; and the aforementioned storage medium includes: ROM, RAM, disk or optical disk and other media that can store program codes.
[0240] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present disclosure, rather than to limit them. Although the present disclosure has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or replace some or all of the technical features therein by equivalents. However, these modifications or replacements do not cause the essence of the corresponding technical solutions to deviate from the scope of the technical solutions of the embodiments of the present disclosure.
Claims
1. A method for determining code prompt information, characterized in that: include: Get the SQL statement to be completed and the preset feature data set; The feature data set includes a completion prompt item and a preset feature corresponding to the completion prompt item, the completion prompt item includes a node type and a node value, and the preset feature data set is obtained by processing an existing complete SQL statement; Determine a current node to be edited according to an abstract syntax tree corresponding to the SQL statement, and determine a node feature of the current node according to the SQL statement, wherein the node feature of the current node includes at least one of first information, second information, or third information, wherein the first information is information of a parent node of the current node, the second information is information of a parallel node parallel to the parent node, and the third information is information of a root node; According to the node feature and the preset feature, a completion prompt item for completing the current node is determined, and the node type and node value included in the completion prompt item are displayed.
2. The method according to claim 1, characterized in that Also includes: An abstract syntax tree corresponding to the SQL statement is generated.
3. The method according to claim 1, characterized in that The determining the node feature of the current node according to the abstract syntax tree of the SQL statement includes: Determine first information of a parent node of the current node according to the abstract syntax tree of the SQL statement; and / or, determining, according to the abstract syntax tree of the SQL statement, second information of a parallel node that is parallel to the parent node; And / or, determine third information of a root node of the abstract syntax tree of the SQL statement.
4. The method according to claim 3, characterized in that: The first information includes at least one of the following: The type of the parent node of the current node; The order of the current node in the parent node; The order of the parent node in its parent node; The second information includes at least one of the following: the type of the left node that is parallel to the parent node; the value of the left node that is parallel to the parent node; the type of the right node that is parallel to the parent node; the value of the right node that is parallel to the parent node; The third information includes the type of the root node and / or the value of the root node.
5. The method according to any one of claims 1 to 4, characterized in that: The determining, according to the node feature and the preset feature, a completion prompt item for completing the current node includes: Determining K preset features similar to the node feature in the feature data set; The completion prompt items corresponding to the K preset features are determined as the completion prompt items for completing the current node.
6. A method for determining a feature data set, characterized in that: include: Get the document including the complete SQL statement; Determine multiple nodes in the SQL statement, and determine node features of the nodes according to the SQL statement, wherein the nodes are leaf nodes, and the node features of the leaf nodes include at least one of first information, second information, or third information, wherein the first information is information of a parent node of the leaf node, the second information is information of a parallel node parallel to the parent node, and the third information is information of a root node; A completion prompt item is determined according to the node, and the feature data set is generated according to the completion prompt item and the node feature of the node; wherein the feature data set includes the completion prompt item and the node feature corresponding to the completion prompt item, and the feature data set is used to determine the completion prompt item of the SQL statement to be completed.
7. The method according to claim 6, characterized in that The node is a leaf node; The method further comprises: An abstract syntax tree corresponding to the SQL statement is generated.
8. The method according to claim 7, characterized in that The step of determining the node feature of the leaf node according to the abstract syntax tree of the SQL statement includes: Determine first information of a parent node of the leaf node according to the abstract syntax tree of the SQL statement; and / or, determining, according to the abstract syntax tree of the SQL statement, second information of a parallel node that is parallel to the parent node; And / or, determine third information of a root node of the abstract syntax tree of the SQL statement.
9. The method according to claim 8, characterized in that The first information includes at least one of the following: The type of the parent node of the leaf node; The order of the leaf nodes in the parent node; The order of the parent node in its parent node; The second information includes at least one of the following: the type of the left node that is parallel to the parent node; the value of the left node that is parallel to the parent node; the type of the right node that is parallel to the parent node; the value of the right node that is parallel to the parent node; The third information includes the type of the root node and / or the value of the root node.
10. A device for determining code prompt information, characterized in that: include: An acquisition unit, used to acquire the SQL statement to be completed and a preset feature data set; The feature data set includes a completion prompt item and a preset feature corresponding to the completion prompt item, the completion prompt item includes a node type and a node value, and the feature data set is obtained by processing an existing complete SQL statement; a determining unit, configured to determine a current node to be edited according to an abstract syntax tree corresponding to the SQL statement, and determine a node feature of the current node according to the SQL statement, wherein the node feature of the current node includes at least one of first information, second information, or third information, wherein the first information is information of a parent node of the current node, the second information is information of a parallel node parallel to the parent node, and the third information is information of a root node; A prompt unit is used to determine a completion prompt item for completing the current node according to the node feature and the preset feature, and display the node type and node value included in the completion prompt item.
11. A device for determining a feature data set, characterized in that: include: A document acquisition unit, used for acquiring a document including a complete SQL statement; a feature extraction unit, configured to determine a plurality of nodes in the SQL statement, and determine node features of the nodes according to the SQL statement, wherein the nodes are leaf nodes, and the node features of the leaf nodes include at least one of first information, second information, or third information, wherein the first information is information of a parent node of the leaf node, the second information is information of a parallel node parallel to the parent node, and the third information is information of a root node; A set generation unit is used to determine a completion prompt item according to the node, and generate the feature data set according to the completion prompt item and the node feature of the node; wherein the feature data set includes the completion prompt item and the node feature corresponding to the completion prompt item, and the feature data set is used to determine the completion prompt item of the SQL statement to be completed.
12. An electronic device, characterized in that: include: Memory; processor; as well as Computer programs; The computer program is stored in the memory and is configured to be executed by the processor to implement the method according to any one of claims 1 to 9.
13. A computer-readable storage medium, characterized in that: The storage medium stores a computer program, and the computer program is executed by a processor to implement the method according to any one of claims 1 to 5 or any one of claims 6 to 9.
14. A computer program product, characterized in that The computer program product comprises a program code, and when a computer runs the computer program product, the program code executes the method according to any one of claims 1 to 5 or any one of claims 6 to 9.
Citation Information
Patent Citations
SQL statement intelligent completion method based on use scene
CN111444708A