SQL statement generation method and device based on relationship perception

By constructing the structural diagram of the problem words and the database mode, using the diagram of the diagram and neural network of the relationship between the relationship to generate the SQL statement method, solve the problem of insufficient expression ability and accuracy of SQL statement in existing technology. Realize the conversion of more efficient natural language to SQL.

CN117493372BActive Publication Date: 2025-01-28CHINA STATE SHIPBUILDING CORP LTD RESEARCH INSTITUTE 719
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202311549842.8
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-11-17
Publication Date
2025-01-28
Estimated Expiration
2043-11-17

AI Technical Summary

Technical Problem

In the prior art, the expression ability of SQL statements generated is insufficient, the accuracy rate is not high, and it is difficult to effectively convert natural language problems into SQL statements executable by machines.

Method used

By constructing problem words and database mode structure diagrams, fusion to generate problem words pattern diagrams, and use the diagram convolutional network and neural network with related perception to extract the characteristic information of the target node, and then generate the abstract syntax tree of SQL. Target SQL statement.

Benefits of technology

Enhance the expression ability of natural language problems and database mode, improve the accuracy of generating SQL statements, and can more effectively convert natural language issues to correct SQL queries.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN117493372B_ABST
    Figure CN117493372B_ABST
Patent Text Reader

Abstract

The present invention provides a method and device for generating SQL statements based on relationship perception, wherein the method comprises: obtaining a problem word pattern diagram based on a problem word structure diagram and a database pattern structure diagram; obtaining target node feature information based on the problem word pattern diagram, a graph convolution network with relationship perception and a neural network with relationship perception; generating an abstract syntax tree of SQL based on a decoder and the target node feature information, and outputting a target SQL statement by traversing the abstract syntax tree of SQL according to depth; wherein the problem word structure diagram is obtained based on the problem words obtained after word segmentation processing of a target natural language question; and the database pattern structure diagram is obtained based on the pattern information of the database. Thus, the expressive power of the problem and the database pattern is improved, and the accuracy of generating SQL statements is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of natural language processing, and in particular to a method and device for generating SQL statements based on relationship perception. Background Art

[0002] With the popularization of electronic devices, databases have become the main tool for storing information. Relational databases use relational models to organize data. They store data in the form of rows and columns. This series of rows and columns is called a table. Tables have become the mainstream way to store large structured data of resources. Users can query the information stored in the table through Structured Query Language (SQL).

[0003] Structured Query Language (SQL) statements have strict syntax constraints and a high threshold for use. Although database professionals can write SQL statements to effectively access table contents, it is difficult for non-professionals to write correct SQL query statements. Therefore, in order to improve the efficiency of database information retrieval and lower the user's threshold, the research on converting natural language questions into machine-executable SQL statements has attracted widespread attention from industry and academia. The task of generating corresponding SQL statements from natural language questions is called Text-to-SQL task.

[0004] The Text-to-SQL task allows non-professional users to easily query the content of the database, and has a wide range of needs and research value in practical applications, such as intelligent question-answering services, voice assistants, and robot navigation. The questions raised by users are automatically converted into SQL statements, and the query is executed in the background database to obtain accurate search results, and the search results are returned to the user. By automatically generating SQL statements from natural language questions and executing them to obtain search results, labor costs can be greatly reduced.

[0005] In the process of generating SQL based on natural language questions in the prior art, an encoder-decoder architecture designed based on deep learning is often used. The encoder encodes the natural language question and the known database schema information, and by constructing the relationship information between the natural language question and the database schema, the relationship information is added to the encoder for encoding to capture the feature information of the natural language question and the database schema; the decoder decodes the feature information generated by the encoder, generates an abstract syntax tree of the SQL statement according to the step sequence prediction, and then converts the abstract syntax tree into the corresponding SQL statement.

[0006] This method lacks expressiveness and the accuracy of the generated SQL statements is not high. Summary of the invention

[0007] In view of the problems existing in the related technology, the present invention provides a method and device for generating SQL statements based on relationship perception, so as to solve the defects of insufficient expression ability and low accuracy of generated SQL statements in the prior art, thereby improving the expression ability of problems and database models and improving the accuracy of generated SQL statements.

[0008] The present invention provides a method for generating SQL statements based on relationship perception, comprising:

[0009] Based on the problem word structure diagram and the database model structure diagram, a problem word model diagram is obtained;

[0010] Based on the problem word pattern graph, the relationship-aware graph convolutional network, and the relationship-aware neural network, characteristic information of the target node is obtained;

