Query statement generation method, device, electronic device and computer readable medium
By extracting the features of input characters and historical query statement sets, predicting and sorting query vocabulary, generating high-accuracy and efficient query statements, and optimizing the execution order of query statements through reinforcement learning, the problems of query statement generation and optimization in the existing technology are solved, improving user experience and query efficiency.
Patent Information
- Application Number
- CN202411023730.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-29
- Publication Date
- 2025-04-08
- Estimated Expiration
- 2044-07-29
AI Technical Summary
When generating query statements, the input data is single, resulting in low accuracy and poor user experience of the generated query statements; at the same time, the efficiency of single-step completion is low, and there are problems of gradient vanishing and error accumulation in multi-step prediction, which is low accuracy and efficiency; dynamic programming algorithms have limitations and large search space when optimizing query statements, resulting in unoptimal optimization results.
By obtaining input characters and historical structured query statement sets, context node type feature extraction is performed, query vocabulary is predicted by combining database information, and using historical vocabulary to filter and sort, a predicted query vocabulary sequence displayed in paging is generated; statement completion and execution are performed in response to user selection operations, and query results are generated; when optimizing query statements, statement measurement is performed, association relationships are encoded and predicates are selected, and execution order is optimized using reinforcement learning model.
It improves the accuracy of the generated query statements and the user query rate, and improves the user experience; by optimizing the execution order of the query statements, it improves the data accuracy and query time, and reduces the waste of memory resources.
Smart Images

