Database query result generation method, device, equipment and storage medium
By performing natural language query processing on the database that has been denormalized in advance, sentence encoding vectors and table encoding vectors are generated, which solves the problem of high cost of multi-table connection queries in the existing technology and realizes efficient natural language database queries.
Patent Information
- Application Number
- CN202210489889.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-05-07
- Publication Date
- 2025-01-21
- Estimated Expiration
- 2042-05-07
AI Technical Summary
The existing technology is difficult to query databases based on natural language, especially in multi-table connection query, which is costly and affects the timeliness of big data analysis.
By receiving the natural language question, the schema information and location information code of the target database that has been denormalized in advance are obtained, and the natural language question, schema information, and location information code are encoded to generate a sentence encoding vector and a table encoding vector, and then Generate database query statements and perform data queries on the target database.
It simplifies the complexity of generating query statements, reduces the requirements for connection operations and the number of tables, and enables efficient querying of the database based on natural language.
Smart Images

Figure CN115062050B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer technology, and in particular to a method, device, equipment and storage medium for generating database query results. Background Art
[0002] In the existing technology, the research focus may be on improving the semantic optimization of natural language to semantic vectors in encoding, such as using BERT, Transformer, Dense-with-CNN and other networks to improve the encoding of natural language semantics in the encoding module; the research focus may be on the decoding method, improving the grammatical correctness and structural correctness of SQL statements, such as using abstract syntax trees to improve the grammatical structure, using slot filling decoders to define syntax, and using graph neural networks to improve the compatibility of grammatical structures; there is little research on the problem of multi-table joins in SQL statements. Multi-table join queries are one of the important query types in the field of data analysis. The implementation cost of join queries is very high, which affects the timeliness of big data analysis results. The JOIN path problem of multi-table joins is also a difficult problem.
[0003] The above contents are only used to assist in understanding the technical solution of the present invention and do not constitute an admission that the above contents are prior art. Summary of the invention
[0004] The main purpose of the present invention is to provide a method, device, equipment and storage medium for generating database query results, aiming to solve the technical problem that the prior art cannot query the database based on natural language.
[0005] To achieve the above object, the present invention provides a method for generating a database query result, the method comprising the following steps:
[0006] When receiving a natural language question, obtaining the mode information and location information code of the target database, wherein the target database is a database that has been pre-denormalized;
[0007] Encoding the natural language question, the pattern information and the position information code to generate a sentence encoding vector and a table encoding vector;
[0008] Generate a database query statement according to the statement encoding vector and the table encoding vector;
[0009] Perform data query on the target database according to the database query statement to generate query results.
[0010] Optionally, before the step of obtaining the mode information and location information code of the target database when receiving the natural language question, wherein the target database is a database that has been pre-denormalized, the step further includes:
[0011] Obtain table information of each data table in the database to be processed;
[0012] Determine the connection relationship between the data tables according to the table information;
[0013] Denormalization is performed on the database to be processed according to the connection relationship to obtain a target database.
[0014] Optionally, the step of performing denormalization processing on the database to be processed according to the connection relationship to obtain a target database includes:
[0015] Dividing the data table in the to-be-processed database into at least one block according to the connection relationship;
[0016] Perform denormalization on the data tables in each block to obtain a denormalized table corresponding to each block;
[0017] Perform a full outer join on the denormalized tables corresponding to each block, and build the target database based on the results of the full outer join.
[0018] Optionally, the step of encoding the natural language question, the pattern information and the position information code to generate a sentence encoding vector and a table encoding vector includes:
[0019] Performing pooling processing on the location information code to obtain a location semantic vector;
[0020] Performing semantic extraction on the natural language question to obtain a question encoding vector;
[0021] Encoding the mode information to generate a mode encoding vector, and encoding the table column name contained in the mode information to obtain a column vector;
[0022] Generate a column encoding vector according to the question encoding vector and the column vector;
[0023] Combining the position semantic vector, the question word encoding vector and the pattern encoding vector into a sentence encoding vector;
[0024] A table encoding vector is constructed based on the column encoding vector.
[0025] Optionally, the step of generating a column encoding vector according to the question encoding vector and the column vector includes:
[0026] Align the question word encoding vector with the column vector to generate a fused column matrix;
[0027] The context column information corresponding to the fused column matrix is captured through a preset context model, and a column encoding vector is generated based on the context column information.
[0028] Optionally, the step of generating a database query statement according to the statement encoding vector and the table encoding vector includes:
[0029] Classifying the sentence encoding vector to obtain filling clause information;
[0030] Constructing a query statement structure according to the fill-in clause information;
[0031] The query statement structure is filled according to the table encoding vector to generate a database query statement.
[0032] Optionally, before the step of constructing the query statement structure according to the filling clause information, the step further includes:
[0033] Detecting whether the filler clause information complies with a preset grammatical specification;
[0034] If it does, then the step of constructing a query statement structure according to the filling clause information is executed.
[0035] In addition, to achieve the above purpose, the present invention also proposes a database query result generating device, the database query result generating device comprising the following modules:
[0036] An information acquisition module, used to acquire the mode information and location information code of the target database when receiving the natural language question, wherein the target database is a database that has been pre-denormalized;
[0037] An encoding processing module, used for encoding the natural language question, the mode information and the position information code to generate a sentence encoding vector and a table encoding vector;
[0038] A statement generation module, used to generate a database query statement according to the statement encoding vector and the table encoding vector;
[0039] The data query module is used to perform data query on the target database according to the database query statement and generate query results.
[0040] In addition, to achieve the above-mentioned purpose, the present invention also proposes a database query result generating device, which includes: a processor, a memory, and a database query program stored on the memory and executable on the processor, and the database query program implements the steps of the database query result generating method as described above when executed by the processor.
[0041] In addition, to achieve the above-mentioned purpose, the present invention also proposes a computer-readable storage medium, on which a database query program is stored, and when the database query program is executed, the steps of the database query result generating method as described above are implemented.
[0042] The present invention obtains the mode information and location information code of the target database when receiving a natural language question, and the target database is a database that has been pre-denormalized; encodes the natural language question, the mode information and the location information code to generate a sentence encoding vector and a table encoding vector; generates a database query statement according to the sentence encoding vector and the table encoding vector; performs data query on the target database according to the database query statement to generate a query result. Since the database is pre-denormalized, the demand for connection operations and the number of tables are reduced, and the complexity of generating query statements is simplified. Then, the database can be queried according to the database query statement generated by encoding, thereby realizing querying the database according to natural language. BRIEF DESCRIPTION OF THE DRAWINGS
[0043] Figure 1 It is a schematic diagram of the structure of an electronic device in a hardware operating environment involved in an embodiment of the present invention;
[0044] Figure 2 This is a flow chart of a first embodiment of a method for generating a database query result according to the present invention;
[0045] Figure 3 A schematic diagram of a filling slot in an embodiment of a method for generating a database query result of the present invention;
[0046] Figure 4 This is a flow chart of a second embodiment of a method for generating a database query result according to the present invention;
[0047] Figure 5 This is a structural block diagram of the first embodiment of the database query result generating device of the present invention.
[0048] The realization of the purpose, functional features and advantages of the present invention will be further explained in conjunction with embodiments and with reference to the accompanying drawings. DETAILED DESCRIPTION
[0049] It should be understood that the specific embodiments described herein are only used to explain the present invention, and are not used to limit the present invention.
[0050] Reference Figure 1 , Figure 1 A schematic diagram of a device structure for generating database query results for a hardware operating environment involved in an embodiment of the present invention.
[0051] like Figure 1As shown, the electronic device may include: a processor 1001, such as a central processing unit (CPU), a communication bus 1002, a user interface 1003, a network interface 1004, and a memory 1005. Among them, the communication bus 1002 is used to realize the connection and communication between these components. The user interface 1003 may include a display screen (Display), an input unit such as a keyboard (Keyboard), and the optional user interface 1003 may also include a standard wired interface and a wireless interface. The network interface 1004 may optionally include a standard wired interface and a wireless interface (such as a wireless fidelity (Wireless-Fidelity, WI-FI) interface). The memory 1005 may be a high-speed random access memory (Random Access Memory, RAM), or a stable non-volatile memory (Non-Volatile Memory, NVM), such as a disk storage. The memory 1005 may also be a storage device independent of the aforementioned processor 1001.
[0052] Those skilled in the art will understand that Figure 1 The structure shown in the figure does not constitute a limitation on the electronic device, and may include more or less components than shown in the figure, or combine certain components, or arrange the components differently.
[0053] like Figure 1 As shown, the memory 1005 as a storage medium may include an operating system, a network communication module, a user interface module, and a database query program.
[0054] exist Figure 1 In the electronic device shown, the network interface 1004 is mainly used for data communication with a network server; the user interface 1003 is mainly used for data interaction with a user; the processor 1001 and the memory 1005 in the electronic device of the present invention can be set in a database query result generating device, and the electronic device calls the database query program stored in the memory 1005 through the processor 1001, and executes the database query result generating method provided in an embodiment of the present invention.
[0055] The embodiment of the present invention provides a method for generating a database query result, referring to Figure 2 , Figure 2 The figure is a flow chart of a first embodiment of a method for generating a database query result according to the present invention.
[0056] In this embodiment, the method for generating database query results includes the following steps:
[0057] Step S10: when a natural language question is received, the mode information and location information code of the target database are obtained, and the target database is a database that has been pre-denormalized.
[0058] It should be noted that the executor of this embodiment can be the database query result generating device, and the database query result generating device can be an electronic device such as a personal computer, a server, or other devices that can achieve the same or similar functions. This embodiment does not limit this. In this embodiment and the following embodiments, the database query result generating method of the present invention is explained by taking the database query result generating device as an example.
[0059] It should be noted that the natural language question may be a query question raised in natural language, for example: "find the relative date of film which directed by Bill Schreiner". The natural language question may be sent by a user operating other devices to the database query result generating device, or may be directly input by a user on the database query result generating device, and this embodiment does not limit this. The mode information may include: table names, column names, primary key tags, foreign key relationships, and other information of each table in the database. The location information code may be generated based on a statistical process control (SPC) prediction query statement and a nested SPC.
[0060] It should be noted that denormalization can be a processing method that reduces the schema encoding in the database by reconstructing the database schema. The advantages of denormalization are that it reduces the need for join operations, reduces the number of foreign keys and indexes, and may also reduce the number of tables. It can simplify the complexity of query (SQL) statements required for querying. The target database can be a database that has been denormalized in advance.
[0061] Step S20: Encode the natural language question, the pattern information and the position information code to generate a sentence encoding vector and a table encoding vector.
[0062] It should be noted that encoding the natural language question, pattern information and position information codes to generate the sentence encoding vector and the table encoding vector can be performed by combining the natural language question, pattern information and position information codes as input data to be input, inputting the input data into a preset encoder, encoding the natural language question, pattern information and position information codes through the preset encoder, and then generating the sentence encoding vector and the table encoding vector. The preset encoder can be a pre-trained Bert encoder, or, of course, other encoders with similar functions.
[0063] The data to be input can be separated by separators. In the data to be input, the [CLS] mark is placed at the beginning of the first sentence, and the [SEP] mark is used to separate two input sentences. For example:
[0064]
[0065] Furthermore, in order to quickly obtain the sentence encoding vector and the table encoding vector, the step S20 of this implementation may include:
[0066] Performing pooling processing on the location information code to obtain a location semantic vector;
[0067] Performing semantic extraction on the natural language question to obtain a question encoding vector;
[0068] Encoding the mode information to generate a mode encoding vector, and encoding the table column name contained in the mode information to obtain a column vector;
[0069] Generate a column encoding vector according to the question encoding vector and the column vector;
[0070] Combining the position semantic vector, the question word encoding vector and the pattern encoding vector into a sentence encoding vector;
[0071] A table encoding vector is constructed based on the column encoding vector.
[0072] It should be noted that the preset encoder may be pre-set with multiple layers (such as embedded coding layer, column coding layer, problem column alignment layer, table coding layer, etc.), each layer has different functions. The position information code is composed of embedded vectors in the embedded coding layer. After the maximum pooling layer processing, the position semantic vector V is obtained p .
[0073] In the column encoding layer model, DenseCNN is used to encode the words in the column names of the tables contained in the natural language questions and pattern information to capture semantic features and output the question encoding vector and column vector.
[0074] In the question column alignment layer, the question encoding vector is linked to the corresponding column in the hidden column vector, and the column vector is modeled with the context information of the natural language question. In the question table alignment layer, the same network architecture as the question column alignment layer is used to model the table vector with the context information in the question sentence and output the table encoding vector.
[0075] The preset encoder can eventually generate a position semantic vector, a question encoding vector, a pattern encoding vector, a table encoding vector, and a column encoding vector. After that, the position semantic vector, the question encoding vector, and the pattern encoding vector can be combined into a sentence encoding vector, and then the column encoding vector can be combined with the label encoding vector to generate a table encoding vector.
[0076] In a specific implementation, in order to accurately generate a column encoding vector, the step of generating a column encoding vector according to the problem encoding vector and the column vector in this implementation may include:
[0077] Align the question word encoding vector with the column vector to generate a fused column matrix;
[0078] The context column information corresponding to the fused column matrix is captured through a preset context model, and a column encoding vector is generated based on the context column information.
[0079] In practical use, the problem encoding vector can be aligned with the column vector using the scaled dot product, which can be expressed as:
[0080]
[0081] In the formula, H c Can be a column vector, V q can be a question encoding vector, d can be a scaling factor pre-set or adjusted by the administrator of the database query result generating device, T is the matrix transpose operator, softmax is the softmax function, and A Q2C Can be a scaled dot product.
[0082] For large, the scaling dot product grows by orders of magnitude, pushing the softmax function into regions with very small gradients. To counteract this effect, the dot product can be expanded by a factor of 1. Q2C Perform heuristic fusion to obtain the fusion column matrix F c , in the fused column matrix F c Transformer is applied on the tuple to capture the context column information and output the column encoding vector. The table encoding layer can integrate the column vectors of each table in the target database to obtain the encoded table vector.
[0083] Step S30: Generate a database query statement according to the statement encoding vector and the table encoding vector.
[0084] It should be noted that generating a database query statement based on a statement encoding vector and a table encoding vector may be performed by decoding the statement encoding vector and the table encoding vector through a preset decoder, thereby generating an SQL statement executable in a database, ie, a database query statement.
[0085] In actual use, the preset encoder and the preset decoder can be set in the same model and then trained with the Spider dataset. Since the target database is a denormalized database, its database schema has been changed, and the generated query statements are bound to be very different from the query statements provided by the Spider dataset. Therefore, the verification indicator in the training process can be execution accuracy, that is, based on the SQL statements obtained by executing the prediction, the database can return the correct answer for verification.
[0086] Furthermore, in order to quickly generate a database query statement, step S30 in this embodiment may include:
[0087] Classifying the sentence encoding vector to obtain filling clause information;
[0088] Constructing a query statement structure according to the fill-in clause information;
[0089] The query statement structure is filled according to the table encoding vector to generate a database query statement.
[0090] It should be noted that a filling slot may be pre-set in the preset decoder, and the filling slot may be constructed according to SQL grammar, and the SQL grammar may be SQL language complying with specific specifications and guidelines.
[0091] For ease of understanding, refer to Figure 3 This is for illustration but not for limitation. Figure 3 The schematic diagram of the filling slot in the present invention can be used. The SQL syntax structure includes clauses, expressions, predicates, queries and statements. According to the SQL syntax, the filling slot is divided into ten key tasks arranged in different subtasks, namely, the FROM task, SELECT task, ORDER BY task, GROUP BY task, LIMIT task, WHERE task, HAVING task, INTERSECT task, UNION task and EXCEPT task in SQL.
[0092] Key tasks consist of permutations and combinations of subtasks, defined as follows:
[0093] $SEL and $COL represent the table name and column name respectively, $AGG indicates the operation relationship, which means one of {none, max, min, count, sum, avg}, $ARI indicates the operator, which means one of {none, -, +, *, / }, $COND indicates the conditional operator, which means one of {between, =, >, <, > =, < =, ! =, in, like, is, exists}. $DIST and $NOT are table name Boolean variables, which represent the keywords Distinct and NOT respectively. $ORD represents the binary value of the keywords ASC / DESC. $CONJ indicates the conjunction, which means one of {and, or}. $VAL indicates the value of the WHERE or HAVING condition. $SEL indicates the SELECT statement.
[0094] In actual use, the sentence encoding vector can be classified by applying two fully connected layers to obtain the algebraic representation of whether a clause exists and the number of each clause, generate filling clause information, and then create the corresponding query statement position code based on the filling clause information, and recursively generate the query statement structure. Then, based on the table encoding vector, the values corresponding to each existing subtask in the filling slot are predicted, and the query statement structure is filled according to the predicted results, thereby generating a database query statement.
[0095] Furthermore, in order to ensure that the generated database query statement complies with SQL syntax, before the step of constructing the query statement structure according to the filling clause information in this embodiment, the following may also be included:
[0096] Detecting whether the filler clause information complies with a preset grammatical specification;
[0097] If it does, then the step of constructing a query statement structure according to the filling clause information is executed.
[0098] It should be noted that the preset syntax specification can be set by the administrator of the database query result generating device according to the SQL syntax.
[0099] In actual use, it is possible to detect whether a specific clause in the filling clause information exists. If it exists, it is determined that the filling clause information conforms to the preset grammatical specification; if it does not exist, it is determined that the filling clause information does not conform to the preset grammatical specification. For example: detect whether there are "FROM" and "SELECT" clauses in the filling clause information. If both "FROM" and "SELECT" clauses exist, it is determined that the filling clause information conforms to the preset grammatical specification. If "FROM" or "SELECT" clauses do not exist, it is determined that the filling clause information does not conform to the preset grammatical specification.
[0100] It is understandable that if the filling clause information complies with the preset grammatical specification, it means that the filling clause information now has all the clause structures that comply with the SQL grammar, and therefore, the subsequent steps can be continued to generate a database query statement.
[0101] Step S40: performing data query on the target database according to the database query statement to generate query results.
[0102] It is understandable that performing data query on the target database according to the database query statement and generating the query result may be sending the database query statement to the target database so that the target database executes the database query statement to perform data query and returns the query result of the data query.
[0103] In actual use, after obtaining the data query results, the database query can also display the data query results, for example: directly displaying the data query results on the display device of the database query result generating device, or sending the data query results to the user's user terminal for display.
[0104] This embodiment obtains the pattern information and location information code of the target database when receiving a natural language question, and the target database is a database that has been pre-denormalized; encodes the natural language question, the pattern information and the location information code to generate a sentence encoding vector and a table encoding vector; generates a database query statement based on the sentence encoding vector and the table encoding vector; and performs a data query on the target database based on the database query statement to generate a query result. Since the database is pre-denormalized, the need for connection operations and the number of tables are reduced, and the complexity of generating query statements is simplified. Then, the database can be queried based on the database query statement generated by encoding, thereby realizing the query of the database based on natural language.
[0105] refer to Figure 4 , Figure 4 It is a flowchart diagram of a second embodiment of a method for generating database query results according to the present invention.
[0106] Based on the first embodiment described above, the method for generating a database query result in this embodiment further includes, before step S10:
[0107] Step S01: Obtain table information of each data table in the database to be processed.
[0108] It should be noted that the database to be processed may be a database that needs to be queried but has not been denormalized. The table information of the data table may include: table information, number of columns, column name, primary key, foreign key and other information.
[0109] Step S02: Determine the connection relationship between the data tables according to the table information.
[0110] In actual use, the foreign keys contained in each table are determined based on the table information, and the connection relationship between the data tables is determined based on the direction of the foreign keys.
[0111] Step S03: Denormalize the database to be processed according to the connection relationship to obtain a target database.
[0112] It should be noted that denormalizing the database to be processed according to the connection relationship to obtain the target database can be performed by denormalizing the database to be processed according to the connection relationship, merging the data tables in the database to be processed to generate a single table containing all the data in the database to be processed, thereby obtaining the target database.
[0113] In a specific implementation, in order to quickly perform denormalization and ensure the correctness of data, step S03 in this embodiment may include:
[0114] Dividing the data table in the to-be-processed database into at least one block according to the connection relationship;
[0115] Perform denormalization on the data tables in each block to obtain a denormalized table corresponding to each block;
[0116] Perform a full outer join on the denormalized tables corresponding to each block, and build the target database based on the results of the full outer join.
[0117] It should be noted that dividing the data table in the database to be processed into at least one block according to the connection relationship can be dividing the data tables with data association in the database to be processed into the same block according to the connection relationship, thereby obtaining at least one block. Denormalizing the data tables in each block to obtain the denormalized table corresponding to each block can be connecting the data tables in the block according to the data association relationship to generate the denormalized table corresponding to the block. In order to avoid data loss, each data table can be externally connected according to the foreign key in the data table when connecting the tables.
[0118] For example: Assume that a block contains six tables, namely Staff, Claims_Document, Claims_Processing, Claims_Headers, Polliticies, and Customers. During the quasi-normalization process, the first two tables, Staff and Claims_Document, will be externally joined based on their foreign keys, and then the two tables will be replaced by the generated new table. At this time, the block only contains 5 tables, and the cycle will be repeated until only one table remains in the block, indicating that the denormalization of the block is completed. At this time, the remaining table in the block is the denormalized table corresponding to the block.
[0119] It is understandable that there is no connection relationship between the data tables in different blocks. Therefore, in order to ensure the comprehensiveness of the data and avoid data loss, the denormalized tables corresponding to each block can be fully outer joined, and then a database can be constructed as the target data based on the result of the full outer join, that is, the data table obtained by the full outer join.
[0120] This embodiment obtains the target database by obtaining the table information of each data table in the database to be processed; determining the connection relationship between each data table according to the table information; and performing denormalization processing on the database to be processed according to the connection relationship. Since the table information of each data table in the database to be processed is obtained in advance, the connection relationship between each data table can be quickly determined according to the table information, thereby ensuring that the database to be processed can be quickly denormalized, which provides a basis for the implementation of the database query result generation method of the present invention.
[0121] In addition, an embodiment of the present invention further provides a storage medium, on which a database query program is stored. When the database query program is executed by a processor, the steps of the database query result generating method described above are implemented.
[0122] Reference Figure 5 , Figure 5 This is a structural block diagram of the first embodiment of the database query result generating device of the present invention.
[0123] like Figure 5 As shown, the database query result generating device proposed in the embodiment of the present invention includes:
[0124] The information acquisition module 10 is used to acquire the mode information and location information code of the target database when receiving the natural language question, wherein the target database is a database that has been pre-denormalized;
[0125] The encoding processing module 20 is used to perform encoding processing on the natural language question, the mode information and the position information code to generate a sentence encoding vector and a table encoding vector;
[0126] A statement generation module 30, used to generate a database query statement according to the statement encoding vector and the table encoding vector;
[0127] The data query module 40 is used to perform data query on the target database according to the database query statement and generate query results.
[0128] This embodiment obtains the pattern information and location information code of the target database when receiving a natural language question, and the target database is a database that has been pre-denormalized; encodes the natural language question, the pattern information and the location information code to generate a sentence encoding vector and a table encoding vector; generates a database query statement based on the sentence encoding vector and the table encoding vector; and performs a data query on the target database based on the database query statement to generate a query result. Since the database is pre-denormalized, the need for connection operations and the number of tables are reduced, and the complexity of generating query statements is simplified. Then, the database can be queried based on the database query statement generated by encoding, thereby realizing the query of the database based on natural language.
[0129] Furthermore, the information acquisition module 10 is also used to obtain table information of each data table in the database to be processed; determine the connection relationship between the data tables according to the table information; and perform denormalization processing on the database to be processed according to the connection relationship to obtain the target database.
[0130] Furthermore, the information acquisition module 10 is also used to divide the data table in the database to be processed into at least one block according to the connection relationship; perform denormalization on the data table in each block to obtain the denormalized table corresponding to each block; perform full outer join on the denormalized table corresponding to each block, and construct the target database according to the result of the full outer join.
[0131] Furthermore, the encoding processing module 20 is also used to perform pooling processing on the position information code to obtain a position semantic vector; perform semantic extraction on the natural language question to obtain a question encoding vector; encode the pattern information to generate a pattern encoding vector, and encode the table column name contained in the pattern information to obtain a column vector; generate a column encoding vector based on the question encoding vector and the column vector; combine the position semantic vector, the question word encoding vector and the pattern encoding vector into a sentence encoding vector; and construct a table encoding vector based on the column encoding vector.
[0132] Furthermore, the encoding processing module 20 is also used to align the problem word encoding vector with the column vector to generate a fused column matrix; capture the context column information corresponding to the fused column matrix through a preset context model, and generate a column encoding vector based on the context column information.
[0133] Furthermore, the statement generation module 30 is also used to classify the statement encoding vector to obtain filling clause information; construct a query statement structure according to the filling clause information; fill the query statement structure according to the table encoding vector to generate a database query statement.
[0134] Furthermore, the statement generation module 30 is also used to detect whether the filling clause information conforms to a preset grammatical specification; if it conforms, the step of constructing a query statement structure according to the filling clause information is executed.
[0135] It should be understood that the above is only an example and does not constitute any limitation on the technical solution of the present invention. In specific applications, technicians in this field can make settings as needed, and the present invention does not limit this.
[0136] It should be noted that the workflow described above is merely illustrative and does not limit the scope of protection of the present invention. In practical applications, technicians in this field can select part or all of them according to actual needs to achieve the purpose of the present embodiment, and no limitation is made here.
[0137] In addition, for technical details that are not described in detail in this embodiment, reference can be made to the database query result generating method provided in any embodiment of the present invention, and will not be repeated here.
[0138] In addition, it should be noted that, in this article, the terms "include", "comprises" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, article or system including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or system. In the absence of further restrictions, an element defined by the sentence "comprises a ..." does not exclude the existence of other identical elements in the process, method, article or system including the element.
[0139] The serial numbers of the above embodiments of the present invention are only for description and do not represent the advantages or disadvantages of the embodiments.
[0140] Through the description of the above implementation methods, those skilled in the art can clearly understand that the above-mentioned embodiment methods can be implemented by means of software plus a necessary general hardware platform, and of course by hardware, but in many cases the former is a better implementation method. Based on such an understanding, the technical solution of the present invention, or the part that contributes to the prior art, can be embodied in the form of a software product, which is stored in a storage medium (such as a read-only memory (ROM) / RAM, a magnetic disk, or an optical disk), and includes a number of instructions for a terminal device (which can be a mobile phone, a computer, a server, or a network device, etc.) to execute the methods described in each embodiment of the present invention.
[0141] The above are only preferred embodiments of the present invention, and are not intended to limit the patent scope of the present invention. Any equivalent structure or equivalent process transformation made using the contents of the present invention specification and drawings, or directly or indirectly applied in other related technical fields, are also included in the patent protection scope of the present invention.
Claims
1. A method for generating database query results, characterized in that: The database query result generation method comprises the following steps: When receiving a natural language question, obtaining the mode information and location information code of the target database, wherein the target database is a database that has been pre-denormalized; Encoding the natural language question, the pattern information and the position information code to generate a sentence encoding vector and a table encoding vector; Generate a database query statement according to the statement encoding vector and the table encoding vector; Performing data query on the target database according to the database query statement to generate query results; The step of encoding the natural language question, the pattern information and the position information code to generate a sentence encoding vector and a table encoding vector comprises: Performing pooling processing on the location information code to obtain a location semantic vector; Performing semantic extraction on the natural language question to obtain a question encoding vector; Encoding the mode information to generate a mode encoding vector, and encoding the table column name contained in the mode information to obtain a column vector; Generate a column encoding vector according to the question encoding vector and the column vector; Combining the position semantic vector, the question encoding vector and the pattern encoding vector into a sentence encoding vector; constructing a table encoding vector according to the column encoding vector; The step of generating a column encoding vector according to the question encoding vector and the column vector comprises: Aligning the problem encoding vector with the column vector to generate a fused column matrix; The context column information corresponding to the fused column matrix is captured through a preset context model, and a column encoding vector is generated based on the context column information.
2. The method for generating database query results according to claim 1, characterized in that: Before the step of obtaining the mode information and location information code of the target database upon receiving the natural language question, wherein the target database is a database that has been pre-denormalized, the method further includes: Obtain table information of each data table in the database to be processed; Determine the connection relationship between the data tables according to the table information; Denormalization is performed on the database to be processed according to the connection relationship to obtain a target database.
3. The method for generating database query results according to claim 2, characterized in that: The step of performing denormalization processing on the database to be processed according to the connection relationship to obtain a target database includes: Dividing the data table in the to-be-processed database into at least one block according to the connection relationship; Perform denormalization on the data tables in each block to obtain a denormalized table corresponding to each block; Perform a full outer join on the denormalized tables corresponding to each block, and build the target database based on the results of the full outer join.
4. The method for generating a database query result according to any one of claims 1 to 3, characterized in that: The step of generating a database query statement according to the statement encoding vector and the table encoding vector comprises: Classifying the sentence encoding vector to obtain filling clause information; Constructing a query statement structure according to the fill-in clause information; The query statement structure is filled according to the table encoding vector to generate a database query statement.
5. The method for generating database query results according to claim 4, characterized in that: Before the step of constructing the query statement structure according to the filling clause information, the method further includes: Detecting whether the filler clause information complies with a preset grammatical specification; If it does, then the step of constructing a query statement structure according to the filling clause information is executed.
6. A database query result generating device, characterized in that: The database query result generating device comprises the following modules: An information acquisition module, used to acquire the mode information and location information code of the target database when receiving the natural language question, wherein the target database is a database that has been pre-denormalized; An encoding processing module, used for encoding the natural language question, the mode information and the position information code to generate a sentence encoding vector and a table encoding vector; A statement generation module, used to generate a database query statement according to the statement encoding vector and the table encoding vector; A data query module, used to perform data query on the target database according to the database query statement and generate query results; The encoding processing module is further used to perform pooling processing on the position information code to obtain a position semantic vector; perform semantic extraction on the natural language question to obtain a question encoding vector; encode the pattern information to generate a pattern encoding vector, and encode the table column name contained in the pattern information to obtain a column vector; generate a column encoding vector according to the question encoding vector and the column vector; combine the position semantic vector, the question encoding vector and the pattern encoding vector into a sentence encoding vector; and construct a table encoding vector according to the column encoding vector; The encoding processing module is also used to align the problem encoding vector with the column vector to generate a fused column matrix; capture the context column information corresponding to the fused column matrix through a preset context model, and generate a column encoding vector based on the context column information.
7. A database query result generating device, characterized in that: The database query result generating device comprises: a processor, a memory, and a database query program stored in the memory and executable on the processor. When the database query program is executed by the processor, the steps of the database query result generating method according to any one of claims 1 to 5 are implemented.
8. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a database query program, which, when executed, implements the steps of the database query result generating method according to any one of claims 1 to 5.
Citation Information
Patent Citations
Method for generating structured query statement based on natural language
CN111813802A
Natural Language Processing Engine For Translating Questions Into Executable Database Queries
US20210173829A1