[0011] Generate an abstract syntax tree of SQL based on the decoder and the target node feature information, and traverse the abstract syntax tree of SQL according to the depth to output the target SQL statement;

[0012] The question word structure diagram is obtained based on the question words obtained after word segmentation processing of the target natural language question; and the database model structure diagram is obtained based on the model information of the database.

[0013] According to a method for generating SQL statements based on relationship perception provided by the present invention, the problem word pattern diagram is obtained based on the problem word structure diagram and the database pattern structure diagram, specifically including:

[0014] Respectively determining an explicit matching relationship and an implicit matching relationship between a question word node in the question word structure diagram and a table column name node in the database model structure diagram;

[0015] Based on the explicit matching relationship and the implicit matching relationship, the question word structure diagram and the database model structure diagram are connected to obtain the question word model diagram.

[0016] According to a method for generating SQL statements based on relationship perception provided by the present invention, the target node feature information is obtained based on the problem word pattern graph, the graph convolution network with relationship perception and the neural network with relationship perception, specifically including:

[0017] Inputting the problem word pattern graph into a graph convolutional network with relationship awareness to obtain first node feature information;

[0018] Calculating the attention weights of the table column name node and the question word node, and determining the probability value of the table column name node being mentioned by the target natural language question based on the attention weights;

[0019] Based on the probability value, updating the characteristic information of the table column name node to obtain second node characteristic information;

[0020] The second node feature information is input into a neural network with relationship perception to obtain target node feature information.

[0021] According to a method for generating SQL statements based on relational awareness provided by the present invention, the abstract syntax tree of SQL is generated based on the decoder and the target node feature information, specifically comprising:

[0022] Encoding the target node feature information and the previous action of the decoder into the decoder, and the next action of the decoder;

[0023] Generate the SQL abstract syntax tree according to the next action of the decoder.

[0024] According to a relationship-aware SQL statement generation method provided by the present invention, determining the implicit matching relationship between the question word node in the question word structure diagram and the table column name node in the database schema structure diagram specifically includes:

[0025] The inference knowledge graph is used to capture the implicit matching relationship between the question word nodes in the question word structure graph and the table column name nodes in the database model structure graph.

[0026] According to a method for generating SQL statements based on relationship perception provided by the present invention, the generation method of the problem word structure diagram includes:

[0027] Using a Chinese word segmentation tool, the target natural language question is segmented to obtain the question words;

[0028] Obtain the dependency relationship between the problem words through a dependency parsing tool;

[0029] The problem words are taken as nodes and the dependency relationships are taken as edges to generate the problem word structure graph.

[0030] The present invention also provides a SQL statement generation device based on relationship perception, comprising:

[0031] A structure diagram module obtains a problem word pattern diagram based on the problem word structure diagram and the database pattern structure diagram;

[0032] A feature module, which obtains target node feature information based on the problem word pattern graph, the relationship-aware graph convolutional network, and the relationship-aware neural network;

[0033] A statement module generates an abstract syntax tree of SQL based on the decoder and the target node feature information, and traverses the abstract syntax tree of SQL according to depth to output a target SQL statement;

[0034] The question word structure diagram is obtained by performing word segmentation processing on the target natural language question to obtain question words and obtain the dependency relationship between the question words; the database model structure diagram is obtained based on the model information of the database.

[0035] The present invention also provides an electronic device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the program, the method for generating SQL statements based on relationship perception as described above is implemented.

[0036] The present invention also provides a non-transitory computer-readable storage medium having a computer program stored thereon, and when the computer program is executed by a processor, the method for generating SQL statements based on relationship awareness as described in any one of the above is implemented.

[0037] The present invention also provides a computer program product, including a computer program, wherein when the computer program is executed by a processor, the method for generating SQL statements based on relationship awareness as described above is implemented.

[0038] The relationship-aware SQL statement generation method and device provided by the present invention obtain problem words by performing word segmentation processing on the target natural language problem, and generate a problem word structure diagram, fuse the problem word structure diagram and the database model structure diagram to obtain a problem word model diagram, and then pass the problem word model diagram through a graph convolution network with relationship awareness and a neural network with relationship awareness to obtain target node feature information, and then decode and generate an abstract syntax tree of SQL, and deeply traverse to obtain the target SQL statement, which fully considers the structural information of the target natural language problem and fully integrates it with the database structure information, thereby enhancing the expression ability of natural language problems and database models, and can generate more accurate SQL statements. BRIEF DESCRIPTION OF THE DRAWINGS