Figure CN119003571B_ABST
Abstract
Description
Technical Field
[0001] Embodiments of the present disclosure relate to the field of computer technology, and in particular to a query statement generation method, device, electronic device, and computer-readable medium. Background Art
[0002] Structured Query Language (SQL) is a special-purpose programming language used to access data and query, update, and manage relational database systems. However, writing SQL statements requires a high level of SQL proficiency from the user, and the writing process is tedious, time-consuming, and labor-intensive. For the generation of query statements, the commonly used method is: in response to detecting the input operation of the above-mentioned target user, the input data corresponding to the input operation is obtained. The input data is lexically serialized to obtain an input lexical sequence. Finally, the sequence model is used to complete the input lexical sequence to obtain a structured query statement.
[0003] However, in practice, it has been found that when using the above method to generate query statements, the following technical problems often arise: Since the input data only includes the above information of the query statement to be completed, and the sequence model only learns the semantics of the input data, the influencing factors of learning are too single, resulting in low accuracy of the generated query statement to be completed, which reduces the user query experience.
[0004] In the process of adopting technical solutions to solve the above-mentioned technical problem 1, the following technical problem 2 is often accompanied: single-step completion of the structured query statement to be completed can improve the accuracy of the structured query statement to be completed, but single-step completion can only predict one sentence word at a time, which prolongs the completion time, reduces the completion efficiency, and reduces the user experience. In response to the above-mentioned technical problem 2, the conventional solution is generally to use a Seq2Seq model (sequence to sequence) model of a long short-term memory neural network to perform multi-step completion on the structured query statement to be completed, obtain the completed structured query statement and display the query result of the completed structured query statement. However, the above-mentioned conventional solution still has the following problems: because the Seq2Seq model using a long short-term memory neural network has a gradient vanishing problem when the sequence of the structured query statement to be completed is long, and it needs to consume a large amount of computing resources, and the Seq2Seq model has an error accumulation problem when performing multi-step prediction, resulting in a low accuracy rate of the generated completed structured query statement, an increase in the waste of memory resources, a low completion efficiency, and a reduced user experience.
[0005] In the process of adopting technical solutions to solve the above-mentioned technical problem one, the following technical problem three is often accompanied: how to optimize the generated query statements to be completed, so as to reduce the system resources consumed when executing the query statements to be completed and improve the efficiency of statement execution. In response to the above-mentioned technical problem three, the conventional solution is generally to use a dynamic programming algorithm to optimize the structured query statement information set. However, the above-mentioned conventional solution still has the following problems: since the dynamic programming algorithm is based on various evaluation indicators discovered empirically by experts for algorithm initialization, there are great limitations, and the dynamic programming algorithm requires a large search space, which can easily cause the optimized query statement to be not the optimal query statement, the accuracy of the acquired data is low, and the query time is long, resulting in a poor user experience and a large waste of memory resources.
[0006] The above information disclosed in this Background section is only for enhancement of understanding of the background of the present disclosure concept and therefore it may contain information that does not form the prior art that is already known in this country to a person of ordinary skill in the art. Summary of the Invention
[0007] The content of this disclosure is used to briefly introduce concepts that will be described in detail in the detailed description section below. The content of this disclosure is not intended to identify key features or essential features of the claimed technical solution, nor is it intended to limit the scope of the claimed technical solution.
[0008] Some embodiments of the present disclosure provide query statement generation methods, devices, electronic devices, and computer-readable media to solve one or more of the technical problems mentioned in the above background technology section.
[0009] In a first aspect, some embodiments of the present disclosure provide a query statement generation method, comprising: in response to detecting an input operation of a target user, obtaining input characters and a historical structured query statement set corresponding to the input operation; based on the input characters, executing the following query statement generation steps: in response to determining that the character position of the input character is not the starting position, obtaining the structured query statement to be completed that is located before the input character; performing context node type feature extraction on the structured query statement to be completed to obtain a predicted vocabulary node type feature vector set; predicting the query vocabulary corresponding to the input character based on the predicted vocabulary node type feature vector set, the input character and database information to obtain a predicted query vocabulary set, wherein the above-mentioned database information is a data table set and a data field set included in each data table of the database corresponding to the structured query statement to be completed; generating a historical vocabulary set based on the above-mentioned historical structured query statement set; and The historical vocabulary set is used to determine the vocabulary position information of each predicted query vocabulary in the predicted query vocabulary set to obtain a vocabulary position information set; the predicted query vocabulary set is sorted according to the vocabulary position information set to obtain a predicted query vocabulary sequence, and the predicted query vocabulary sequence is sent in a paged form to the user terminal corresponding to the above-mentioned target user for paged display; in response to detecting the selection operation of the above-mentioned target user on the predicted query vocabulary sequence, sentence completion is performed on the structured query statement to be completed to obtain a structured query statement; in response to detecting the execution operation of the above-mentioned target user on the structured query statement, a sentence query result of the above-mentioned structured query statement is generated, and the above-mentioned sentence query result is sent to the above-mentioned user terminal for terminal display; in response to detecting the input operation of the above-mentioned target user, the current input character corresponding to the input operation is determined as the input character, so as to execute the above-mentioned query statement determination step again.
[0010] In a second aspect, some embodiments of the present disclosure provide a query statement generation device, comprising: an acquisition unit, configured to, in response to detecting an input operation of a target user, acquire input characters and a set of historical structured query statements corresponding to the input operation; an execution unit, configured to, based on the input characters, execute the following query statement generation steps: in response to determining that the character position of the input character is not the starting position, acquire the structured query statement to be completed that is located before the input character; perform context node type feature extraction on the structured query statement to be completed to obtain a predicted vocabulary node type feature vector set; predict the query vocabulary corresponding to the input character based on the predicted vocabulary node type feature vector set, the input character and database information to obtain a predicted query vocabulary set, wherein the database information is a set of data tables and a set of data fields included in each data table included in the database corresponding to the structured query statement to be completed; generate a historical vocabulary based on the above-mentioned set of historical structured query statements set; based on the above historical vocabulary set, determining the vocabulary position information of each predicted query vocabulary in the predicted query vocabulary set to obtain a vocabulary position information set; based on the vocabulary position information set, sorting the predicted query vocabulary set to obtain a predicted query vocabulary sequence, and sending the predicted query vocabulary sequence in a paged form to the user terminal corresponding to the above target user for paged display; in response to detecting the selection operation of the above target user on the predicted query vocabulary sequence, completing the structured query statement to be completed to obtain a structured query statement; in response to detecting the execution operation of the above target user on the structured query statement, generating a sentence query result of the structured query statement, and sending the sentence query result to the above user terminal for terminal display; a determining unit is configured to, in response to detecting the input operation of the above target user, determine the current input character corresponding to the input operation as the input character, so as to execute the above query statement determination step again.
[0011] In a third aspect, some embodiments of the present disclosure provide an electronic device comprising: one or more processors; a storage device on which one or more programs are stored, and when the one or more programs are executed by one or more processors, the one or more processors implement the method described in any implementation manner in the first aspect.
[0012] In a fourth aspect, some embodiments of the present disclosure provide a computer-readable medium having a computer program stored thereon, wherein when the computer program is executed by a processor, the method described in any implementation manner in the first aspect is implemented.
[0013] The above-described embodiments of the present disclosure have the following beneficial effects: the query statement generation method of some embodiments of the present disclosure can improve the accuracy of generated query statements and user query rate, thereby enhancing user experience. Specifically, the low accuracy of the generated structured query statements and the reduced user query experience are caused by the fact that the input data only includes the contextual information of the query statement to be completed, and the sequence model only learns the semantics of the input data. The learning influencing factors are too single, resulting in low accuracy of the generated query statement to be completed, thereby reducing the user query experience. Based on this, the query statement generation method of some embodiments of the present disclosure can first, in response to detecting an input operation of a target user, obtain the input characters and historical structured query statement set corresponding to the input operation. Here, the input characters and historical structured query statement set are used for subsequent prediction of a query vocabulary. Then, based on the input characters, the following query statement generation steps are performed: First, in response to determining that the character position of the input character is not the starting position, obtain the structured query statement to be completed that is located before the input character. Here, the structured query statement to be completed is used to provide context information for subsequent prediction of the query vocabulary. The second step is to extract context node type features from the structured query statement to be completed to obtain a set of predicted vocabulary node type feature vectors. Extracting context node type features can improve the accuracy of feature extraction and the quality of the predicted vocabulary node type feature vectors. The third step is to predict the query terms corresponding to the input characters based on the predicted vocabulary node type feature vector set, the input characters, and database information to obtain a predicted query vocabulary set, where the database information is the set of data tables and the set of data fields included in each data table in the database corresponding to the structured query statement to be completed. By using the predicted vocabulary node type feature vector set, the input characters, and the database information, multiple factors affecting the accuracy of the predicted query terms are considered, thereby improving the accuracy of the predicted query terms. The fourth step is to generate a historical vocabulary set based on the above-mentioned historical structured query statement set. This is used to screen the above-mentioned predicted query terms, taking into account the user habits of the target user, making the completed structured query statement more personalized. The fifth step is to determine the vocabulary position information of each predicted query term in the predicted query vocabulary set based on the above-mentioned historical vocabulary set to obtain a vocabulary position information set. Here, the predicted probability values for each predicted query term in the predicted query vocabulary set are determined, facilitating subsequent placement of predicted query terms with higher probability values at the front, thereby improving the user experience. In the sixth step, the predicted query vocabulary set is sorted based on the vocabulary position information set to obtain a predicted query vocabulary sequence. This predicted query vocabulary sequence is then sent in paginated form to the user terminal corresponding to the target user for paginated display.Here, the predicted query words with a higher prediction probability are placed in the front position and displayed in pages, so that the user can find the sentence words corresponding to the input characters in the first few positions, reducing the user operation steps and improving the user experience. The seventh step is to complete the structured query statement to be completed in response to detecting the target user's selection operation on the predicted query word sequence, and obtain a structured query statement. Here, the accuracy of the structured query statement can be improved and the workload of the target user in writing the structured query statement can be reduced. The eighth step is to generate a sentence query result of the structured query statement in response to detecting the target user's execution operation on the structured query statement, and send the sentence query result to the user terminal and display it on the terminal. Here, the execution efficiency of the structured query statement can be improved and the query time can be reduced. Finally, in response to detecting the input operation of the target user, the current input character corresponding to the input operation is determined as the input character, and the query statement determination step is performed again. Here, the completion of the structured query statement to be completed is performed through a loop execution method, which can reduce the workload of the target user in writing and improve the user experience. Therefore, the query statement generation method can improve the accuracy of the generated query statement and the user query rate, thereby improving the user experience. BRIEF DESCRIPTION OF THE DRAWINGS
[0014] The above and other features, advantages, and aspects of the various embodiments of the present disclosure will become more apparent with reference to the following detailed description in conjunction with the accompanying drawings. Throughout the drawings, the same or similar reference numerals represent the same or similar elements. It should be understood that the drawings are schematic and that components and elements are not necessarily drawn to scale.
[0015] Figure 1 is a flowchart of some embodiments of the query statement generation method according to the present disclosure;
[0016] Figure 2 is a schematic structural diagram of some embodiments of the query statement generating device according to the present disclosure;
[0017] Figure 3 It is a structural diagram of an electronic device suitable for implementing some embodiments of the present disclosure. DETAILED DESCRIPTION
[0018] Embodiments of the present disclosure will be described in more detail below with reference to the accompanying drawings. Although certain embodiments of the present disclosure are shown in the accompanying drawings, it should be understood that the present disclosure can be implemented in various forms and should not be construed as being limited to the embodiments described herein. On the contrary, these embodiments are provided to provide a more thorough and complete understanding of the present disclosure. It should be understood that the drawings and embodiments of the present disclosure are for illustrative purposes only and are not intended to limit the scope of protection of the present disclosure.
[0019] It should also be noted that, for ease of description, only the parts related to the invention are shown in the drawings. In the absence of conflict, the embodiments and features in the embodiments of the present disclosure may be combined with each other.
[0020] It should be noted that the concepts of "first" and "second" mentioned in this disclosure are only used to distinguish different devices, modules or units, and are not used to limit the order or interdependence of the functions performed by these devices, modules or units.
[0021] It should be noted that the modifications of "one" and "multiple" mentioned in the present disclosure are illustrative rather than restrictive, and those skilled in the art should understand that unless otherwise clearly indicated in the context, they should be understood as "one or more".
[0022] The names of the messages or information exchanged between multiple devices in the embodiments of the present disclosure are only used for illustrative purposes and are not used to limit the scope of these messages or information.
[0023] The present disclosure will be described in detail below with reference to the accompanying drawings and in conjunction with embodiments.
[0024] Figure 1 The process 100 of some embodiments of the query statement generation method according to the present disclosure is shown. The query statement generation method includes the following steps:
[0025] Step 101: In response to detecting an input operation of a target user, obtaining input characters and a set of historical structured query statements corresponding to the input operation.
[0026] In some embodiments, the execution subject (e.g., electronic device) of the query statement generation method can obtain the input characters and historical structured query statement set corresponding to the input operation through a wired connection or a wireless connection in response to detecting the input operation of the target user. The target user may be the user of the user terminal who is currently performing the input operation. The input characters may be the current input characters of the structured query statement to be completed that the target user is currently entering. For example, the input may be the s in select. The historical structured query statements in the historical structured query statement set may be SQL statements entered by the target user before the current time.
[0027] Step 102: Based on the input characters, execute the following query statement generation steps:
[0028] Step 1021 : In response to determining that the character position of the input character is not the starting position, obtaining a structured query statement to be completed that is located before the input character.
[0029] In some embodiments, in response to determining that the position of the input character is not the starting position, the execution entity may obtain a structured query statement to be completed that precedes the input character. The structured query statement to be completed may be an incomplete structured query statement that has been output before the input character. For example, the structured query statement to be completed may be select * from.
[0030] Step 1022 : extract context node type features from the structured query statement to be completed to obtain a predicted vocabulary node type feature vector.
[0031] In some embodiments, the execution subject may perform context node type feature extraction on the structured query statement to be completed to obtain a predicted vocabulary node type feature vector. The predicted vocabulary node type feature vector may characterize the type of vocabulary corresponding to the input character. The types of vocabulary include: structured query statement keywords, database fields, and operators. The structured query statement keywords may be reserved words specified in the structured query statement. For example, the structured query statement keywords may be, but are not limited to, at least one of the following: select, drop, from, group by. The database fields may be words related to the data tables included in the database, the fields included in the data tables, and the field attributes. For example, the database field may be a data table name, or a name field in a data table.
[0032] As an example, the execution entity may input the structured query statement to be completed into a temporal convolutional neural network to obtain a predicted vocabulary node type feature vector.
[0033] In some optional implementations of some embodiments, extracting context node type features from the structured query to be completed to obtain a predicted vocabulary node type feature vector may include the following steps:
[0034] The first step is to embed the vocabulary node type node set and vocabulary node value node set included in the abstract syntax tree corresponding to the above-mentioned structured query statement to be completed, and obtain a vocabulary node type embedding vector set and a vocabulary node value embedding vector set. The above-mentioned abstract syntax tree can be a tree structure that represents the grammatical structure of the structured query statement to be completed. The child nodes of the above-mentioned abstract syntax tree can represent various parts of the structured query statement to be completed. For example, the child nodes of the above-mentioned abstract syntax tree can be, but are not limited to, at least one of the following: a drop clause node, a where clause node, and a between clause node. The leaf nodes of the above-mentioned abstract syntax tree can represent words or expressions. For example, the leaf nodes of the above-mentioned abstract syntax tree can be, but are not limited to, at least one of the following: a statement keyword, a table name, a column name, a field attribute value, and an expression. The vocabulary node type nodes in the above-mentioned vocabulary node type node set can be nodes that represent the type of the vocabulary. The vocabulary node value nodes in the above-mentioned vocabulary node value node set can be nodes that represent the attribute value corresponding to the vocabulary. The vocabulary node type embedding vectors in the above-mentioned vocabulary node type embedding vector set can represent the type information of the vocabulary. The lexical node value embedding vectors in the above-mentioned lexical node value embedding vector set can represent the attribute values of the vocabulary. In practice, the above-mentioned execution subject can first use a lexical segmenter to perform lexical segmentation on the above-mentioned structured query statement to be completed to obtain a structured query morpheme set. Among them, the structured query morphemes in the above-mentioned structured query morpheme set may include: structured query statement keywords, database fields, operators and lexical attribute values. Then, using a syntax parser, an abstract syntax tree is constructed for the above-mentioned structured query morpheme set to obtain an abstract syntax tree. Finally, using the Word2Vec algorithm, the lexical node type node set and the lexical node value node set included in the abstract syntax tree are embedded to obtain a lexical node type embedding vector set and a lexical node value embedding vector set.
[0035] In the second step, the above-mentioned vocabulary node type embedding vector set and the above-mentioned vocabulary node value embedding vector set are concatenated to obtain a vocabulary node concatenated embedding vector set.
[0036] In the third step, the concatenated vocabulary node embedding vector set is input into the forward sentence completion network to obtain a forward vocabulary node feature vector set. The forward sentence completion network can be a neural network model that captures the long-distance dependency of the input vocabulary node embedding vector set and extracts the semantic information of multiple words that precede the input characters in the structured query sentence to be completed. For example, the forward sentence completion network can be a forward long short-term memory network. The forward vocabulary node feature vector in the forward vocabulary node feature vector set can be the semantic information of the words that precede the input characters in the structured query sentence to be completed.
[0037] The fourth step is to input the forward vocabulary node feature vector set into the backward sentence completion network to obtain the backward vocabulary node feature vector set. The backward sentence completion network can be a neural network model that captures the long-distance dependency of the input vocabulary node embedding vector set and extracts the semantic information of multiple words located after the input character in the structured query sentence to be completed. For example, the forward sentence completion network can be a backward long short-term memory network. The backward vocabulary node feature vector in the backward vocabulary node feature vector set can be the semantic information of the words located after the input character in the structured query sentence to be completed.
[0038] The fifth step is to perform feature concatenation on the backward vocabulary node feature vector set and the forward vocabulary node feature vector set to obtain a context feature vector set for the input character.
[0039] In the sixth step, the backward vocabulary node feature vector set and the context feature vector set are input into the context attention mechanism layer to obtain the vocabulary context feature vector set.
[0040] In the seventh step, the lexical node type embedding vector of the parent node of the input character, the lexical context feature vector set, and the backward lexical node feature vector set are concatenated to obtain a lexical node concatenation feature vector set. The lexical node type embedding vector of the parent node of the input character may be an embedding vector obtained by performing word embedding processing on the node type of the parent node of the input character.
[0041] The eighth step is to predict the vocabulary node type of the above-mentioned vocabulary node splicing feature vector set to obtain a predicted vocabulary node type feature vector set. The above-mentioned predicted vocabulary node type feature vector can characterize the vocabulary type of the sentence vocabulary corresponding to the predicted input character. In practice, the above-mentioned execution subject can first input the above-mentioned vocabulary node splicing feature vector set into the fully connected layer to perform feature dimension transformation to obtain a vocabulary node dimension feature vector set. Secondly, the above-mentioned vocabulary node dimension feature vector set is input into the hyperbolic tangent activation function to obtain the activated vocabulary node feature vector set. Then, the above-mentioned activated vocabulary node feature vector set is spatially mapped to obtain the mapped vocabulary node feature vector set. Finally, the above-mentioned mapped vocabulary node feature vector set is input into the step activation function to obtain the predicted vocabulary node type feature vector set. The above-mentioned step activation function can be a Sigmod activation function.
[0042] Step 1023 : predicting the query terms corresponding to the input characters based on the predicted vocabulary node type feature vector set, the input characters, and the database information to obtain a predicted query vocabulary set.
[0043] In some embodiments, the execution entity may predict query terms corresponding to the input characters based on a predicted vocabulary node type feature vector set, the input characters, and database information to obtain a predicted query vocabulary set, wherein the database information includes a set of data tables and a set of data fields in each data table included in a database corresponding to the structured query statement to be completed. The predicted query terms in the predicted query vocabulary set may be complete terms predicted for the input characters.
[0044] As an example, the execution entity may first input the predicted vocabulary node type feature vector into a pointer network to obtain an initial predicted query vocabulary set. Secondly, at least one initial predicted query vocabulary identical to the input character may be filtered out from the initial predicted query vocabulary set to obtain a filtered predicted query vocabulary set. Then, the filtered predicted query vocabulary set is matched with the database information to obtain a vocabulary matching result set. Finally, at least one filtered predicted query vocabulary corresponding to at least one vocabulary matching result in the vocabulary matching result set that indicates a successful match is determined as the predicted query vocabulary set.
[0045] In some optional implementations of some embodiments, predicting the query terms corresponding to the input characters based on the predicted vocabulary node type feature vector, the input characters, and database information to obtain a predicted query vocabulary set may include the following steps:
[0046] In the first step, feature concatenation is performed on the backward vocabulary node feature vector set and the vocabulary context feature vector set to obtain a concatenated vocabulary node feature vector set.
[0047] The second step is to perform pointer prediction on the above-mentioned concatenated vocabulary node feature vector set to obtain a vocabulary pointer feature vector set. The above-mentioned vocabulary pointer feature vector can represent the position information of the sentence vocabulary corresponding to the input character. The above-mentioned position information can be located in a preset dictionary, or in front of or behind the input character in the structured query sentence to be completed. In practice, the above-mentioned execution entity can input the above-mentioned concatenated vocabulary node feature vector set into the Sigmod activation function to obtain a vocabulary pointer feature vector set.
[0048] In the third step, the feature vector set of the vocabulary node type to be predicted and the feature vector set of the vocabulary pointer are multiplied to obtain a first feature vector set to be predicted.
[0049] The fourth step is to determine the feature difference between the preset vocabulary feature vector set and the vocabulary pointer feature vector set to obtain a difference vocabulary pointer feature vector set. The preset vocabulary feature vectors in the preset vocabulary feature vector set may be pre-set feature vectors. For example, the preset vocabulary feature vectors may be feature vectors whose elements are 1.
[0050] In the fifth step, the vocabulary node weight feature vector set and the difference vocabulary pointer feature vector set are subjected to feature multiplication processing to obtain a second feature vector set to be predicted.
[0051] In the sixth step, the first feature vector set to be predicted and the second feature vector set to be predicted are concatenated to obtain a feature vector set of node values to be predicted.
[0052] In the seventh step, the node value feature vector set to be predicted is processed for vocabulary prediction to obtain a vocabulary set to be predicted. In practice, the execution entity may input the node value feature vector set to be predicted into a fully connected layer to obtain a vocabulary set to be predicted.
[0053] In the eighth step, the to-be-predicted vocabulary set is screened based on the input characters and the database information to obtain a predicted query vocabulary set.
[0054] As an example, the execution entity may first select at least one predicted word that is identical to the input character from the set of predicted words to obtain a filtered set of predicted words. Then, the filtered set of predicted words is matched with the set of data tables, the set of fields, and the set of field attributes within each data table included in the database information to obtain a set of predicted matching results. Finally, the at least one filtered set of predicted words corresponding to at least one predicted matching result in the set of predicted matching results indicating a successful match is determined as the predicted query word set.
[0055] In some optional implementations of some embodiments, after predicting the query terms corresponding to the input characters based on the predicted vocabulary node type feature vector set, the input characters, and the database information to obtain the predicted query vocabulary set, the method may further include the following steps:
[0056] The first step is to perform character segmentation on the preset structured query keyword set, the data table set, and the field set and field attribute set of each data table included in the database information to obtain a sentence character set, and then determine the preset structured query keyword set, the data table set, the field group set, and the field attribute group set as a sentence query corpus. The sentence characters in the sentence character set can be single English characters.
[0057] In the second step, the sentence character set is deduplicated to obtain a deduplicated sentence character set, and the deduplicated sentence character set is added to a preset initial word list to obtain an added initial word list. The preset initial word list may be a pre-set list for storing the deduplicated sentence character set.
[0058] In the third step, based on the deduplicated character set and the initial word list after addition, perform the following addition steps:
[0059] Sub-step 1, performing character combination deletion processing on the above-mentioned deduplicated sentence character set to obtain a combined sentence character set. In the first loop, the combined sentence character can be a combined character obtained by combining two adjacent deduplicated sentence characters. In the subsequent loops, the combined sentence character is a sentence character obtained by combining and splicing the newly added combined sentence character obtained in the previous loop and the deduplicated sentence character of the previous loop. The above-mentioned newly added combined sentence character can be a character obtained by removing the deduplicated character set from the target word set included in the target word vocabulary.
[0060] As an example, the execution subject may first combine and splice the above-mentioned deduplicated sentence character set to obtain a combined spliced character set. Secondly, each combined spliced character in the above-mentioned combined spliced character set is matched with each vocabulary in the above-mentioned sentence query corpus to obtain a character matching result set. Then, the combined spliced character corresponding to at least one character matching result representing an unmatched match in the above-mentioned character matching result set is determined as the target combined spliced character. Finally, the target combined spliced character set is removed from the above-mentioned combined spliced character set to obtain the removed combined spliced character set as the combined sentence character set.
[0061] Sub-step 2: Determine the frequency of occurrence of each combined sentence character in the combined sentence character set in the sentence query corpus to obtain a combined character frequency set. The combined character frequency in the combined character frequency set can represent the number of times the combined sentence character appears in the sentence query corpus.
[0062] Sub-step 3, filtering out the combination character occurrence frequency with the largest value from the above combination character occurrence frequency set to obtain the target combination character occurrence frequency, and adding the combined sentence characters corresponding to the above target combination character occurrence frequency to the added initial word list to obtain the target word list.
[0063] Sub-step 4: In response to determining that the number of target words included in the target word list is greater than or equal to a preset word threshold, determining the target word list as a node attribute value set. The preset word threshold may be a preset maximum number of target words that can be stored in the preset initial word list.
[0064] In the fourth step, in response to determining that the number of target words included in the target word list is less than the above-mentioned preset word threshold, the target character set included in the target word list is determined as the sentence character set after deduplication, and the target word list is determined as the initial word list after addition, so as to perform the above-mentioned addition step again.
[0065] The fifth step is to perform word vector processing on each query statement node in the grammatical abstract tree corresponding to the above-mentioned structured query statement to be completed, and obtain a query statement node feature vector set, wherein the above-mentioned query statement node includes: the node type of the query statement node and the node attribute value of the query statement node, that is, the attribute value obtained by combining the target word set included in the target word vocabulary. Among them, the above-mentioned query statement node can be the statement vocabulary and the attribute value corresponding to the statement vocabulary in the structured query statement to be completed. When the attribute value does not exist in the above-mentioned query statement node, the attribute value is set to empty. For example, the above-mentioned structured query statement to be completed can be select*from users where last_name="Smith"and. The above-mentioned query statement node can be select and empty, or it can be last_name and Smith.
[0066] In the sixth step, the query sentence node feature vector set is input into a first gated recurrent unit network to obtain a first node hidden feature vector set. The first gated recurrent unit network can be a GRU deep neural network.
[0067] In the seventh step, the first node hidden feature vector set is input into the second gated recurrent unit network to obtain a second node hidden feature vector set.
[0068] In the eighth step, the second node hidden feature vector set is input into the attention mechanism network to obtain the node weight feature vector set.
[0069] In the ninth step, the above node weight feature vector set is fused to obtain the fused node weight feature vector.
[0070] In the tenth step, the fused node weight feature vector and the second node hidden feature vector set are input into a decoder of the fused Gaussian mixture model to obtain a predicted query vocabulary set. In response to a selection operation on the predicted query vocabulary set, the structured query to be completed is completed to obtain a structured query statement. The decoder may be a decoder comprising a two-layer GRU model and a regression classification layer. The regression classification layer may be a fully connected layer including a Softmax activation function.
[0071] The above-mentioned steps 1 to 10, as well as the result step "step 1028" and its related content, as an inventive point of an embodiment of the present disclosure, solve the second technical problem mentioned in the background technology: "Because the Seq2Seq model using the long short-term memory neural network has a gradient vanishing problem when the sequence of structured query statements to be completed is long, and requires a large amount of computing resources, and the Seq2Seq model has an error accumulation problem when performing multi-step predictions, the accuracy of the generated completed structured query statements is low, which increases the waste of memory resources, the completion efficiency is low, and the user experience is reduced." The factors that lead to the low accuracy of the generated completed structured query statements, increased waste of memory resources, low completion efficiency, and reduced user experience are often as follows: Because the Seq2Seq model using the long short-term memory neural network has a gradient vanishing problem when the sequence of structured query statements to be completed is long, and requires a large amount of computing resources, and the Seq2Seq model has an error accumulation problem when performing multi-step predictions. If the above factors are solved, the accuracy of the generated completed structured query statements can be improved, the waste of memory resources can be reduced, and the completion efficiency and user experience can be improved. In order to achieve this effect, the present disclosure first performs character segmentation and combination on the statement query vocabulary set included in the statement query corpus. Since the attribute values corresponding to the statement vocabulary are artificially defined custom identifiers, there will be a large number of irregular statement vocabularies. Character segmentation and combination can reduce the workload of word encoding for a large number of attribute values through sub-characters, and since custom identifiers are obtained by combining sub-character sets, the amount of data for word encoding can be reduced, the accuracy of word encoding for attribute values can be improved, and the error accumulation in completion prediction can be further reduced. Secondly, word vector processing is performed on the query statement node set to obtain a query statement node feature vector set, which can reduce the amount of data processed by the word vector and reduce the waste of computing resources. The query node feature vectors are then fed into the first gated recurrent unit network, the second gated recurrent unit network, and the attention mechanism network. Because the gated recurrent unit network has fewer parameters than the long-short-term memory (LSTM) neural network, and the attention mechanism network prioritizes query nodes that have a greater impact on predicted vocabulary, this reduces feature extraction computational resources and addresses the vanishing gradient problem. The hidden feature vectors of the second node are then fused. Because the gated recurrent unit can extract long-term and short-term dependencies between the vocabulary in the structured query to be completed, fusion of these dependencies further reduces error accumulation in multi-step predictions.Finally, the above-mentioned fused node weight feature vector and the above-mentioned second node hidden feature vector set are input into the decoder of the fused Gaussian mixture model, which can improve the accuracy and prediction probability value of each predicted query vocabulary set. According to the predicted query vocabulary set, the structured query statement to be completed is completed to generate a structured query statement, and the query result of the structured query statement is sent to the target terminal for display, which can improve the accuracy of the query result, reduce the waste of transmission resources and improve the user experience.
[0072] Step 1024: Generate a historical vocabulary set based on the historical structured query statement set.
[0073] In some embodiments, the execution entity may generate a historical vocabulary set based on the historical structured query statement set. The historical vocabulary in the historical vocabulary set may be a sentence vocabulary in the historical structured query statement set. The sentence vocabulary may be, but is not limited to, at least one of the following: a structured query statement keyword, a database field, and an operator.
[0074] As an example, the execution entity may first perform word segmentation processing on each historical structured query statement in the historical structured query statement set to obtain a historical statement vocabulary set. Secondly, the historical statement vocabulary set may be deduplicated to obtain a deduplicated statement vocabulary set. Then, the frequency of occurrence of each deduplicated statement vocabulary in the deduplicated statement vocabulary set may be determined to obtain a vocabulary frequency set. Finally, the vocabulary frequency set and the deduplicated statement vocabulary set may be determined as the historical vocabulary set.
[0075] In some optional implementations of some embodiments, generating a historical vocabulary set based on the historical structured query statement set may include the following steps:
[0076] In the first step, for each historical structured query statement in the above historical structured query statement set, perform the following feature quantification steps:
[0077] Sub-step 1: construct an abstract syntax tree for the historical structured query to obtain an abstract syntax tree of the historical query. The abstract syntax tree to be completed may be a syntax tree that represents the semantic information and structural information of the historical structured query in the form of a tree structure.
[0078] Sub-step 2: Perform pre-order serialization on the historical statement abstract syntax tree to obtain a historical statement vocabulary node sequence. The to-be-completed sentence vocabulary node sequence may be a sequence representing the text and structure information of the historical structured query statement in sequence form. In practice, the execution entity may utilize a pre-order depth-first traversal algorithm to perform pre-order serialization on the historical statement abstract syntax tree to obtain a historical statement vocabulary node sequence.
[0079] Sub-step 3: classify the above historical sentence lexical node sequence to obtain a lexical node type node set and a lexical node value node set.
[0080] Sub-step 4: Perform node type encoding on each lexical node type node in the lexical node type node set to generate a lexical node type encoding vector, thereby obtaining a lexical node type encoding vector set. The lexical node type encoding vector may represent structural information of the historical structured query statement. The structural information may include whether the lexical node type node has child nodes and sibling nodes.
[0081] As an example, the execution entity may perform the following first encoding step for each lexical node type node in the lexical node type node set: First, numerically encode the lexical node type node to obtain a lexical node type value. Second, in response to determining that the lexical node type node has child nodes and sibling nodes, determine the lexical node type encoding vector as the product of the lexical node type value and a first preset threshold, and the sum of the product and a second preset threshold. The first and second preset thresholds may be preset values. For example, the first preset threshold may be 4. The second preset threshold may be 3. Third, in response to determining that the lexical node type node has child nodes and no sibling nodes, determine the lexical node type encoding vector as the product of the lexical node type value and the first preset threshold, and the sum of the product and a third preset threshold. The third preset threshold may be a preset value. For example, the third preset threshold may be 2. Finally, in response to determining that the lexical node type node has no child nodes and has sibling nodes, determine the lexical node type encoding vector as the product of the lexical node type value and the first preset threshold, and the sum of the product and a fourth preset threshold. The fourth preset threshold may be a pre-set value. For example, the fourth preset threshold may be 1. Finally, in response to determining that the lexical node type node has no child nodes and no sibling nodes, the product of the lexical node type value and the first preset threshold is determined as the lexical node type encoding vector.
[0082] Sub-step 5: Perform node value encoding on each lexical node value node in the lexical node value node set to generate a lexical node value encoding vector, thereby obtaining a lexical node value encoding vector set. The lexical node value encoding vectors in the lexical node value encoding vector set can represent the semantic information of the historical structured query statement.
[0083] As an example, the execution subject may perform the following second encoding step for each lexical node value node in the lexical node value node set: first, in response to determining that the sentence vocabulary corresponding to the lexical node value node exists in a preset dictionary, assign a numerical identifier to the lexical node value node as a lexical node value encoding vector, and numerically encode each sentence vocabulary included in the preset dictionary to obtain a dictionary lexical encoding vector set. The preset dictionary may be a lexical dictionary obtained by performing word segmentation processing on a historical structured query statement. Second, in response to determining that the sentence vocabulary corresponding to the lexical node value node does not exist in the preset dictionary, and the sentence vocabulary corresponding to the lexical node value node appears in the historical structured query statement before the preceding lexical node value node distance and within the distance window, the sum of the lexical node value encoding vector corresponding to the lexical node value node, the fourth preset threshold, and the preceding lexical distance is determined as the lexical node value encoding vector. The distance window may be a maximum value of a pre-set distance from the lexical node value node. Then, in response to determining that the sentence vocabulary corresponding to the above-mentioned lexical node value node does not exist in the preset dictionary, and the sentence vocabulary corresponding to the above-mentioned lexical node value node appears in the historical structured query sentence after the post-order vocabulary distance of the lexical node value node and within the distance window, the sum of the lexical node value encoding vector corresponding to the above-mentioned lexical node value node, the above-mentioned fourth preset threshold, the distance window, and the pre-order vocabulary distance is determined as the lexical node value encoding vector. Finally, in response to determining that the sentence vocabulary corresponding to the above-mentioned lexical node value node does not exist in the preset dictionary, the lexical node value node is one-hot encoded to obtain a node value node encoding vector as the lexical node value encoding vector.
[0084] Sub-step 6: Perform word embedding processing on the above-mentioned vocabulary node type encoding vector set and the above-mentioned vocabulary node value encoding vector set, respectively, to obtain a historical vocabulary node type embedding vector set and a historical vocabulary node value embedding vector set. The historical vocabulary node type embedding vectors in the above-mentioned historical vocabulary node type embedding vector set and the historical vocabulary node value embedding vectors in the above-mentioned historical vocabulary node value embedding vector set can both be low-dimensional word vectors. The above-mentioned word embedding processing can be word embedding processing performed using the word2vec algorithm.
[0085] Sub-step 7, performing feature quantization processing on the above-mentioned historical vocabulary node type embedding vector set and the above-mentioned historical vocabulary node value embedding vector set to obtain a node type quantization feature vector set and a node value quantization feature vector set. Among them, the node type quantization feature vector in the above-mentioned node type quantization feature vector set can be a feature vector composed of a plurality of representative dimensional vectors included in the historical vocabulary node type. The node value quantization feature vector in the above-mentioned node value quantization feature vector set can be a feature vector composed of a plurality of representative dimensional vectors included in the historical vocabulary node value embedding vector. The above-mentioned representative multiple dimensional vectors can be obtained by the following steps: performing vector segmentation on the historical vocabulary node type embedding vector or the historical vocabulary node value embedding vector to obtain a segmented feature vector set, wherein each segmented feature vector includes sub-feature vectors of multiple dimensions. Then, clustering processing is performed on each segmented feature vector in the segmented feature vector set to obtain a clustered sub-feature vector set. Finally, the clustered sub-feature vector set is determined as a representative multiple dimensional vector. In practice, the above-mentioned execution entity can use the product quantization algorithm to perform feature quantization processing on the above-mentioned historical vocabulary node type embedding vector set and the above-mentioned historical vocabulary node value embedding vector set to obtain the node type quantization feature vector set and the node value quantization feature vector set.
[0086] The second step is to perform vocabulary prediction processing on the obtained node type quantized feature vector set and node value quantized feature vector set to obtain a historical vocabulary set. The vocabulary prediction processing can be performed by inputting the obtained node type quantized feature vector set and node value quantized feature vector set into a fully connected layer to perform vocabulary prediction.
[0087] Step 1025 : Determine the word position information of each predicted query word in the predicted query word set based on the historical word set to obtain a word position information set.
[0088] In some embodiments, the execution entity may determine the word position information of each predicted query word in the predicted query word set based on the historical word set to obtain a word position information set. The word position information in the word position information set may be the order in which the predicted query words are displayed on the page.
[0089] As an example, the execution entity may first perform matching processing on the predicted query vocabulary set and the historical vocabulary set to obtain a matching result set. Subsequently, at least one predicted query vocabulary and at least one historical vocabulary corresponding to at least one matching result representing a successful match are extracted from the matching result set to obtain a target predicted query vocabulary set and a target historical vocabulary set. Secondly, the ratio of the vocabulary occurrence frequency set and the total vocabulary occurrence frequency corresponding to the target historical vocabulary set is determined as the vocabulary weight value set of the target predicted query vocabulary set. Then, the target predicted query vocabulary set is sorted in descending order according to the vocabulary weight value set to obtain a target vocabulary position information set. Finally, the sorting order of the target vocabulary position information set and at least one predicted query vocabulary representing a failed match is determined as the vocabulary position information set.
[0090] Step 1026 , sorting the predicted query vocabulary set according to the vocabulary position information set to obtain a predicted query vocabulary sequence, and sending the predicted query vocabulary sequence in a paged form to the user terminal corresponding to the target user for paged display.
[0091] In some embodiments, the execution entity may sort the predicted query vocabulary set according to the vocabulary position information set to obtain a predicted query vocabulary sequence, and send the predicted query vocabulary sequence in a paged form to the user terminal corresponding to the target user for paged display.
[0092] As an example, the execution entity may sort the predicted query vocabulary set according to the sorting order of the vocabulary position information set to obtain a predicted query vocabulary sequence.
[0093] Step 1027 : In response to detecting a selection operation of the target user on the predicted query word sequence, sentence completion is performed on the structured query sentence to be completed to obtain a structured query sentence.
[0094] In some embodiments, the execution entity may, in response to detecting a selection operation by the target user on the predicted query word sequence, perform sentence completion on the structured query sentence to be completed to obtain a structured query sentence. The structured query sentence may be a structured query sentence obtained by completing the structured query sentence to be completed. The selection operation may be an operation of selecting a predicted query word from the predicted query word sequence as a complete sentence word for the input characters.
[0095] Step 1028 : In response to detecting that the target user has executed an operation on the structured query statement, generating a statement query result of the structured query statement, and sending the statement query result to the user terminal for terminal display.
[0096] In some embodiments, the execution entity may generate a statement query result for the structured query statement in response to detecting the target user's execution of the structured query statement, and transmit the statement query result to the user terminal for terminal display. The statement query result may be data obtained by filtering fields and field attribute values in the database information according to the constraints corresponding to the structured query statement.
[0097] Optionally, after generating a query result of the structured query statement in response to detecting the target user's execution operation on the structured query statement, and sending the query result to the user terminal and displaying the result on the terminal, the method may further include the following steps:
[0098] In the first step, in response to determining that the character position of the input character is the starting position, the input character is matched with each preset structured query keyword in the preset structured query keyword set to obtain a matching result set.
[0099] In the second step, in response to determining that there is a matching result indicating a successful match in the matching result set, at least one matching result indicating a successful match is determined as a target matching result set.
[0100] The third step is to determine the preset structured query keyword set corresponding to the target matching result set as the prediction candidate vocabulary set. The preset structured query keywords in the preset structured query keyword set can be keywords specified in the structured query statement.
[0101] The fourth step is to determine the candidate position information of each predicted candidate word in the predicted candidate word set based on the historical word set to obtain a candidate position information set, wherein the candidate position information in the candidate position information set may be the ranking position of the predicted candidate word in the predicted candidate word set.
[0102] As an example, the execution entity may first determine the historical vocabulary set corresponding to the predicted candidate vocabulary set as the candidate historical vocabulary set. Secondly, determine the vocabulary occurrence frequency of each candidate historical vocabulary in the candidate historical vocabulary set in the historical vocabulary set as the candidate vocabulary occurrence frequency. Subsequently, determine the sum of the candidate vocabulary occurrence frequency sets as the total frequency. Finally, determine the ratio of the occurrence frequency of each candidate vocabulary in the candidate vocabulary occurrence frequency set to the total frequency as the candidate position information, thereby obtaining the candidate position information set.
[0103] The fifth step is to sort the above-mentioned prediction candidate vocabulary set according to the above-mentioned candidate position information set to obtain a prediction candidate vocabulary sequence.
[0104] In the sixth step, the predicted candidate vocabulary sequence is sent to the user terminal for terminal display so as to provide selection operations for the target user.
[0105] Optionally, in response to determining that there is a matching result indicating a successful match in the matching result set, after determining at least one matching result indicating a successful match as a target matching result set, the method may further include the following steps:
[0106] In the first step, in response to determining that there is no matching result indicating a successful match in the matching result set, error correction is performed on the input character according to the historical vocabulary set to obtain a corrected input character.
[0107] As an example, the execution entity may first select historical words with a vocabulary frequency that is in the first preset number from the historical vocabulary set to obtain a target historical vocabulary set. The preset number may be a pre-set value. For example, the preset number may be 20. Then, the number of occurrences of each first character in the first character set corresponding to the target historical vocabulary set is determined to obtain an occurrence count set. Finally, the first character corresponding to the largest number of occurrences is selected from the occurrence count set and determined as the input character after error correction.
[0108] In the second step, the corrected input characters are matched with each preset structured query keyword in the preset structured query keyword set to obtain a keyword matching result set.
[0109] In the third step, at least one keyword matching result indicating a successful match is selected from the above keyword matching result set as a target matching result set.
[0110] Step 103 : In response to detecting the input operation of the target user, the current input character corresponding to the input operation is determined as the input character, so as to execute the query statement determination step again.
[0111] In some embodiments, the execution entity may, in response to detecting the input operation of the target user, determine the current input character corresponding to the input operation as the input character, so as to execute the query statement determination step again.
[0112] Optionally, after step 103, the execution entity may further perform the following steps:
[0113] The first step is to construct a statement metric set for the structured query statement. The statement metric set may be an indicator used to evaluate the structured query statement. For example, the statement metric set may include, but is not limited to, at least one of the following: the conformance of the structured query statement with the grammatical rules of the structured query statement, the complexity of the structured query statement, the execution efficiency of the structured query statement, the completeness of the structured query statement, and resource consumption.
[0114] The second step is to measure the structured query statement according to the statement measurement indicator set to obtain a statement measurement result, wherein the statement measurement result can represent the statement quality of the structured query statement.
[0115] As an example, the execution entity may utilize a CRITIC (Criteria Importance Though Intercrieria Correlation) algorithm to perform measurement processing on the structured query statement according to the statement measurement indicator set to obtain a measurement result.
[0116] In the third step, in response to determining that the statement measurement result is within the preset statement measurement range, the selection predicate set included in the structured query statement is one-hot encoded to obtain a selection feature vector. The selection predicate in the selection predicate set can be a predicate that represents the attribute value of a field in a data table included in the database information. For example, the structured query statement can be "the attribute value of the first field in the data table information is greater than 0." The selection predicate can be the first field in the data table information. The selection feature vector can represent the feature information of the predicate set. The preset statement measurement range can be a pre-set numerical range. For example, the preset measurement threshold can be [70, 90].
[0117] The fourth step is to perform one-hot encoding on the operator set included in the structured query statement to obtain an operator feature vector. The operators in the operator set may include: a scanning method and a join method for data table information. The scanning method may represent the scanning method of the HANA database query optimizer for data table information. For example, the scanning method may include: Sequence-Scan (data table scan) and Index-Scan (index scan). The join method may represent the method of querying multiple data table information in the query optimizer. For example, the join method may include: Hash-Join (hash join), Nest-Loop-Join (nested loop join), and Merge-Join (sort merge join). The operator feature vector may be a feature vector that represents the feature information of the operator set in a vector format.
[0118] Step 5: Encode the table connection feature set included in the structured query statement to obtain a connection feature vector. The table connection features in the table connection feature set can represent the connection relationship between the various data table information included in the data table information set. The table connection feature set can include: data table type and data table connection order. The data table type can include: left table, right table, and intermediate result table. Perform one-hot encoding on the data table type. Encode the data table connection order using a 2-bit integer. The connection feature vector can represent the characteristic information of the connection relationship between the various data table information included in the service data table information.
[0119] Step 6: Feature encoding is performed on the operator feature vectors and the connection feature vectors to obtain a table execution vector tree. The feature encoding may be performed in the form of a tree. The table execution vector tree may be a vector tree representing the execution order of the various data table information included in the structured query statement executed by the query optimizer. Each node in the table execution vector tree may be composed of an operator feature vector and a connection feature vector.
[0120] In the seventh step, the association feature vector and the selection feature vector are state-encoded to obtain a set of static information feature vectors. The static information feature vectors in the set of static information feature vectors can represent the feature information of the query association relationship and the selection predicate. In practice, the execution entity can input the association feature vector and the selection feature vector into a fully connected layer to obtain a static information feature vector.
[0121] In step 8, the table execution vector tree is serialized to obtain a table execution vector set. The table execution vectors in the table execution vector set can represent an execution order obtained by traversing the nodes of the table execution vector tree. The serialization can be performed using a post-order encoding algorithm.
[0122] In step nine, the table execution vector set is input into a table execution state representation model to obtain a dynamic information feature vector set. The table execution state representation model may be a model that captures the feature vectors of the execution order in the table execution vector set. For example, the table execution state representation model may be a Bidirectional Gated Recurrent Unit (BiGRU) model. The dynamic information feature vectors in the dynamic information feature vector set may represent the execution order of the query data table set included in the structured query statement.
[0123] In the tenth step, the dynamic information feature vector set and the static information feature vector set are concatenated to obtain a concatenated feature vector set as the table execution state vector set.
[0124] In the eleventh step, the state vector set is executed according to the table to generate an optimized structured query statement, and the query results of the optimized structured query statement are displayed. In practice, the execution entity can utilize a reinforcement learning model to execute the state vector set according to the table to generate optimized query statement information. The reinforcement learning model can be a DQN (Deep Q-Network) model or a Q-learning model.
[0125] The above-mentioned first to eleventh steps and their related contents, as an inventive point of an embodiment of the present disclosure, solve the third technical problem mentioned in the background technology, "Using a dynamic programming algorithm to optimize structured query statements, because the dynamic programming algorithm is based on various evaluation indicators discovered empirically by experts for algorithm initialization, there are great limitations, and the dynamic programming algorithm requires a large search space, which easily causes the optimized query statement to be not the optimal query statement, the acquired data accuracy is low, the query time is long, resulting in a poor user experience and a large waste of memory resources." The factors that lead to poor user experience and a large waste of computing resources are often as follows: Using a dynamic programming algorithm to optimize structured query statements, because the dynamic programming algorithm is based on various evaluation indicators discovered empirically by experts for algorithm initialization, there are great limitations, and the dynamic programming algorithm requires a large search space, which easily causes the optimized query statement to be not the optimal query statement, the acquired data accuracy is low, and the query time is long. If the above factors are solved, the effect of improving user experience and reducing the waste of computing resources can be achieved. To achieve this effect, the present invention first performs statement measurement on the completed structured query statement, which can determine the quality of the completed structured query statement and avoid optimizing the completed structured query statement with poor quality, thereby wasting computing resources. Secondly, in response to the statement measurement of the structured query statement being within the preset measurement range, the association relationship set and selection predicate set in the structured query statement are encoded, which can avoid the sparsity of the feature vector to a certain extent and reduce the waste of storage space. Then, the operator set and table connection feature set included in the structured query statement are dynamically encoded, which can accurately represent the execution order of the query optimizer on the data table information and capture the structural characteristics of the execution order of the data table information. Finally, the reinforcement learning model and the obtained table execution state vector set are used to facilitate the query optimizer to select the optimal execution order for executing the query data table set. Through the optimal execution order, the query results obtained are more accurate, the query time is shortened, the user experience is improved, and the waste of computing resources is reduced.
[0126] The above-described embodiments of the present disclosure have the following beneficial effects: the query statement generation method of some embodiments of the present disclosure can improve the accuracy of generated query statements and user query rate, thereby enhancing user experience. Specifically, the low accuracy of the generated structured query statements and the reduced user query experience are caused by the fact that the input data only includes the contextual information of the query statement to be completed, and the sequence model only learns the semantics of the input data. The learning influencing factors are too single, resulting in low accuracy of the generated query statement to be completed, thereby reducing the user query experience. Based on this, the query statement generation method of some embodiments of the present disclosure can first, in response to detecting an input operation of a target user, obtain the input characters and historical structured query statement set corresponding to the input operation. Here, the input characters and historical structured query statement set are used for subsequent prediction of a query vocabulary. Then, based on the input characters, the following query statement generation steps are performed: First, in response to determining that the character position of the input character is not the starting position, obtain the structured query statement to be completed that is located before the input character. Here, the structured query statement to be completed is used to provide context information for subsequent prediction of the query vocabulary. The second step is to extract context node type features from the structured query statement to be completed to obtain a set of predicted vocabulary node type feature vectors. Extracting context node type features can improve the accuracy of feature extraction and the quality of the predicted vocabulary node type feature vectors. The third step is to predict the query terms corresponding to the input characters based on the predicted vocabulary node type feature vector set, the input characters, and database information to obtain a predicted query vocabulary set, where the database information is the set of data tables and the set of data fields included in each data table in the database corresponding to the structured query statement to be completed. By using the predicted vocabulary node type feature vector set, the input characters, and the database information, multiple factors affecting the accuracy of the predicted query terms are considered, thereby improving the accuracy of the predicted query terms. The fourth step is to generate a historical vocabulary set based on the above-mentioned historical structured query statement set. This is used to screen the above-mentioned predicted query terms, taking into account the user habits of the target user, making the completed structured query statement more personalized. The fifth step is to determine the vocabulary position information of each predicted query term in the predicted query vocabulary set based on the above-mentioned historical vocabulary set to obtain a vocabulary position information set. Here, the predicted probability values for each predicted query term in the predicted query vocabulary set are determined, facilitating subsequent placement of predicted query terms with higher probability values at the front, thereby improving the user experience. In the sixth step, the predicted query vocabulary set is sorted based on the vocabulary position information set to obtain a predicted query vocabulary sequence. This predicted query vocabulary sequence is then sent in paginated form to the user terminal corresponding to the target user for paginated display.Here, the predicted query words with a higher prediction probability are placed in the front position and displayed in pages, so that the user can find the sentence words corresponding to the input characters in the first few positions, reducing the user operation steps and improving the user experience. The seventh step is to complete the structured query statement to be completed in response to detecting the target user's selection operation on the predicted query word sequence, and obtain a structured query statement. Here, the accuracy of the structured query statement can be improved and the workload of the target user in writing the structured query statement can be reduced. The eighth step is to generate a sentence query result of the structured query statement in response to detecting the target user's execution operation on the structured query statement, and send the sentence query result to the user terminal and display it on the terminal. Here, the execution efficiency of the structured query statement can be improved and the query time can be reduced. Finally, in response to detecting the input operation of the target user, the current input character corresponding to the input operation is determined as the input character, and the query statement determination step is performed again. Here, the completion of the structured query statement to be completed is performed through a loop execution method, which can reduce the workload of the target user in writing and improve the user experience. Therefore, the query statement generation method can improve the accuracy of the generated query statement and the user query rate, thereby improving the user experience.
[0127] Further references Figure 2 As an implementation of the methods shown in the above figures, the present disclosure provides some embodiments of a query statement generating device. These device embodiments are similar to Figure 1 Corresponding to the method embodiments shown, the query statement generating device can be specifically applied to various electronic devices.
[0128] like Figure 2As shown, a query statement generation device 200 includes: an acquisition unit 201, an execution unit 202 and a determination unit 203. The acquisition unit 201 is configured to: in response to detecting an input operation of a target user, acquire the input characters and a historical structured query statement set corresponding to the input operation. The execution unit 202 is configured to: based on the input characters, perform the following query statement generation steps: in response to determining that the character position of the input character is not the starting position, acquire the structured query statement to be completed that is located before the input character; perform context node type feature extraction on the structured query statement to be completed to obtain a predicted vocabulary node type feature vector set; predict the query vocabulary corresponding to the input character based on the predicted vocabulary node type feature vector set, the input character and the database information to obtain a predicted query vocabulary set, wherein the database information is a data table set and a data field set included in each data table of the database corresponding to the structured query statement to be completed; generate a historical vocabulary set based on the historical structured query statement set; and generate a historical vocabulary set based on the historical The method further comprises the steps of: determining a vocabulary set, determining the vocabulary position information of each predicted query vocabulary in the predicted query vocabulary set, obtaining a vocabulary position information set; sorting the predicted query vocabulary set according to the vocabulary position information set, obtaining a predicted query vocabulary sequence, and sending the predicted query vocabulary sequence in a paged form to the user terminal corresponding to the above-mentioned target user for paged display; in response to detecting the selection operation of the above-mentioned target user on the predicted query vocabulary sequence, performing sentence completion on the structured query statement to be completed, obtaining a structured query statement; in response to detecting the execution operation of the above-mentioned target user on the structured query statement, generating a sentence query result of the structured query statement, and sending the sentence query result to the above-mentioned user terminal for terminal display. The determination unit 203 is configured to: in response to detecting the input operation of the above-mentioned target user, determine the current input character corresponding to the input operation as the input character, so as to perform the above-mentioned query statement determination step again.
[0129] It is understandable that the units recorded in the query statement generating device 200 and the reference Figure 1 The steps in the described method correspond to each other. Therefore, the operations, features and beneficial effects described above for the method are also applicable to the query statement generating device 200 and the units included therein, and will not be repeated here.
[0130] Reference below Figure 3 , which shows a structural schematic diagram of an electronic device (eg, an electronic device) 300 suitable for implementing some embodiments of the present disclosure. Figure 3 The electronic device shown is only an example and should not bring any limitation to the functions and scope of use of the embodiments of the present disclosure.
[0131] like Figure 3As shown, the electronic device 300 may include a processing device (e.g., a central processing unit, a graphics processing unit, etc.) 301, which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 302 or a program loaded from a storage device 308 into a random access memory (RAM) 303. Various programs and data required for the operation of the electronic device 300 are also stored in the RAM 303. The processing device 301, the ROM 302, and the RAM 303 are connected to each other via a bus 304. An input / output (I / O) interface 305 is also connected to the bus 304.
[0132] Typically, the following devices may be connected to the I / O interface 305: an input device 306 including, for example, a touch screen, a touchpad, a keyboard, a mouse, a camera, a microphone, an accelerometer, a gyroscope, etc.; an output device 307 including, for example, a liquid crystal display (LCD), a speaker, a vibrator, etc.; a storage device 308 including, for example, a magnetic tape, a hard disk, etc.; and a communication device 309. The communication device 309 may allow the electronic device 300 to communicate with other devices wirelessly or by wire to exchange data. Figure 3 The electronic device 300 is shown with various devices, but it should be understood that it is not required to implement or possess all of the devices shown. More or fewer devices may be implemented or possessed instead. Figure 3 Each block shown in the figure may represent one device, or may represent multiple devices as needed.
[0133] In particular, according to some embodiments of the present disclosure, the processes described above with reference to the flowcharts can be implemented as computer software programs. For example, some embodiments of the present disclosure include a computer program product comprising a computer program carried on a computer-readable medium, the computer program comprising program code for executing the method shown in the flowchart. In some such embodiments, the computer program can be downloaded and installed from a network via the communication device 309, or installed from the storage device 308, or installed from the ROM 302. When the computer program is executed by the processing device 301, the above-mentioned functions defined in the method of some embodiments of the present disclosure are performed.
[0134] It should be noted that in some embodiments of the present disclosure, the computer-readable medium mentioned above may be a computer-readable signal medium or a computer-readable storage medium, or any combination of the two. The computer-readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device, or device, or any combination of the above. More specific examples of computer-readable storage media may include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In some embodiments of the present disclosure, the computer-readable storage medium may be any tangible medium containing or storing a program that can be used by or in conjunction with an instruction execution system, device, or device. In some embodiments of the present disclosure, the computer-readable signal medium may include a data signal propagated in baseband or as part of a carrier wave, which carries computer-readable program code. Such a propagated data signal may take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. A computer-readable signal medium may also be any computer-readable medium other than a computer-readable storage medium that can transmit, propagate, or transport a program for use by or in conjunction with an instruction execution system, apparatus, or device. The program code contained on the computer-readable medium may be transmitted using any suitable medium, including but not limited to wires, optical cables, RF (radio frequency), etc., or any suitable combination thereof.
[0135] In some embodiments, the client and server can communicate using any currently known or future developed network protocol, such as HTTP (Hypertext Transfer Protocol), and can be interconnected with any form or medium of digital data communication (e.g., a communication network). Examples of communication networks include a local area network ("LAN"), a wide area network ("WAN"), an internet (e.g., the Internet), and a peer-to-peer network (e.g., an ad hoc peer-to-peer network), as well as any currently known or future developed network.
[0136] The above-mentioned computer-readable medium may be included in the above-mentioned electronic device; or it may exist independently and not be assembled into the electronic device. The above-mentioned computer-readable medium carries one or more programs. When the above-mentioned one or more programs are executed by the electronic device, the electronic device: in response to detecting the input operation of the target user, obtains the input characters and historical structured query statement set corresponding to the above-mentioned input operation; based on the input characters, performs the following query statement generation steps: in response to determining that the character position of the input character is not the starting position, obtains the structured query statement to be completed that is located before the input character; performs context node type feature extraction on the structured query statement to be completed to obtain a predicted vocabulary node type feature vector set; predicts the query vocabulary corresponding to the input character based on the predicted vocabulary node type feature vector set, the input character and the database information to obtain a predicted query vocabulary set, wherein the above-mentioned database information is the data table set and the data field set included in each data table of the database corresponding to the structured query statement to be completed; generates a query statement based on the above-mentioned historical structured query statement set. a historical vocabulary set; based on the above historical vocabulary set, determining the vocabulary position information of each predicted query vocabulary in the predicted query vocabulary set to obtain a vocabulary position information set; based on the vocabulary position information set, sorting the predicted query vocabulary set to obtain a predicted query vocabulary sequence, and sending the predicted query vocabulary sequence in a paged form to the user terminal corresponding to the above target user for paged display; in response to detecting the selection operation of the above target user on the predicted query vocabulary sequence, performing sentence completion on the structured query statement to be completed to obtain a structured query statement; in response to detecting the execution operation of the above target user on the structured query statement, generating a sentence query result of the above structured query statement, and sending the above sentence query result to the above user terminal for terminal display; in response to detecting the input operation of the above target user, determining the current input character corresponding to the input operation as the input character, so as to execute the above query statement determination step again.
[0137] Computer program code for performing the operations of some embodiments of the present disclosure may be written in one or more programming languages, or a combination thereof, including object-oriented programming languages such as Java, Smalltalk, C++, and conventional procedural programming languages such as "C" or similar programming languages. The program code may be executed entirely on the user's computer, partially on the user's computer, as a stand-alone software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In cases involving a remote computer, the remote computer may be connected to the user's computer through any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computer (e.g., through the Internet using an Internet service provider).
[0138] The flowcharts and block diagrams in the accompanying drawings illustrate the possible implementation architecture, functions and operations of the systems, methods and computer program products according to various embodiments of the present disclosure. In this regard, each box in the flowchart or block diagram can represent a module, program segment, or a part of code, and the module, program segment, or a part of code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the box can also occur in a different order than that marked in the accompanying drawings. For example, two boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram and / or flowchart, and the combination of the boxes in the block diagram and / or flowchart, can be implemented with a dedicated hardware-based system that performs the specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.
[0139] The units described in some embodiments of the present disclosure may be implemented in software or in hardware. The described units may also be provided in a processor, for example, they may be described as: a processor comprising an acquisition unit, an execution unit, and a determination unit. The names of these units do not, in some cases, constitute a limitation on the units themselves. For example, the acquisition unit may also be described as "a unit that, in response to detecting an input operation of a target user, acquires input characters and a set of historical structured query statements corresponding to the above input operation."
[0140] The functions described above herein may be performed, at least in part, by one or more hardware logic components. For example, and without limitation, exemplary types of hardware logic components that may be used include: field programmable gate arrays (FPGAs), application specific integrated circuits (ASICs), application specific standard products (ASSPs), systems on chip (SOCs), complex programmable logic devices (CPLDs), and the like.
[0141] The above description is only an illustration of some preferred embodiments of the present disclosure and the technical principles used. Those skilled in the art should understand that the scope of the invention involved in the embodiments of the present disclosure is not limited to the technical solutions formed by the specific combination of the above-mentioned technical features, but should also cover other technical solutions formed by any combination of the above-mentioned technical features or their equivalent features without departing from the above-mentioned inventive concept. For example, the above-mentioned features are replaced with (but not limited to) technical features with similar functions disclosed in the embodiments of the present disclosure.
Claims
1. A method for generating a query statement, comprising: In response to detecting an input operation of a target user, obtaining input characters and a historical structured query statement set corresponding to the input operation; Based on the input characters, the following query statement generation steps are performed: In response to determining that the character position of the input character is not the starting position, obtaining a structured query statement to be completed that is located before the input character; Extracting context node type features of the structured query to be completed, and obtaining a predicted vocabulary node type feature vector set; Predicting query words corresponding to the input characters according to the predicted word node type feature vector set, the input characters and the database information to obtain a predicted query word set, wherein the database information is a data table set and a data field set included in each data table of the database corresponding to the structured query statement to be completed; Generate a historical vocabulary set according to the historical structured query statement set; Determining the vocabulary position information of each predicted query vocabulary in the predicted query vocabulary set according to the historical vocabulary set to obtain a vocabulary position information set; Sorting the predicted query vocabulary set according to the vocabulary position information set to obtain a predicted query vocabulary sequence, and sending the predicted query vocabulary sequence in a paged form to a user terminal corresponding to the target user for paged display; In response to detecting a selection operation of the target user on the predicted query vocabulary sequence, completing the structured query sentence to be completed to obtain a structured query sentence; In response to detecting that the target user performs an execution operation on the structured query statement, generating a statement query result of the structured query statement, and sending the statement query result to the user terminal for terminal display; In response to detecting the input operation of the target user, a current input character corresponding to the input operation is determined as the input character, so as to execute the query statement generating step again.
2. The method according to claim 1, wherein: After generating a statement query result of the structured query statement in response to detecting that the target user has executed an operation on the structured query statement, and sending the statement query result to the user terminal and displaying the result on the terminal, the method further includes: In response to determining that the character position of the input character is the starting position, matching the input character with each preset structured query keyword in the preset structured query keyword set to obtain a matching result set; In response to determining that there is a matching result indicating a successful match in the matching result set, determining at least one matching result indicating a successful match as a target matching result set; Determining a preset structured query keyword set corresponding to the target matching result set as a prediction candidate vocabulary set; Determining candidate position information of each predicted candidate word in the predicted candidate word set according to the historical word set to obtain a candidate position information set; According to the candidate position information set, the predicted candidate vocabulary set is sorted to obtain a predicted candidate vocabulary sequence; The predicted candidate vocabulary sequence is sent to the user terminal for terminal display so as to provide selection operation for the target user.
3. The method according to claim 2, after determining that there is a matching result indicating a successful match in the matching result set, determining at least one matching result indicating a successful match as a target matching result set, the method further comprises: In response to determining that there is no matching result indicating a successful match in the matching result set, performing error correction processing on the input character according to the historical vocabulary set to obtain a corrected input character; Matching the corrected input character with each preset structured query keyword in the preset structured query keyword set to obtain a keyword matching result set; At least one keyword matching result indicating a successful match is selected from the keyword matching result set as a target matching result set.
4. The method according to claim 1, wherein: The context node type feature extraction is performed on the structured query sentence to be completed to obtain a predicted vocabulary node type feature vector set, including: Embedding a vocabulary node type node set and a vocabulary node value node set included in an abstract syntax tree corresponding to the structured query statement to be completed to obtain a vocabulary node type embedding vector set and a vocabulary node value embedding vector set; Concatenating the vocabulary node type embedding vector set and the vocabulary node value embedding vector set to obtain a vocabulary node concatenated embedding vector set; Inputting the vocabulary node concatenated embedding vector set into a forward sentence completion network to obtain a forward vocabulary node feature vector set; Inputting the forward vocabulary node feature vector set into a backward sentence completion network to obtain a backward vocabulary node feature vector set; Performing feature concatenation on the backward vocabulary node feature vector set and the forward vocabulary node feature vector set to obtain a context feature vector set for the input character; Inputting the backward vocabulary node feature vector set and the context feature vector set into a context attention mechanism layer to obtain a vocabulary context feature vector set; Performing feature concatenation on the vocabulary node type embedding vector of the parent node of the input character, the vocabulary context feature vector set, and the backward vocabulary node feature vector set to obtain a vocabulary node concatenation feature vector set; The vocabulary node type is predicted for the vocabulary node concatenation feature vector set to obtain a predicted vocabulary node type feature vector set.
5. The method according to claim 4, wherein: The method predicts the query vocabulary corresponding to the input character according to the predicted vocabulary node type feature vector set, the input character and the database information to obtain the predicted query vocabulary set, including: Performing feature splicing processing on the backward vocabulary node feature vector set and the vocabulary context feature vector set to obtain a spliced vocabulary node feature vector set; Performing pointer prediction on the concatenated vocabulary node feature vector set to obtain a vocabulary pointer feature vector; Performing feature multiplication processing on the predicted vocabulary node type feature vector set and the vocabulary pointer feature vector to obtain a first feature vector to be predicted; Determine a feature difference between a preset vocabulary feature vector and the vocabulary pointer feature vector to obtain a difference vocabulary pointer feature vector; Performing feature multiplication processing on the vocabulary node weight feature vector set and the difference vocabulary pointer feature vector to obtain a second feature vector to be predicted; Concatenate the first feature vector to be predicted and the second feature vector to be predicted to obtain a feature vector of a node value to be predicted; Performing vocabulary prediction processing on the feature vector of the node value to be predicted to obtain a vocabulary set to be predicted; The to-be-predicted vocabulary set is screened according to the input characters and the database information to obtain a predicted query vocabulary set.
6. The method according to claim 1, wherein: Generating a historical vocabulary set according to the historical structured query statement set includes: For each historical structured query statement in the historical structured query statement set, the following feature quantification steps are performed: Constructing an abstract syntax tree for the historical structured query statement to obtain an abstract syntax tree for the historical statement; Performing pre-order serialization on the historical sentence abstract syntax tree to obtain a historical sentence vocabulary node sequence; Classifying the historical sentence lexical node sequence to obtain a lexical node type node set and a lexical node value node set; Performing node type encoding processing on each lexical node type node in the lexical node type node set to generate a lexical node type encoding vector, thereby obtaining a lexical node type encoding vector set; Performing node value encoding processing on each lexical node value node in the lexical node value node set to generate a lexical node value encoding vector, thereby obtaining a lexical node value encoding vector set; Performing word embedding processing on the vocabulary node type encoding vector set and the vocabulary node value encoding vector set respectively to obtain a historical vocabulary node type embedding vector set and a historical vocabulary node value embedding vector set; Performing feature vector processing on the historical vocabulary node type embedding vector set and the historical vocabulary node value embedding vector set to obtain a node type quantized feature vector set and a node value quantized feature vector set; The obtained node type quantized feature vector set and node value quantized feature vector set are subjected to vocabulary prediction processing to obtain a historical vocabulary set.
7. A query statement generating device, comprising: an acquisition unit, configured to, in response to detecting an input operation of a target user, acquire input characters and a historical structured query statement set corresponding to the input operation; The execution unit is configured to execute the following query statement generation steps based on the input character: in response to determining that the character position of the input character is not the starting position, obtaining the structured query statement to be completed that is located before the input character; extracting the context node type feature of the structured query statement to be completed to obtain a predicted vocabulary node type feature vector set; predicting the query vocabulary corresponding to the input character according to the predicted vocabulary node type feature vector set, the input character and the database information to obtain a predicted query vocabulary set, wherein the database information is a data table set and a data field set included in each data table of the database corresponding to the structured query statement to be completed; generating a historical vocabulary set according to the historical structured query statement set; and generating a historical vocabulary set according to the historical vocabulary set. Gathering, determining the vocabulary position information of each predicted query word in the predicted query vocabulary set, and obtaining the vocabulary position information set; sorting the predicted query vocabulary set according to the vocabulary position information set, obtaining a predicted query vocabulary sequence, and sending the predicted query vocabulary sequence in a paged form to the user terminal corresponding to the target user for paged display; in response to detecting the target user's selection operation on the predicted query vocabulary sequence, completing the structured query statement to be completed, and obtaining a structured query statement; in response to detecting the target user's execution operation on the structured query statement, generating a statement query result of the structured query statement, and sending the statement query result to the user terminal for terminal display; The determination unit is configured to, in response to detecting an input operation of the target user, determine a current input character corresponding to the input operation as the input character, so as to execute the query statement generation step again.
8. An electronic device comprising: one or more processors; a storage device having one or more programs stored thereon, When the one or more programs are executed by the one or more processors, the one or more processors implement the method according to any one of claims 1 to 6.
9. A computer readable medium having a computer program stored thereon, wherein: When the computer program is executed by a processor, the method according to any one of claims 1 to 6 is implemented.
Citation Information
Patent Citations
Query method and device, electronic equipment and storage medium
CN117633004A
Data query method and device, computer equipment and storage medium
CN117931858A