Database operation statement generation method and device, computer device, and storage medium
By receiving natural language information and converting it into database operation language information, database operation statements are generated, solving the problem of low database operation efficiency in low-code platforms and simplifying the operation process and improving efficiency.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- INDUSTRIAL AND COMMERCIAL BANK OF CHINA
- Filing Date
- 2023-06-19
- Publication Date
- 2026-06-05
AI Technical Summary
Database operations based on visual logic orchestration in low-code platforms are inefficient and rely on cumbersome drag-and-drop visual components.
By receiving natural language information, obtaining database data structure information, using a pre-trained database statement generation model to determine the information of related data tables, and converting the natural language information into database operation language information to generate database operation statements.
It simplifies the database operation process, improves operational efficiency, and reduces reliance on drag-and-drop functionality for visual components.
Smart Images

Figure CN116756179B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of computer technology, and in particular to a method, apparatus, computer device, storage medium, and computer program product for generating database operation statements. Background Technology
[0002] With the rapid development of the information society, low-code platforms have played a vital role in the digital transformation of various industries. Through visual logic orchestration, low-code platforms can assist developers in manipulating databases; however, visual logic orchestration relies on developers dragging and dropping visual components, a cumbersome process that results in low efficiency for database operations. Summary of the Invention
[0003] Therefore, it is necessary to provide a database operation statement generation method, apparatus, computer equipment, computer-readable storage medium, and computer program product that can improve the operational efficiency of database operations, in order to address the above-mentioned technical problems.
[0004] Firstly, this application provides a method for generating database operation statements. The method includes:
[0005] Receive input natural language information for manipulating the database;
[0006] Obtain the data structure information from the database, and determine the associated data table information in the database that is related to the natural language information based on the data structure information; the data structure information is used to characterize the dependency relationships between the data in each data table of the database;
[0007] In addition, the natural language information is converted into database language information that matches the database operation language environment;
[0008] Based on the associated data table information and the database language information, database operation statements corresponding to the natural language information are generated.
[0009] In an exemplary embodiment, determining the associated data table information in the database that is related to the natural language information based on the data structure information includes:
[0010] Based on the pre-trained database statement generation model and the semantic vector corresponding to the natural language information, the first associated data table of the natural language information in the database and the associated data of the natural language information in the first associated data table are determined.
[0011] Based on the semantic vector corresponding to the data structure information and the associated data, determine the second associated data table in the database that is associated with the first associated data table;
[0012] Based on the first associated data table, the associated data, and the second associated data table, associated data table information related to the natural language information is obtained.
[0013] In one exemplary embodiment, converting the natural language information into database language information that matches the database operation language environment includes:
[0014] The database statement generation model, which is obtained through pre-training, identifies the first keyword that meets the preset keyword conditions from the keywords of the natural language information.
[0015] The first keyword is processed by language conversion to obtain a second keyword that matches the database operation language environment;
[0016] Based on the third keyword and the second keyword in the natural language information, the database language information that matches the database operation language environment is obtained; the third keyword is a keyword other than the first keyword among the keywords in the natural language information.
[0017] In an exemplary embodiment, the step of performing language conversion processing on the first keyword to obtain a second keyword that matches the database operation language environment includes:
[0018] From the semantic vector corresponding to the natural language information, identify the sub-semantic vector corresponding to the first keyword;
[0019] Based on the sub-semantic vector and keyword mapping relationship corresponding to the first keyword, database language keywords that match the first keyword are identified in the database language keyword library that matches the database operation language environment, and are used as the second keyword that matches the database operation language environment.
[0020] In an exemplary embodiment, the step of identifying database language keywords matching the first keyword in a database language keyword library that matches the database operation language environment, based on the sub-semantic vector corresponding to the first keyword and the keyword mapping relationship, includes:
[0021] Based on the attention mechanism layer in the pre-trained database statement generation model, the sub-semantic vector corresponding to the first keyword, and the keyword mapping relationship, the weight of each database language keyword in the database language keyword library corresponding to the first keyword is determined.
[0022] Based on the weights, the mapping correlation between the first keyword and each database language keyword is determined;
[0023] Among the various database language keywords, database language keywords whose corresponding mapping relevance meets the preset mapping relevance conditions are identified and used as database language keywords that match the first keyword.
[0024] In one exemplary embodiment, obtaining the data structure information in the database includes:
[0025] Retrieve the data tables stored in the database;
[0026] For each data table, determine the data structure attributes of the data table;
[0027] Based on the data structure attributes of each data table, determine the first dependency relationship between the data stored in each data table, and the second dependency relationship between the data tables;
[0028] The first dependency and the second dependency are determined as data structure information in the database.
[0029] In one exemplary embodiment, before receiving input natural language information for manipulating the database, the method further includes:
[0030] The display shows a natural language input page with multiple input options;
[0031] The system receives text input for each input entry point, combines the text according to the order of the input entries, and obtains the natural language information used to operate the database.
[0032] Secondly, this application also provides a database operation statement generation apparatus. The apparatus includes:
[0033] The language information receiving module is used to receive input natural language information for database operations;
[0034] The association information confirmation module is used to obtain data structure information from the database and, based on the data structure information, determine the association data table information in the database that is associated with the natural language information; the data structure information is used to characterize the dependency relationship between the data in each data table in the database.
[0035] The language information conversion module is used to convert the natural language information into database language information that matches the database operation language environment;
[0036] The operation statement generation module is used to generate database operation statements corresponding to the natural language information based on the associated data table information and the database language information.
[0037] Thirdly, this application also provides a computer device. The computer device includes a memory and a processor, the memory storing a computer program, and the processor executing the computer program to perform the following steps:
[0038] Receive input natural language information for manipulating the database;
[0039] Obtain the data structure information from the database, and determine the associated data table information in the database that is related to the natural language information based on the data structure information; the data structure information is used to characterize the dependency relationships between the data in each data table of the database;
[0040] In addition, the natural language information is converted into database language information that matches the database operation language environment;
[0041] Based on the associated data table information and the database language information, database operation statements corresponding to the natural language information are generated.
[0042] Fourthly, this application also provides a computer-readable storage medium. The computer-readable storage medium stores a computer program thereon, which, when executed by a processor, performs the following steps:
[0043] Receive input natural language information for manipulating the database;
[0044] Obtain the data structure information from the database, and determine the associated data table information in the database that is related to the natural language information based on the data structure information; the data structure information is used to characterize the dependency relationships between the data in each data table of the database;
[0045] In addition, the natural language information is converted into database language information that matches the database operation language environment;
[0046] Based on the associated data table information and the database language information, database operation statements corresponding to the natural language information are generated.
[0047] Fifthly, this application also provides a computer program product. The computer program product includes a computer program that, when executed by a processor, performs the following steps:
[0048] Receive input natural language information for manipulating the database;
[0049] Obtain the data structure information from the database, and determine the associated data table information in the database that is related to the natural language information based on the data structure information; the data structure information is used to characterize the dependency relationships between the data in each data table of the database;
[0050] In addition, the natural language information is converted into database language information that matches the database operation language environment;
[0051] Based on the associated data table information and the database language information, database operation statements corresponding to the natural language information are generated.
[0052] The aforementioned database operation statement generation method, apparatus, computer device, storage medium, and computer program product first receive input natural language information for database operations; then, they acquire data structure information from the database, and based on this data structure information, determine the associated data table information in the database that is linked to the natural language information; the data structure information is used to characterize the dependencies between data in each data table in the database; and the natural language information is converted into database language information that matches the database operation language environment; finally, based on the associated data table information and the database language information, database operation statements corresponding to the natural language information are generated. In this way, by using the input natural language information for database operations and the associated data table information obtained based on the database's data structure information, natural language information can be converted into database language information, thereby generating database operation statements capable of operating the database. This database operation statement generation method, based on the above process, can convert the natural language input by developers into database language that matches the database operation language environment, thus eliminating the reliance on drag-and-drop behavior of visual components for database operations on low-code platforms, simplifying the database operation process, and improving the efficiency of database operations. Attached Figure Description
[0053] Figure 1 This is a flowchart illustrating a database operation statement generation method in one embodiment;
[0054] Figure 2 This is a flowchart illustrating the steps of determining the associated data table information in the database that is related to natural language information based on data structure information in one embodiment.
[0055] Figure 3 This is a flowchart illustrating the steps of converting natural language information into database language information that matches the database operation language environment in one embodiment.
[0056] Figure 4 This is a flowchart illustrating the steps of identifying database language keywords that match the first keyword in one embodiment.
[0057] Figure 5 This is a schematic diagram of the database data structure information in one embodiment;
[0058] Figure 6 This is a schematic diagram of a natural language input page including multiple input entries in one embodiment;
[0059] Figure 7 This is a flowchart illustrating a database operation statement generation method in another embodiment;
[0060] Figure 8 This is a flowchart illustrating the steps of generating a database query statement using a dual-channel deep model based on a bidirectional long short-term memory artificial neural network in one embodiment.
[0061] Figure 9 This is a structural block diagram of a database operation statement generation device in one embodiment;
[0062] Figure 10 This is an internal structural diagram of a computer device in one embodiment. Detailed Implementation
[0063] To make the objectives, technical solutions, and advantages of this application clearer, the following detailed description is provided in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative and not intended to limit the scope of this application.
[0064] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, data stored, data displayed, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties, and the collection, use and processing of the relevant data shall comply with the relevant laws, regulations and standards of the relevant countries and regions.
[0065] It should also be noted that the database operation statement generation method, apparatus, computer equipment, storage medium and computer program products provided in this application can be applied to the financial technology field, such as assisting bank R&D personnel in querying and other operations on the bank's business system database; they can also be applied to other related fields, such as in the field of computer technology, where the database operation statement generation method provided in this application can convert natural language into database language to assist non-professional developers in operating the database.
[0066] In one exemplary embodiment, such as Figure 1As shown, a method for generating database operation statements is provided. This embodiment illustrates the application of this method to a server; it is understood that this method can also be applied to a terminal, and to a system including both a server and a terminal, and is implemented through interaction between the server and the terminal. The server can be a standalone server or a server cluster composed of multiple servers; the terminal can be, but is not limited to, various personal computers, laptops, smartphones, and tablets. In this embodiment, the method includes the following steps:
[0067] Step S102: Receive input natural language information for operating the database.
[0068] The operations on the database include at least query operations, add operations, delete operations, and modify operations.
[0069] Natural language refers to languages that evolve naturally with culture, such as Chinese and English; natural language information refers to information expressed in natural language forms, such as natural language statements.
[0070] Specifically, the server receives natural language information entered by researchers on the natural language input page. It is understandable that the sentence components and word order of natural language are not fixed, so the server can set up standardized input entry points on the natural language input page to facilitate researchers to input standardized natural language information.
[0071] For example, when R&D personnel need to query the most expensive car in a database table named "Garage" and display the brand of that car, they would enter the natural language statement "Please query the brand of the most expensive car in the garage" on the natural language input page and send this natural language statement to the server via the message sending button.
[0072] Step S104: Obtain data structure information from the database; determine the associated data table information in the database that is related to the natural language information based on the data structure information; and convert the natural language information into database language information that matches the database operation language environment.
[0073] Among them, data structure information is used to represent the dependencies between data in various data tables in the database; for example, the attributes included in each data table can be understood as, in a data table, one column represents one attribute; another example is the reference relationship between various data tables, such as the attribute "Brand" in the data table "Garage" needing to reference the attribute "Brand Name" in the data table "Brand", then the data table "Garage" and the data table "Brand" have established a reference relationship through the attribute "Brand" and the attribute "Brand Name".
[0074] Among them, the associated data table information is used to represent the data table to be operated on in the database, as well as the data in the data table to be operated on. For example, for the natural language information "Please query the brand of the most expensive car in the garage", assuming that the attribute "Brand" of the data table "Garage" needs to reference the attribute "Brand Name" of the data table "Brand", then the associated data table information associated with this natural language information includes at least: data table "Garage", attribute "Price", attribute "Brand", data table "Brand", and attribute "Brand Name".
[0075] Among them, database language information that matches the database operation language environment refers to information expressed in a form that the database can recognize, such as SQL statements (Structured Query Language).
[0076] It is understandable that the server can break down natural language information into four key elements: operation action, operation object, problem description, and display content. For the natural language information "Please query the brand of the most expensive car in the garage", the four key elements are "query", "garage", "most expensive", and "car brand". Therefore, the server can use database language to express these four key elements respectively, thereby obtaining database language information corresponding to the natural language information.
[0077] Specifically, the server first determines the data structure information in the database based on the attributes of each data table and the reference relationships between them. Then, based on the natural language information and the data structure information, the server determines the data table to be operated on and the data in the data table to be operated on, and uses the data table to be operated on and the data in the data table to be operated on as the associated data table information of the natural language information. At the same time, the server breaks down the natural language information into four key elements: operation action, operation object, problem description, and display content. Through the mapping relationship between natural language and database language, the server converts the expression of each key element of the natural language information into database language, thereby obtaining database language information that matches the database operation language environment.
[0078] Step S106: Based on the information of the associated data table and the database language information, generate database operation statements corresponding to the natural language information.
[0079] Database operation statements are SQL statements.
[0080] Specifically, the server generates statements that conform to the database language syntax based on the associated data table information, the corresponding database language information, and the database language syntax, thus obtaining the database operation statements corresponding to the natural language information. Based on the generated database operation statements, the server can perform corresponding queries, additions, deletions, and modifications on the database, and display the results to the developers through a front-end interface.
[0081] For example, suppose the server receives the natural language information "Please query the price of car number 123 in the garage". The database operation statement generated by the server is "SELECT price FROM garage WHERE car number = '123'". If the price of car number 123 in the garage is 123456, then the server will display the price "123456" to the developers through the front-end interface.
[0082] In the database operation statement generation method provided in the above embodiments, the server first receives input natural language information for database operation; then, it obtains data structure information from the database, and determines the associated data table information in the database that is related to the natural language information based on the data structure information; the data structure information is used to characterize the dependencies between data in various data tables in the database; and the natural language information is converted into database language information that matches the database operation language environment; finally, based on the associated data table information and the database language information, the server generates database operation statements corresponding to the natural language information. In this way, the server can convert the input natural language information for database operation, and the associated data table information obtained based on the database data structure information, into database language information, thereby generating database operation statements capable of operating the database. Based on the above process, the database operation statement generation method allows the server to convert the natural language input by developers into database language that matches the database operation language environment, thus making database operations based on low-code platforms no longer dependent on drag-and-drop behavior of visual components, simplifying the database operation process, and improving the efficiency of database operations.
[0083] like Figure 2 As shown, in an exemplary embodiment, step S104 above, determining the associated data table information in the database related to natural language information based on data structure information, specifically includes the following steps:
[0084] Step S202: Based on the pre-trained database statement generation model and the semantic vector corresponding to the natural language information, determine the first associated data table of the natural language information in the database, and the associated data of the natural language information in the first associated data table.
[0085] Step S204: Based on the semantic vector corresponding to the data structure information and the associated data, determine the second associated data table in the database that is associated with the first associated data table.
[0086] Step S206: Based on the first associated data table, associated data, and the second associated data table, obtain the associated data table information associated with the natural language information.
[0087] Among them, the pre-trained database statement generation model is a dual-channel deep model based on a bidirectional LSTM (Long Short-Term Memory) network, trained based on the database operation statement generation process of sample natural language information.
[0088] The first associated data table is the data table that the server needs to directly manipulate in the database based on natural language information. The associated data in the first associated data table is the data to be manipulated by the server in the first associated data table based on natural language information. The second associated data table is the data table that the server determines by establishing a reference relationship between the data to be manipulated in the first associated data table and the first associated data table based on natural language information. For example, for the natural language information "Please query the brand of the most expensive car in the garage", assuming that the attribute "brand" of the data table "garage" needs to reference the attribute "brand name" of the data table "brand", then the first associated data table is the data table "garage", the associated data is the attributes "price" and "brand" in the first associated data table, and the second associated data table is the data table "brand".
[0089] Specifically, the server first performs word vector mapping on the natural language information and data structure information respectively to obtain the word vectors corresponding to the natural language information and the data structure information. Then, through a semantic expression model, it learns the word vectors corresponding to the natural language information and the data structure information respectively to obtain the semantic vectors corresponding to the natural language information and the data structure information. Then, the server inputs the semantic vectors corresponding to the natural language information and the data structure information into a pre-trained database statement generation model. Through the pre-trained database statement generation model, the server first determines the data table that the natural language information needs to directly manipulate in the database, as the first associated data table of the natural language information in the database, and determines the data to be manipulated in the first associated data table, as the associated data of the natural language information in the first associated data table. Next, the server determines the reference relationship between the first associated data table and the other data tables according to the semantic vectors corresponding to the data structure information, and then determines the data table associated with the data to be manipulated, as the second associated data table associated with the first associated data table. Finally, the server determines the above-mentioned first associated data table, associated data, and second associated data table as the associated data table information associated with the natural language information.
[0090] It is understandable that the server can also consider data in the second associated data table that has a reference relationship with the associated data as associated data table information related to natural language information; for example, in addition to the first associated data table "garage", the attribute "price" in the first associated data table, the attribute "brand" in the first associated data table, and the second associated data table "brand", the server can also identify the attribute "brand name" in the second associated data table as associated data table information related to natural language information.
[0091] In this embodiment, the server, through a pre-trained database statement generation model, can determine the first associated data table, the second associated data table, and associated data in the database based on database structure information and natural language information. This facilitates the subsequent conversion of database language information and the generation of database operation statements, thereby simplifying the database operation process and improving the efficiency of database operations.
[0092] like Figure 3 As shown, in an exemplary embodiment, step S104 above, converting natural language information into database language information that matches the database operation language environment, specifically includes the following steps:
[0093] Step S302: Using a pre-trained database statement generation model, identify the first keyword that meets the preset keyword conditions from the various keywords in the natural language information.
[0094] Step S304: Perform language conversion processing on the first keyword to obtain a second keyword that matches the database operation language environment.
[0095] Step S306: Based on the third and second keywords in the natural language information, obtain database language information that matches the database operation language environment.
[0096] Among them, each keyword in natural language information refers to the vocabulary in natural language information that corresponds to each key element of natural language information (operation action, operation object, problem description, and display content).
[0097] The first keyword is a keyword in the natural language information that is related to an action (such as querying, deleting, modifying, adding, etc.) or a description of a problem (such as most expensive, largest, smallest, and, or, and, in, etc.). The third keyword is a keyword in the natural language information that is not related to the first keyword, i.e., a keyword related to the object of the operation or the content displayed, such as table name, attribute name, etc.
[0098] Specifically, the server first inputs natural language information into a pre-trained database statement generation model. Since the server has set up standardized input entry points on the natural language input page, the pre-trained database statement generation model can identify keywords corresponding to the operation action or question description from the keywords in the natural language information based on the input entry points corresponding to each key element (query object, question description, and displayed content), and use these keywords as the first keyword that meets the preset keyword conditions. Alternatively, the pre-trained database statement generation model can identify keywords that match the natural language keyword library from the natural language information based on text detection, and use these keywords as the first keyword that meets the preset keyword conditions. Next, the server performs language conversion processing on the first keyword through keyword mapping relationships, converting the first keyword in natural language into a second keyword that matches the database operation language environment. Finally, the server combines the third keyword in the natural language information and the second keyword that matches the database operation language environment to obtain database language information that matches the database operation language environment.
[0099] It is understandable that since the third keyword is related to the query object and displayed content in natural language information, such as table name and attribute name, and the table name and attribute name are themselves the data table identifier and attribute identifier of the data table stored in the database, the server does not need to convert the third keyword.
[0100] For example, suppose the first keyword is "most expensive" and "query", and the third keyword is "garage", "brand", and "price". Since "most expensive" means the largest price value, the server can determine that the expression in the database language corresponding to "most expensive" is "MAX" through the keyword mapping relationship. Thus, the server can obtain the second keyword "MAX" that matches the database operation language environment. In turn, the server obtains the database language information that matches the database operation language environment as "MAX", "garage", "price" and "brand".
[0101] In this embodiment, the server, through a pre-trained database statement generation model, can identify the first keyword that needs to be converted and the third keyword that does not need to be converted from natural language information. It then converts the first keyword that matches the natural language environment into the second keyword that matches the database operation language environment. Based on the third and second keywords, it obtains database language information that matches the database operation language environment, providing a foundation for the subsequent generation of database operation statements based on the database language information. This simplifies the database operation process and improves the efficiency of database operations.
[0102] In an exemplary embodiment, step S304 above, which performs language conversion processing on the first keyword to obtain a second keyword that matches the database operation language environment, specifically includes the following: identifying the sub-semantic vector corresponding to the first keyword from the semantic vector corresponding to the natural language information; and based on the sub-semantic vector corresponding to the first keyword and the keyword mapping relationship, identifying the database language keyword that matches the first keyword in the database language keyword library that matches the database operation language environment, and using it as the second keyword that matches the database operation language environment.
[0103] It should be noted that because database languages have strict syntax and logical structures, the server can construct a mapping relationship between natural language keywords and database language keywords by using sample natural language information and its corresponding database language information.
[0104] The keyword mapping relationship is a mapping relationship constructed by the server based on the correspondence between keywords related to operation actions or problem descriptions in the sample natural language information and keywords in the database language; as shown in Table 1, it is a keyword mapping relationship table representing the keyword mapping relationship; it should be understood that Table 1 only lists a portion of the keyword mapping relationships:
[0105] Table 1 Keyword Mapping Relationship Table
[0106]
[0107]
[0108] Specifically, the server first identifies the sub-semantic vector corresponding to the first keyword from the semantic vector corresponding to the natural language information. Then, based on the sub-semantic vector corresponding to the first keyword and the keyword mapping relationship, it identifies the matching database language keyword corresponding to the first keyword in the database language keyword library that matches the database operation language environment, and uses it as the second keyword that matches the database operation language environment.
[0109] For example, if the first keyword is "or", the server can obtain the second keyword "OR" by querying the keyword mapping table shown in Table 1; as another example, if the first keyword is "minimum", the server can obtain the second keyword "MIN" by querying the keyword mapping table shown in Table 1.
[0110] In this embodiment, the server can accurately convert the first keyword in natural language into the second keyword in database language through keyword mapping relationship, which provides a basis for subsequent determination of database language information and generation of database operation statements based on database language information, thereby simplifying the database operation process and improving the efficiency of database operation.
[0111] like Figure 4 As shown, in an exemplary embodiment, the above steps, based on the sub-semantic vector corresponding to the first keyword and the keyword mapping relationship, identify database language keywords matching the first keyword in a database language keyword library that matches the database operation language environment, specifically including the following steps:
[0112] Step S402: Based on the attention mechanism layer in the pre-trained database statement generation model, the sub-semantic vector corresponding to the first keyword, and the keyword mapping relationship, determine the weight of each database language keyword in the database language keyword library corresponding to the first keyword.
[0113] Step S404: Based on the weights, determine the mapping correlation between the first keyword and the language keywords of each database.
[0114] Step S406: Among the various database language keywords, identify the database language keywords whose corresponding mapping relevance meets the preset mapping relevance conditions, and use them as the database language keywords that match the first keyword.
[0115] The first keyword corresponds to the weight of each database language keyword in the database language keyword library, which is used to characterize the strength of the mapping relationship between the first keyword and each database language keyword in the database language keyword library. For example, if the natural language keyword "or" has a mapping relationship with the database language keyword "OR", then the weight between the first keyword "or" and the database language keyword "OR" is the highest, and the weight between the first keyword "or" and the other database language keywords in the database language keyword library other than "OR" is lower.
[0116] Among them, the mapping relevance is used to characterize the probability that the first keyword can be converted into each database language keyword in the database language keyword library; the higher the mapping relevance, the greater the probability that the first keyword can be converted into the corresponding database language keyword.
[0117] Specifically, the server, based on the attention mechanism layer in the pre-trained database statement generation model, queries the keyword mapping table representing keyword mapping relationships to find the mapping relationship of the first keyword, and determines the weight of each database language keyword in the database language keyword library corresponding to the first keyword based on the mapping relationship of the first keyword. Then, the server determines the mapping correlation between the first keyword and each database language keyword based on the weight, for example, using the weight as the probability of the first keyword being converted into each database language keyword, and using the probability as the mapping correlation between the first keyword and each database language keyword. Finally, the server identifies the database language keyword with the highest corresponding mapping correlation, or the corresponding mapping correlation greater than the mapping correlation threshold, as the database language keyword that matches the first keyword.
[0118] It should be noted that when the server determines the weights based on the attention mechanism layer, it can set the weight between the first keyword and the database language keyword that have a mapping relationship to be the highest, and the weight between the first keyword and the database keyword that do not have a mapping relationship to be the lowest; alternatively, it can set the weight between the first keyword and the database language keyword that have a mapping relationship to be 1, and the weight between the first keyword and the database keyword that do not have a mapping relationship to be 0.
[0119] In this embodiment, the server can determine the weight between the first keyword and each database language keyword based on the attention mechanism layer and keyword mapping relationship, and then determine the correlation mapping degree between the first keyword and each database language keyword, which facilitates the subsequent determination of the database language keyword that matches the first keyword, thereby enabling the conversion of the first keyword into a second keyword that matches the database language environment.
[0120] In an exemplary embodiment, step S104 above, obtaining data structure information from the database, specifically includes the following: obtaining each data table stored in the database; determining the data structure attributes of each data table; determining a first dependency relationship between the data stored in each data table and a second dependency relationship between each data table based on the data structure attributes of each data table; and determining the first dependency relationship and the second dependency relationship as data structure information in the database.
[0121] Among them, data structure attributes are used to characterize the data structure of a data table, such as the attributes contained in the data table and the reference relationships between data tables.
[0122] Specifically, the server first retrieves each data table stored in the database. Then, for each data table, based on the definition of its data structure, it determines the attributes contained in each data table and uses these attributes as the first dependency between the data stored in each data table. Based on the definition of each data table's data structure, it also determines the reference relationships between the data tables and uses these reference relationships as the second dependency between the data tables. Finally, the server combines the first and second dependencies to determine the data structure information in the database.
[0123] For example, suppose the database table "User Car Purchase" includes the attributes "User ID", "Car Name", "Car ID", "Purchase Time", and "Purchase Price". The attributes "Car ID" and "Purchase Price" reference the attributes "Car ID" and "Selling Price" in the table "Garage", respectively. The "Garage" table includes the attributes "Car ID", "Selling Price", and "Brand". The attribute "Brand" references the attribute "Brand Name" in the table "Brand". The "Brand" table includes the attributes "Brand Name" and "Series Name". Then, the data structure information obtained by the server can be visualized as follows: Figure 5 As shown.
[0124] In this embodiment, the server can obtain the database's data structure information based on the dependencies between the data stored in the data tables, as well as the dependencies between the data tables themselves. This is beneficial for generating accurate database language information based on natural language information, thereby improving the reliability of the generated database operation statements.
[0125] In an exemplary embodiment, before receiving the input natural language information for operating the database in step S102, the method further includes the following: displaying a natural language input page including multiple input entries; receiving text input for each input entry, and combining the text according to the order of the input entries to obtain natural language information for operating the database.
[0126] The input entry point is a text input box, and each input entry point corresponds to a key element of natural language information.
[0127] It is understandable that natural language information consists of four key elements: operation action, operation object, problem description, and display content. Correspondingly, database operation statements also consist of four key elements: operation action, operation object, problem description, and display content. Taking the natural language information "Please query the most expensive price in the garage" and the corresponding database operation statement "SELECT MAX(price) FROM garage" as an example, in the natural language information, the operation action is "query", the operation object is "garage", the problem description is "most expensive price", and the display content is "price". In the database operation statement, the operation action is "SELECT", the operation object is "garage", the problem description is "MAX(price)", and the display content is "price".
[0128] Specifically, the server displays a natural language input page with multiple input entry points on the front-end interface, and receives text input for each input entry point through the multiple input entry points on the natural language input page. Then, it combines the text according to the order of the input entry points to obtain natural language information for operating the database.
[0129] For example, such as Figure 6 As shown, the server displays a natural language input page with multiple input fields. Developers can input text by entering it in the input fields or by selecting text from the drop-down menu. Based on the order of the input fields and the text entered in each field, the server obtains the natural language information "Please query the brand of the most expensive car in the garage" for database operations.
[0130] It should be noted that the selection text in the drop-down options is determined by the server based on the data stored in the database; for example, when a developer enters "user purchases a car" in the input field corresponding to the operation object, the server will update the drop-down options corresponding to the input field of the displayed content to user ID, car name, car number, purchase time, and purchase price.
[0131] In this embodiment, by setting multiple input entrances in the natural language input interface, the server can ensure that the natural language information input by the R&D personnel has a certain degree of standardization, which facilitates the server's subsequent recognition of the first and third keywords, as well as the server's conversion of natural language information, and is conducive to the accurate generation of database operation language. In addition, by providing drop-down selection options, the server also simplifies the process of R&D personnel inputting natural language information.
[0132] In one exemplary embodiment, such as Figure 7As shown, another method for generating database operation statements is provided. Taking the application of this method to a server as an example, the steps include:
[0133] Step S701: Display a natural language input page including multiple input entries, receive text input for each input entry, combine the text according to the order of each input entry, and obtain natural language information for operating the database.
[0134] Step S702: Receive input natural language information for operating the database.
[0135] Step S703: Obtain data structure information from the database; based on the pre-trained database statement generation model and the semantic vector corresponding to the natural language information, determine the first associated data table of the natural language information in the database, and the associated data of the natural language information in the first associated data table.
[0136] Step S704: Based on the semantic vector corresponding to the data structure information and the associated data, determine the second associated data table in the database that is associated with the first associated data table.
[0137] Step S705: Based on the first associated data table, associated data, and the second associated data table, obtain the associated data table information associated with the natural language information.
[0138] Step S706: Using a pre-trained database statement generation model, identify the first keyword that meets the preset keyword conditions from the various keywords in the natural language information.
[0139] Step S707: Identify the sub-semantic vector corresponding to the first keyword from the semantic vector corresponding to the natural language information.
[0140] Step S708: Based on the attention mechanism layer in the pre-trained database statement generation model, the sub-semantic vector corresponding to the first keyword, and the keyword mapping relationship, determine the weight of each database language keyword in the database language keyword library corresponding to the first keyword.
[0141] Step S709: Based on the weights, determine the mapping correlation between the first keyword and the language keywords of each database.
[0142] Step S710: Among the various database language keywords, identify the database language keywords whose corresponding mapping relevance meets the preset mapping relevance conditions, and use them as the second keywords that match the first keyword.
[0143] Step S711: Based on the third and second keywords in the natural language information, obtain database language information that matches the database operation language environment.
[0144] Step S712: Based on the information of the associated data table and the database language information, generate database operation statements corresponding to the natural language information.
[0145] In this embodiment, firstly, the server, through a pre-trained database statement generation model, can determine the first associated data table, the second associated data table, and associated data in the database based on database structure information and natural language information. This facilitates subsequent conversion of database language information and generation of database operation statements. Secondly, the server, through the pre-trained database statement generation model, can identify the first keyword that needs conversion and the third keyword that does not need conversion from the natural language information. Through keyword mapping relationships, the first keyword matching the natural language environment is converted into the second keyword matching the database operation language environment. Thus, based on the third and second keywords, database language information matching the database operation language environment is obtained, providing a foundation for subsequent generation of database operation statements based on the database language information. In addition, the server, through the setting of multiple input entrances in the natural language input interface, can ensure that the natural language information input by the researchers has a certain degree of standardization, which facilitates the server's subsequent identification of the first and third keywords and the server's conversion of natural language information, thus contributing to the accurate generation of database operation language. Based on the above process, the database operation statement generation method allows the server to convert the natural language input by developers into a database language that matches the database operation language environment. This eliminates the need for drag-and-drop functionality of visual components in low-code platform-based database operations, simplifying the database operation process and improving its efficiency.
[0146] To more clearly illustrate the database operation statement generation method provided in the embodiments of this application, a specific embodiment is used below to describe the method in detail. However, it should be understood that the embodiments of this application are not limited thereto. In an exemplary embodiment, this application also provides a method for automatically generating database query statements on a low-code platform based on semantic parsing, specifically including the following steps:
[0147] 1. Construct keyword mapping relationships.
[0148] Based on the syntax and logical structure of SQL statements, the server designs a mapping dictionary between natural language keywords and SQL language keywords, and constructs keyword mapping relationships between natural language keywords and SQL language keywords based on the mapping dictionary.
[0149] 2. Obtain data structure information.
[0150] In a database, a data table corresponds to an entity. The data structure of an entity records entity information, field attributes, and relationship information. The server can obtain the dependencies between data in each data table and the dependencies between data tables based on the entity information, thereby obtaining the database's data structure information.
[0151] 3. Receive natural language information.
[0152] The server receives text input from researchers through multiple input points in the natural language input interface and obtains natural language information with a fixed grammatical order and grammatical components.
[0153] 4. Generate database query statements.
[0154] like Figure 8 As shown, the server first performs word vector mapping processing on the natural language information and the data structure information respectively to obtain the word vectors corresponding to the natural language information and the word vectors corresponding to the data structure information. Then, the word vectors corresponding to the natural language information and the word vectors corresponding to the data structure information are input into the semantic expression model. Through the semantic expression model's semantic learning of the word vectors, the semantic vectors corresponding to the natural language information and the semantic vectors corresponding to the data structure information are obtained.
[0155] Then, the server inputs the semantic vectors of natural language information and data structure information into a dual-channel deep model based on a bidirectional long short-term memory artificial neural network. On the one hand, based on the keyword mapping relationship, the natural language information is converted into database language information that matches the database language environment; on the other hand, based on the data structure information, the associated data table information of the natural language information is determined.
[0156] Finally, the server combines the database language information and the related data table information to generate a database query statement corresponding to the natural language information.
[0157] In this embodiment, the server introduces an automatic database query statement generation method in the low-code platform, which helps non-professional R&D personnel to complete relatively complex database query operations, improves the development efficiency of the low-code platform, and enriches the use cases of the low-code platform.
[0158] It should be understood that although the steps in the flowcharts of the embodiments described above are shown sequentially according to the arrows, these steps are not necessarily executed in the order indicated by the arrows. Unless explicitly stated herein, there is no strict order restriction on the execution of these steps, and they can be executed in other orders. Moreover, at least some steps in the flowcharts of the embodiments described above may include multiple steps or multiple stages. These steps or stages are not necessarily completed at the same time, but can be executed at different times. The execution order of these steps or stages is not necessarily sequential, but can be performed alternately or in turn with other steps or at least some of the steps or stages of other steps.
[0159] Based on the same inventive concept, this application also provides a database operation statement generation apparatus for implementing the database operation statement generation method described above. The solution provided by this apparatus is similar to the implementation described in the above method; therefore, the specific limitations in one or more database operation statement generation apparatus embodiments provided below can be found in the limitations of the database operation statement generation method described above, and will not be repeated here.
[0160] In one exemplary embodiment, such as Figure 9 As shown, a database operation statement generation device is provided, including: a language information receiving module 902, an association information confirmation module 904, a language information conversion module 906, and an operation statement generation module 908, wherein:
[0161] The language information receiving module 902 is used to receive input natural language information for operating the database.
[0162] The association information confirmation module 904 is used to obtain data structure information from the database and, based on the data structure information, determine the association data table information in the database that is associated with the natural language information; the data structure information is used to characterize the dependency relationships between the data in each data table in the database.
[0163] The language information conversion module 906 is used to convert natural language information into database language information that matches the database operation language environment.
[0164] The operation statement generation module 908 is used to generate database operation statements corresponding to natural language information based on the information of the related data table and the database language information.
[0165] In an exemplary embodiment, the association information confirmation module 904 is further configured to: determine a first association data table in the database for natural language information and associated data in the first association data table based on a pre-trained database statement generation model and the semantic vector corresponding to the natural language information; determine a second association data table in the database associated with the first association data table based on the semantic vector corresponding to the data structure information and the associated data; and obtain association data table information associated with the natural language information based on the first association data table, the associated data, and the second association data table.
[0166] In an exemplary embodiment, the language information conversion module 906 is further configured to identify a first keyword that meets preset keyword conditions from the keywords in the natural language information using a pre-trained database statement generation model; perform language conversion processing on the first keyword to obtain a second keyword that matches the database operation language environment; and obtain database language information that matches the database operation language environment based on the third keyword and the second keyword in the natural language information; wherein the third keyword is a keyword other than the first keyword among the keywords in the natural language information.
[0167] In an exemplary embodiment, the language information conversion module 906 is further configured to identify the sub-semantic vector corresponding to the first keyword from the semantic vector corresponding to the natural language information; based on the sub-semantic vector corresponding to the first keyword and the keyword mapping relationship, identify the database language keyword matching the first keyword in the database language keyword library that matches the database operation language environment, and use it as the second keyword matching the database operation language environment.
[0168] In an exemplary embodiment, the language information conversion module 906 is further configured to determine the weight of each database language keyword in the database language keyword library corresponding to the first keyword based on the attention mechanism layer in the pre-trained database statement generation model, the sub-semantic vector corresponding to the first keyword, and the keyword mapping relationship; determine the mapping correlation degree between the first keyword and each database language keyword based on the weight; and identify the database language keyword whose corresponding mapping correlation degree satisfies the preset mapping correlation degree condition among the database language keywords, and use it as the database language keyword that matches the first keyword.
[0169] In one exemplary embodiment, the association information confirmation module 904 is further configured to obtain each data table stored in the database; for each data table, determine the data structure attributes of the data table; based on the data structure attributes of each data table, determine the first dependency relationship between the data stored in each data table and the second dependency relationship between each data table; and determine the first dependency relationship and the second dependency relationship as data structure information in the database.
[0170] In one exemplary embodiment, the database operation statement generation device further includes a language information acquisition module, which is used to display a natural language input page including multiple input entrances; receive text input for each input entrance; combine the text according to the order of each input entrance to obtain natural language information for operating the database.
[0171] Each module in the aforementioned database operation statement generation device can be implemented entirely or partially through software, hardware, or a combination thereof. These modules can be embedded in the processor of a computer device in hardware form or independent of it, or stored in the memory of the computer device in software form, so that the processor can call and execute the operations corresponding to each module.
[0172] In one exemplary embodiment, a computer device is provided, which may be a server, and its internal structure diagram may be as follows: Figure 10 As shown, this computer device includes a processor, memory, input / output interfaces (I / O), and a communication interface. The processor, memory, and I / O interfaces are connected via a system bus, and the communication interface is also connected to the system bus via the I / O interfaces. The processor provides computational and control capabilities. The memory includes non-volatile storage media and internal memory. The non-volatile storage media stores the operating system, computer programs, and a database. The internal memory provides the environment for the operating system and computer programs stored in the non-volatile storage media. The database stores database structure information, keyword mapping relationships, and other data. The I / O interfaces are used for exchanging information between the processor and external devices. The communication interface is used for communication with external terminals via a network connection. When executed by the processor, the computer program implements a database operation statement generation method.
[0173] Those skilled in the art will understand that Figure 10 The structure shown is merely a block diagram of a portion of the structure related to the present application and does not constitute a limitation on the computer device to which the present application is applied. Specific computer devices may include more or fewer components than those shown in the figure, or combine certain components, or have different component arrangements.
[0174] In one exemplary embodiment, a computer device is also provided, including a memory and a processor, wherein the memory stores a computer program, and the processor executes the computer program to implement the steps in the above-described method embodiments.
[0175] In one exemplary embodiment, a computer-readable storage medium is provided having a computer program stored thereon that, when executed by a processor, implements the steps in the above-described method embodiments.
[0176] In one exemplary embodiment, a computer program product is provided, including a computer program that, when executed by a processor, implements the steps in the above-described method embodiments.
[0177] Those skilled in the art will understand that all or part of the processes in the methods of the above embodiments can be implemented by a computer program instructing related hardware. The computer program can be stored in a non-volatile computer-readable storage medium, and when executed, it can include the processes of the embodiments of the above methods. Any references to memory, databases, or other media used in the embodiments provided in this application can include at least one of non-volatile and volatile memory. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory, optical memory, high-density embedded non-volatile memory, resistive random access memory (ReRAM), magnetic random access memory (MRAM), ferroelectric random access memory (FRAM), phase change memory (PCM), graphene memory, etc. Volatile memory can include random access memory (RAM) or external cache memory, etc. By way of illustration and not limitation, RAM can take many forms, such as Static Random Access Memory (SRAM) or Dynamic Random Access Memory (DRAM). The databases involved in the embodiments provided in this application may include at least one type of relational database and non-relational database. Non-relational databases may include, but are not limited to, blockchain-based distributed databases. The processors involved in the embodiments provided in this application may be general-purpose processors, central processing units, graphics processing units, digital signal processors, programmable logic devices, quantum computing-based data processing logic devices, etc., and are not limited to these.
[0178] The technical features of the above embodiments can be combined in any way. For the sake of brevity, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.
[0179] The embodiments described above are merely illustrative of several implementation methods of this application, and while the descriptions are specific and detailed, they should not be construed as limiting the scope of this patent application. It should be noted that those skilled in the art can make various modifications and improvements without departing from the concept of this application, and these all fall within the protection scope of this application. Therefore, the protection scope of this application should be determined by the appended claims.
Claims
1. A method for generating database operation statements, characterized in that, The method includes: Receive input natural language information for manipulating the database; Obtain the data structure information from the database, and determine the associated data table information in the database that is related to the natural language information based on the data structure information; the data structure information is used to characterize the dependency relationships between the data in each data table of the database; In addition, the natural language information is converted into database language information that matches the database operation language environment; Based on the associated data table information and the database language information, generate database operation statements corresponding to the natural language information; The step of obtaining the data structure information from the database includes: Retrieve the data tables stored in the database; For each data table, determine the data structure attributes of the data table; Based on the data structure attributes of each data table, determine the first dependency relationship between the data stored in each data table, and the second dependency relationship between the data tables; The first dependency and the second dependency are determined as data structure information in the database; The method further includes: learning word vectors corresponding to natural language information and data structure information respectively through a semantic expression model to obtain semantic vectors corresponding to natural language information and semantic vectors corresponding to data structure information.
2. The method according to claim 1, characterized in that, The step of determining the associated data table information in the database that is related to the natural language information based on the data structure information includes: Based on the pre-trained database statement generation model and the semantic vector corresponding to the natural language information, the first associated data table of the natural language information in the database and the associated data of the natural language information in the first associated data table are determined. Based on the semantic vector corresponding to the data structure information and the associated data, determine the second associated data table in the database that is associated with the first associated data table; Based on the first associated data table, the associated data, and the second associated data table, associated data table information related to the natural language information is obtained.
3. The method according to claim 1, characterized in that, The step of converting the natural language information into database language information that matches the database operation language environment includes: The database statement generation model, which is obtained through pre-training, identifies the first keyword that meets the preset keyword conditions from the keywords of the natural language information. The first keyword is processed by language conversion to obtain a second keyword that matches the database operation language environment; Based on the third keyword and the second keyword in the natural language information, the database language information that matches the database operation language environment is obtained; the third keyword is a keyword other than the first keyword among the keywords in the natural language information.
4. The method according to claim 3, characterized in that, The step of performing language conversion processing on the first keyword to obtain a second keyword that matches the database operation language environment includes: From the semantic vector corresponding to the natural language information, identify the sub-semantic vector corresponding to the first keyword; Based on the sub-semantic vector and keyword mapping relationship corresponding to the first keyword, database language keywords that match the first keyword are identified in the database language keyword library that matches the database operation language environment, and are used as the second keyword that matches the database operation language environment.
5. The method according to claim 4, characterized in that, The step of identifying database language keywords matching the first keyword in a database language keyword library that matches the database operation language environment, based on the sub-semantic vector corresponding to the first keyword and the keyword mapping relationship, includes: Based on the attention mechanism layer in the pre-trained database statement generation model, the sub-semantic vector corresponding to the first keyword, and the keyword mapping relationship, the weight of each database language keyword in the database language keyword library corresponding to the first keyword is determined. Based on the weights, the mapping correlation between the first keyword and each database language keyword is determined; Among the various database language keywords, database language keywords whose corresponding mapping relevance meets the preset mapping relevance conditions are identified and used as database language keywords that match the first keyword.
6. The method according to any one of claims 1 to 5, characterized in that, Before receiving the input natural language information used to manipulate the database, it also includes: The display shows a natural language input page with multiple input options; The system receives text input for each input entry point, combines the text according to the order of the input entries, and obtains the natural language information used to operate the database.
7. A database operation statement generation device, characterized in that, The device includes: The language information receiving module is used to receive input natural language information for database operations; The association information confirmation module is used to obtain data structure information from the database and, based on the data structure information, determine the association data table information in the database that is associated with the natural language information; the data structure information is used to characterize the dependency relationship between the data in each data table in the database. The language information conversion module is used to convert the natural language information into database language information that matches the database operation language environment; The operation statement generation module is used to generate database operation statements corresponding to the natural language information based on the associated data table information and the database language information. The association information confirmation module is also used to obtain each data table stored in the database; for each data table, determine the data structure attributes of the data table; based on the data structure attributes of each data table, determine the first dependency relationship between the data stored in each data table and the second dependency relationship between the data tables; and determine the first dependency relationship and the second dependency relationship as the data structure information in the database. The device further includes: learning word vectors corresponding to natural language information and data structure information respectively through a semantic expression model to obtain semantic vectors corresponding to natural language information and semantic vectors corresponding to data structure information.
8. A computer device comprising a memory and a processor, wherein the memory stores a computer program, characterized in that, When the processor executes the computer program, it implements the steps of the method according to any one of claims 1 to 6.
9. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by a processor, it implements the steps of the method according to any one of claims 1 to 6.
10. A computer program product, comprising a computer program, characterized in that, When the computer program is executed by a processor, it implements the steps of the method according to any one of claims 1 to 6.