[0039] In order to more clearly illustrate the technical solutions in the present invention or the prior art, the following briefly introduces the drawings required for use in the embodiments or the description of the prior art. Obviously, the drawings described below are some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.

[0040] Figure 1 A schematic diagram of the process of generating a SQL statement based on relationship perception provided by the present invention;

[0041] Figure 2 A schematic diagram of an embodiment of the present invention;

[0042] Figure 3 A schematic diagram of the structure of a SQL statement generation device based on relationship perception provided by the present invention;

[0043] Figure 4 This is a schematic structural diagram of an electronic device provided by the present invention. DETAILED DESCRIPTION

[0044] In order to make the purpose, technical solution and advantages of the present invention clearer, the technical solution of the present invention will be clearly and completely described below in conjunction with the drawings of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.

[0045] The existing methods for generating SQL based on natural language questions have the following shortcomings:

[0046] 1) Existing methods are basically based on encoder-decoder implementation. The encoder part uses the modeling structure information of the question and the database schema to enhance its representation ability, and finally obtains the characteristic information of the natural language question and the database schema. The modeling structure information is roughly divided into three parts: the connection structure between the natural language question and the database schema, the internal structure of the database schema, and the natural language question structure. Existing methods focus the modeling structure information mainly on the connection structure and the internal structure of the database, while ignoring the structure of the natural language question;

[0047] 2) In practical applications, there are many tables and columns in the database. Existing methods will become more difficult to encode methods and select appropriate tables or columns when predicting and generating SQL statements in large-scale databases.

[0048] 3) Some studies have found that the robustness of existing methods is poor. When natural language questions or database table names and column names are disturbed, the performance of the methods will be seriously affected.

[0049] In view of the above problems, the present invention provides a method and device for generating SQL statements based on relationship perception.

[0050] Figure 1 A flow chart of the SQL statement generation method based on relationship perception provided by the present invention is shown as follows: Figure 1 As shown, the method comprises the following steps:

[0051] Step 100: Based on the question word structure diagram and the database model structure diagram, a question word model diagram is obtained.

[0052] Step 101: Based on the question word pattern graph, the relationship-aware graph convolutional network, and the relationship-aware neural network, the target node feature information is obtained.

[0053] Step 102: Generate an abstract syntax tree of SQL based on the decoder and target node feature information, and traverse the abstract syntax tree of SQL according to depth to output a target SQL statement.

[0054] Among them, the question word structure diagram is obtained based on the question words obtained after word segmentation processing of the target natural language question; the database model structure diagram is obtained based on the model information of the database.

[0055] Specifically, the target natural language question refers to a natural language question that needs to be converted into an SQL statement, and the target SQL statement is the SQL statement converted by the target natural language question according to the SQL statement generation method provided by the present invention.

[0056] Since the prior art mainly focuses on the link relationship information between the natural language question and the database model and the relationship information within the database model during the encoding process, but ignores the structural relationship information within the natural language question, in an embodiment of the present invention, it is first necessary to perform word segmentation processing on the target natural language question to obtain question words, and then obtain a question word structure diagram based on the question words, which can fully consider the structural information of the natural language question.

[0057] Optionally, the question word structure diagram is generated in the following manner:

[0058] Use the Chinese word segmentation tool to segment the target natural language question and obtain the question words;

[0059] Obtain the dependency relationship between question words through dependency parsing tools;

[0060] The problem words are taken as nodes and the dependency relationships are taken as edges to generate a problem word structure graph.

[0061] Specifically, in the process of generating the problem word structure diagram, the target natural language problem can first be segmented by a Chinese word segmentation tool to obtain the problem words. The Chinese word segmentation tool in the embodiment of the present invention can be Jieba, SnowNLP, LTP, HanNLP, etc., and the present invention does not limit the type of the Chinese word segmentation tool.

[0062] After obtaining the problem words, the dependency relationship between the problem words can be obtained through a dependency parsing tool. Dependency parsing is to represent the structure of a sentence through the relationship between a certain word and other words, showing which words depend on which other words. The present invention does not limit the type of dependency parsing tool.

[0063] After obtaining the dependency relationships between the problem words, the problem words can be used as nodes and the dependency relationships as edges to generate a problem word structure graph.

[0064] The embodiment of the present invention also needs to obtain a database schema structure diagram based on the database schema information, wherein the table column names (i.e., table names and column names, this concept is consistent throughout the text and will not be repeated hereafter) in the database schema information are used as nodes, and the subordinate relationships between tables and columns and the primary key and foreign key relationships are used as edges to generate the database schema structure diagram.

[0065] After respectively generating the problem word structure diagram and the database pattern diagram, the problem word structure diagram and the database pattern structure diagram can be merged to analyze the connection relationship between each node in the problem word structure diagram and each node in the database pattern structure diagram, thereby obtaining the problem word pattern diagram.

[0066] After obtaining the problem word pattern graph, the feature information of each node in the problem word pattern graph, that is, the target node feature information, can be obtained based on the problem word pattern graph, the relationship-aware graph convolutional network, and the relationship-aware neural network.

[0067] In one implementation, the question word pattern graph may be sequentially passed through a graph convolutional network with relationship awareness and a neural network with relationship awareness to obtain target node feature information.

[0068] Among them, the graph convolutional network with relationship awareness in the embodiment of the present invention can be a relational graph convolutional network (R-GCN), and the neural network with relationship awareness can be a relation-aware transformer neural network (RAT).

[0069] After obtaining the target node feature information, the target node feature information can be decoded by a decoder to generate an abstract syntax tree of SQL, and finally the abstract syntax tree of SQL is traversed by depth to output the target SQL statement.

[0070] The relationship-aware SQL statement generation method provided by the present invention obtains problem words by performing word segmentation processing on the target natural language problem, and generates a problem word structure graph, merges the problem word structure graph and the database model structure graph to obtain a problem word model graph, and then passes the problem word model graph through a graph convolution network with relationship awareness and a neural network with relationship awareness to obtain target node feature information, and then decodes and generates an abstract syntax tree of SQL, and deeply traverses to obtain the target SQL statement, which fully considers the structural information of the target natural language problem and fully merges it with the database structure information, thereby enhancing the expression ability of natural language problems and database models, and can generate more accurate SQL statements.

[0071] According to a method for generating SQL statements based on relationship perception provided by the present invention, a problem word pattern diagram is obtained based on a problem word structure diagram and a database pattern structure diagram, which specifically includes:

[0072] Determine the explicit matching relationship and the implicit matching relationship between the question word node in the question word structure diagram and the table column name node in the database model structure diagram respectively;

[0073] Based on the explicit matching relationship and the implicit matching relationship, the question word structure diagram and the database model structure diagram are connected to obtain the question word model diagram.

[0074] Specifically, in the process of obtaining the question word pattern diagram based on the question word structure diagram and the database pattern structure diagram, we can first determine the explicit matching relationship between the question word nodes in the question word structure diagram and the table column name nodes in the database pattern structure diagram. In some implementations, we can use the n-gram method to calculate the matching probability between the question words and the table column names, thereby determining the explicit matching relationship between the question word nodes and the table column name nodes.

[0075] It is also possible to determine the implicit matching relationship between the question word node in the question word structure diagram and the table column name node in the database schema structure diagram. In some implementations, the reasoning knowledge graph can be used to infer unknown facts or relationships based on existing facts or relationships in the knowledge graph, thereby capturing the implicit matching relationship between the question word node in the question word structure diagram and the table column name node in the database schema structure diagram, and determining the implicit matching relationship between the question word node and the table column name node, such as synonyms, synonyms, etc.

[0076] The embodiment of the present invention takes into account implicit matching relationships, which can better ensure the relationship between questions and database patterns, making it less likely for the algorithm to lose relationships between synonyms, thereby enhancing the robustness of the model.

[0077] According to a method for generating SQL statements based on relationship perception provided by the present invention, target node feature information is obtained based on a problem word pattern graph, a graph convolutional network with relationship perception, and a neural network with relationship perception, specifically including:

[0078] Input the question word pattern graph into the relationship-aware graph convolutional network to obtain the first node feature information;

[0079] Calculate the attention weights of the table column name node and the question word node, and determine the probability value of the table column name node being mentioned by the target natural language question based on the attention weights;

[0080] Based on the probability value, update the characteristic information of the table column name node to obtain the second node characteristic information;

[0081] The second node feature information is input into a neural network with relationship perception to obtain the target node feature information.

[0082] Specifically, in the process of obtaining the target node feature information based on the question word pattern graph, the relationship-aware graph convolutional network and the relationship-aware neural network, the question word pattern graph can be first input into the relationship-aware graph convolutional network, such as R-GCN. For any node, the feature information of the node can be obtained through the information of the nodes adjacent to it and the information of each edge of the node (that is, the relationship between the node and other nodes), thereby obtaining the first node feature information of the entire question word pattern graph.

[0083] Suppose the problem word node vector set q i The feature vector representing the i-th question word node, the database pattern node vector set s j The feature vector representing the jth database schema node, i.e., the feature vector of the table column name node;

[0084] Then the question word pattern graph is input into the n-layer relation-aware graph convolutional network R-GCN, and the specific update formula for the first node feature information is obtained as follows:

[0085]

[0086] in, represents the feature information of the i-th node in the graph of the (l+1)th layer, r represents the edge relationship in the graph, and R represents the set of all possible edge relationships. represents the set of nodes with relationship r pointing to the i-th node, c i,r yes The number of nodes in the and is the trainable parameter matrix and σ is the activation function (ReLU).

[0087] Then, the attention weights of each column name node and each question word node in the question word pattern graph can be calculated, that is, whether the edge between each column name node and each question word node is noticed, so as to find the probability value of each column name node being mentioned by the target natural language question. The specific calculation formula is as follows:

[0088] e ij =q i W Q (s j W k +r ij ) T

[0089]

[0090]

[0091]

[0092]

[0093] Among them, q i Represents the feature vector of the i-th question word node, s j represents the feature vector of the jth database schema node, that is, the feature vector of the table column name node, α n*m represents the attention weights of the question word node and the table column name node, W Q , W k is the trainable weight matrix, r ij is the relationship vector between the i-th question word node and the j-th database pattern node, u j As the maximum probability that the jth node in the database pattern node vector set S is mentioned by the target natural language question, represents the normalized maximum probability.

[0094] A high probability value indicates a high probability of occurrence, and a low probability value indicates a low probability of occurrence. Therefore, after obtaining the probability value of each column name node being mentioned by the target natural language question, the feature information of the column name node can be updated according to the probability value. During the update process, the expression ability of the column name node with a high probability of occurrence is enhanced, and the expression ability of the column name node with a low probability of occurrence is weakened, and finally the second node feature information is obtained. The specific calculation formula is as follows:

[0095]

[0096] in, Indicates the second node feature information obtained after updating.

[0097] After obtaining the second node feature information, the second node feature information can be input into a neural network with relationship perception, such as RAT, to make full use of the information of the edges between each node (that is, the relationship between each node) to further update the node feature information, and finally obtain the target node feature information. The specific update formula is as follows:

[0098]

[0099]

[0100]

[0101]

[0102]

[0103]

[0104] Among them, x i and x j represents the feature information of the second node, H is the number of heads of multi-head attention, represents the attention weights of the i-th node and the j-th node of the h-th head, represents the trainable weight matrix of the h-th head, r ij is the relationship vector between the i-th node and the j-th node, d z is the dimension of the feature vector, is the feature information of the i-th node after the h-th head updates, z i It is to concatenate the feature information of H heads into a dimension of d z The eigenvector of i It represents the feature information finally obtained by the i-th node, LayerNorm(·) is the layer normalization method, FC(·) represents the fully connected layer, and ReLU(·) represents the activation function.

[0105] Therefore, when there are a large number of table columns in the database, the probability of selecting the correct table column when decoding and generating the SQL statement can be improved.

[0106] According to a method for generating SQL statements based on relational awareness provided by the present invention, an abstract syntax tree of SQL is generated based on a decoder and target node feature information, specifically comprising:

[0107] The target node feature information and the decoder's previous action code are input into the decoder to obtain the decoder's next action;

[0108] Generate the SQL abstract syntax tree according to the next action of the decoder.

[0109] Specifically, in the process of decoding the target node feature information through the decoder to generate the abstract syntax tree of SQL, the target node feature information and the decoder's previous action encoding can be input into the decoder, and the decoder can predict the next execution action, which can be a table selection action, a column selection action, and an application of predefined SQL rule actions, etc.

[0110] Therefore, the decoder can perform decoding processing according to the action of the previous step and the feature information of the target node, and predict and generate the next action. Each action is actually building the abstract syntax tree of SQL. When the decoder prediction is completed, it means that the abstract syntax tree of SQL is completed, thus obtaining the abstract syntax tree of SQL.

[0111] The following further illustrates the SQL statement generation method based on relationship perception provided by the present invention through embodiments in specific application scenarios.

[0112] Figure 2 The schematic diagram of the embodiment provided by the present invention is as follows: Figure 2 As shown, this embodiment specifically includes the following steps:

[0113] (1) Use Chinese word segmentation tools to segment natural language questions and obtain segmented question words;

[0114] (2) Using dependency parsing tools, we can obtain the dependency relationships between question words, with words as nodes and dependency relationships as edges, to obtain a question structure graph (i.e., question word structure graph);

[0115] (3) Based on the database schema information, the table name / column name is used as a node, and the subordinate relationship between the table and the column, the primary key and foreign key relationship, etc. are used as edges to obtain a database schema structure diagram;

[0116] (4) The explicit matching relationship between question words and table names / column names is calculated using the n-gram method, and the implicit matching relationship between question words and table names / column names is captured using the inference knowledge graph. The question structure graph and the database schema structure graph are linked into one graph through the matching relationship: the question-schema graph (i.e., question word schema graph);

[0117] (5) Input the question-pattern graph into the relationship-aware graph convolutional network (R-GCN layer), and use the information of neighbor nodes and relationship (edge) information to update the node feature information to obtain preliminary node feature information;

[0118] (6) Calculate the attention weights of table / column nodes and question word nodes, find the probability that the table / column node is mentioned in the question, and update the feature information of the table / column node based on the probability to weaken the expressive power of the table / column that will not appear;

[0119] (7) Input the updated node information into the relationship-aware neural network (RAT layer), make full use of the relationship (edge) information to update the node feature information, and obtain the final feature information;

[0120] (8) The feature information of the node is used as part of the decoder input. The decoder predicts and generates the next action according to the action of the previous step and the feature information of the node, such as selecting a table action, selecting a column action, and applying a predefined SQL rule action, and finally generates an abstract syntax tree of SQL;

[0121] (9) Traverse the abstract syntax tree of SQL in depth and output the generated SQL.

[0122] Through the above steps, this embodiment can generate corresponding SQL statements from the natural language questions input by the user, use SQL to query the database, and then obtain the content required by the user.

[0123] The method provided by the present invention has been verified in some application scenarios, such as providing intelligent question-and-answer services in a two-loop system. Users query relevant content in the database through natural language questions, assemble data for users and return relevant answers, such as querying related basic information of files based on tags, etc., which improves information retrieval efficiency.

[0124] The following is a description of the SQL statement generation device based on relationship perception provided by the present invention. The SQL statement generation device based on relationship perception described below and the SQL statement generation method based on relationship perception described above can refer to each other.

[0125] Figure 3 A schematic diagram of the structure of the SQL statement generation device based on relationship perception provided by the present invention, such as Figure 3 As shown, the device comprises:

[0126] A structure diagram module 300 obtains a problem word pattern diagram based on the problem word structure diagram and the database pattern structure diagram;

[0127] The feature module 310 obtains target node feature information based on the question word pattern graph, the relationship-aware graph convolutional network, and the relationship-aware neural network;

[0128] The statement module 320 generates an abstract syntax tree of SQL based on the decoder and target node feature information, and traverses the abstract syntax tree of SQL according to depth to output the target SQL statement;

[0129] Among them, the question word structure diagram is obtained by performing word segmentation processing on the target natural language question, obtaining question words, and obtaining the dependency relationship between the question words; the database model structure diagram is obtained based on the model information of the database.

[0130] According to a relationship-aware SQL statement generation device provided by the present invention, a problem word pattern diagram is obtained based on a problem word structure diagram and a database pattern structure diagram, specifically including:

[0131] Determine the explicit matching relationship and the implicit matching relationship between the question word node in the question word structure diagram and the table column name node in the database model structure diagram respectively;

[0132] Based on the explicit matching relationship and the implicit matching relationship, the question word structure diagram and the database model structure diagram are connected to obtain the question word model diagram.

[0133] According to a relationship-aware SQL statement generation device provided by the present invention, target node feature information is obtained based on a problem word pattern graph, a relationship-aware graph convolutional network, and a relationship-aware neural network, specifically including:

[0134] Input the question word pattern graph into the relationship-aware graph convolutional network to obtain the first node feature information;

[0135] Calculate the attention weights of the table column name node and the question word node, and determine the probability value of the table column name node being mentioned by the target natural language question based on the attention weights;

[0136] Based on the probability value, update the characteristic information of the table column name node to obtain the second node characteristic information;

[0137] The second node feature information is input into a neural network with relationship perception to obtain the target node feature information.

[0138] According to a relation-aware SQL statement generation device provided by the present invention, an abstract syntax tree of SQL is generated based on a decoder and target node feature information, specifically comprising:

[0139] The target node feature information and the decoder's previous action code are input into the decoder to obtain the decoder's next action;

[0140] Generate the SQL abstract syntax tree according to the next action of the decoder.

[0141] According to a relationship-aware SQL statement generation device provided by the present invention, determining the implicit matching relationship between the question word node in the question word structure diagram and the table column name node in the database model structure diagram specifically includes:

[0142] The inference knowledge graph is used to capture the implicit matching relationship between the question word nodes in the question word structure graph and the table column name nodes in the database schema structure graph.

[0143] According to a SQL statement generation device based on relationship perception provided by the present invention, the generation method of the problem word structure diagram includes:

[0144] Use the Chinese word segmentation tool to segment the target natural language question and obtain the question words;

[0145] Obtain the dependency relationship between question words through dependency parsing tools;

[0146] The problem words are taken as nodes and the dependency relationships are taken as edges to generate a problem word structure graph.

[0147] Figure 4 A schematic diagram of the structure of an electronic device provided by the present invention, such as Figure 4 As shown, the electronic device may include: a processor 410, a communication interface 420, a memory 430 and a communication bus 440, wherein the processor 410, the communication interface 420 and the memory 430 communicate with each other through the communication bus 440. The processor 410 may call the logic instructions in the memory 430 to execute the SQL statement generation method based on relationship perception provided by the above methods, and the method includes:

[0148] Based on the problem word structure diagram and the database model structure diagram, a problem word model diagram is obtained;

[0149] Based on the question word pattern graph, the relationship-aware graph convolutional network, and the relationship-aware neural network, the target node feature information is obtained;

[0150] Generate an abstract syntax tree of SQL based on the decoder and target node feature information, and traverse the abstract syntax tree of SQL according to depth to output the target SQL statement;

[0151] Among them, the question word structure diagram is obtained based on the question words obtained after word segmentation processing of the target natural language question; the database model structure diagram is obtained based on the model information of the database.

[0152] In addition, the logic instructions in the above-mentioned memory 430 can be implemented in the form of a software functional unit and can be stored in a computer-readable storage medium when it is sold or used as an independent product. Based on such an understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art or the part of the technical solution, can be embodied in the form of a software product, and the computer software product is stored in a storage medium, including a number of instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present invention. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), disk or optical disk and other media that can store program codes.

[0153] On the other hand, the present invention further provides a computer program product, the computer program product comprising a computer program, the computer program can be stored in a non-transitory computer-readable storage medium, when the computer program is executed by a processor, the computer can execute the relationship-aware SQL statement generation method provided by the above methods, the method comprising:

[0154] Based on the problem word structure diagram and the database model structure diagram, a problem word model diagram is obtained;

[0155] Based on the question word pattern graph, the relationship-aware graph convolutional network, and the relationship-aware neural network, the target node feature information is obtained;

[0156] Generate an abstract syntax tree of SQL based on the decoder and target node feature information, and traverse the abstract syntax tree of SQL according to depth to output the target SQL statement;

[0157] Among them, the question word structure diagram is obtained based on the question words obtained after word segmentation processing of the target natural language question; the database model structure diagram is obtained based on the model information of the database.

[0158] In another aspect, the present invention further provides a non-transitory computer-readable storage medium having a computer program stored thereon, which is implemented when the computer program is executed by a processor to execute the relationship-aware SQL statement generation method provided by the above methods, the method comprising:

[0159] Based on the problem word structure diagram and the database model structure diagram, a problem word model diagram is obtained;

[0160] Based on the question word pattern graph, the relationship-aware graph convolutional network, and the relationship-aware neural network, the target node feature information is obtained;

[0161] Generate an abstract syntax tree of SQL based on the decoder and target node feature information, and traverse the abstract syntax tree of SQL according to depth to output the target SQL statement;

[0162] Among them, the question word structure diagram is obtained based on the question words obtained after word segmentation processing of the target natural language question; the database model structure diagram is obtained based on the model information of the database.

[0163] The device embodiments described above are merely illustrative, wherein the units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place, or they may be distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the scheme of this embodiment. Ordinary technicians in this field can understand and implement it without paying creative labor.

[0164] Through the description of the above implementation methods, those skilled in the art can clearly understand that each implementation method can be implemented by means of software plus a necessary general hardware platform, and of course, it can also be implemented by hardware. Based on this understanding, the above technical solution is essentially or the part that contributes to the prior art can be embodied in the form of a software product, and the computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, a disk, an optical disk, etc., including a number of instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to execute the methods described in each embodiment or some parts of the embodiments.

[0165] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit it. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present invention.

Claims

1. A method for generating a structured query language SQL statement based on relationship awareness, characterized in that: include: Based on the problem word structure diagram and the database model structure diagram, a problem word model diagram is obtained; Based on the problem word pattern graph, the relationship-aware graph convolutional network, and the relationship-aware neural network, characteristic information of the target node is obtained; Generate an abstract syntax tree of SQL based on the decoder and the target node feature information, and traverse the abstract syntax tree of SQL according to the depth to output the target SQL statement; Wherein, the question word structure diagram is obtained based on the question words obtained after word segmentation processing of the target natural language question; the database model structure diagram is obtained based on the model information of the database; The problem word pattern diagram is obtained based on the problem word structure diagram and the database pattern structure diagram, specifically including: Respectively determining an explicit matching relationship and an implicit matching relationship between a question word node in the question word structure diagram and a table column name node in the database model structure diagram; Based on the explicit matching relationship and the implicit matching relationship, the question word structure diagram and the database model structure diagram are connected to obtain the question word model diagram; The step of obtaining target node feature information based on the problem word pattern graph, the relationship-aware graph convolutional network, and the relationship-aware neural network specifically includes: Inputting the problem word pattern graph into a graph convolutional network with relationship awareness to obtain first node feature information; Calculating the attention weights of the table column name node and the question word node, and determining the probability value of the table column name node being mentioned by the target natural language question based on the attention weights; Based on the probability value, updating the characteristic information of the table column name node to obtain second node characteristic information; The second node feature information is input into a neural network with relationship perception to obtain target node feature information.

2. The method for generating SQL statements based on relationship perception according to claim 1, characterized in that: The generating of the SQL abstract syntax tree based on the decoder and the target node feature information specifically includes: The target node feature information and the previous action of the decoder are encoded and input into the decoder to obtain the next action of the decoder; Generate an abstract syntax tree of SQL according to the next action of the decoder.

3. The method for generating SQL statements based on relationship perception according to claim 1, characterized in that: Determining an implicit matching relationship between a question word node in the question word structure diagram and a table column name node in the database model structure diagram specifically includes: The inference knowledge graph is used to capture the implicit matching relationship between the question word nodes in the question word structure graph and the table column name nodes in the database model structure graph.

4. The method for generating SQL statements based on relationship perception according to claim 1, characterized in that: The generation method of the problem word structure diagram includes: Using a Chinese word segmentation tool, the target natural language question is segmented to obtain the question words; Obtain the dependency relationship between the problem words through a dependency parsing tool; The problem words are taken as nodes and the dependency relationships are taken as edges to generate the problem word structure graph.

5. A structured query language SQL statement generation device based on relationship perception, characterized in that: include: A structure diagram module obtains a problem word pattern diagram based on the problem word structure diagram and the database pattern structure diagram; A feature module, which obtains target node feature information based on the problem word pattern graph, the relationship-aware graph convolutional network, and the relationship-aware neural network; A statement module generates an abstract syntax tree of SQL based on the decoder and the target node feature information, and traverses the abstract syntax tree of SQL according to depth to output a target SQL statement; The question word structure diagram is obtained by performing word segmentation processing on the target natural language question to obtain question words and obtain the dependency relationship between the question words; the database model structure diagram is obtained according to the model information of the database; The problem word pattern diagram is obtained based on the problem word structure diagram and the database pattern structure diagram, specifically including: Respectively determining an explicit matching relationship and an implicit matching relationship between a question word node in the question word structure diagram and a table column name node in the database model structure diagram; Based on the explicit matching relationship and the implicit matching relationship, the question word structure diagram and the database model structure diagram are connected to obtain the question word model diagram; The step of obtaining target node feature information based on the problem word pattern graph, the relationship-aware graph convolutional network, and the relationship-aware neural network specifically includes: Inputting the problem word pattern graph into a graph convolutional network with relationship awareness to obtain first node feature information; Calculating the attention weights of the table column name node and the question word node, and determining the probability value of the table column name node being mentioned by the target natural language question based on the attention weights; Based on the probability value, updating the characteristic information of the table column name node to obtain second node characteristic information; The second node feature information is input into a neural network with relationship perception to obtain target node feature information.

6. An electronic device comprising a memory, a processor, and a computer program stored in the memory and running on the processor, characterized in that: When the processor executes the program, the method for generating SQL statements based on relationship awareness as described in any one of claims 1 to 4 is implemented.

7. A non-transitory computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the method for generating SQL statements based on relationship awareness as described in any one of claims 1 to 4 is implemented.

8. A computer program product, comprising a computer program, characterized in that When the computer program is executed by a processor, the method for generating SQL statements based on relationship awareness as described in any one of claims 1 to 4 is implemented.

Citation Information

Patent Citations

  • SQL (Structured Query Language) conversion method and system based on language model coding and multi-task decoding

    CN112988785A

  • Construction method and application of SQL statement generation model of natural Chinese language

    CN114020768A