A method and related device for converting natural language to SQL statement

By combining database analysis of the ambiguity and uncheckable fields of natural query statements, a clarification request was issued to the user, which solved the problem that SQL statements in the prior art did not meet the user's requirements, and realized the generation of executable SQL statements that meet the user's intentions, improving the conversion Reliability and user experience of the solution.

CN118331996BActive Publication Date: 2024-11-05IFLYTEK (SUZHOU) TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202410770741.1
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-06-14
Publication Date
2024-11-05
Estimated Expiration
2044-06-14

AI Technical Summary

Technical Problem

The conversion scheme of existing natural language to SQL statements does not meet user requirements. It is mainly due to the ambiguity of the user's natural query statement and/or involves uncheckable fields.

Method used

By analyzing whether the user's natural query statement has ambiguity and/or involves unsearchable fields in combination with the data table in the database, a clarification request is issued to the user until a natural query statement that meets the requirements is obtained and then an executable SQL statement is generated. The method includes parsing and conceptual regularization processing, determining the query conditions and specific conceptual values ​​of the object, and modifying temporary SQL statements based on the clarification results to generate the final executable SQL statement.

Benefits of technology

Ensure that the generated SQL statements meet user requirements, improve the reliability and interpretability of the conversion scheme, and enhance the user experience.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118331996B_ABST
    Figure CN118331996B_ABST
Patent Text Reader

Abstract

The present application discloses a method for converting natural language to SQL statements and a related device, which relates to the field of natural language processing and database query technology, wherein the method includes: when obtaining a user's first natural query statement, analyzing whether the first natural query statement is ambiguous and / or involves unsearchable fields in combination with a data table in a database; if the first natural query statement is not ambiguous and does not involve unsearchable fields, generating an executable SQL statement based on the first natural query statement; if the first natural query statement is ambiguous and / or involves unsearchable fields, issuing a clarification request to the user; when obtaining a second natural query statement re-proposed by the user in response to the clarification request, generating an executable SQL statement based on the second natural query statement. Based on the method for converting natural language to SQL statements disclosed in the present application, an SQL statement that meets the user's requirements can be obtained.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the technical field of natural language processing and database query, and in particular to a method for converting natural language to SQL statements and related devices. Background Art

[0002] In modern information systems, databases are important tools for storing and managing data. The data in the database needs to be queried using SQL statements, that is, if a user wants to query the data in the database, he needs to write an SQL statement first. However, writing an SQL statement requires an in-depth understanding of the database structure and query language, which is very difficult for non-professional users. The natural language to SQL statement conversion technology can effectively break down the barriers between users and databases. This technology can understand the user's natural query statements and the database's structural information, and integrate and analyze them to generate SQL statements that can be executed by the database.

[0003] Most of the current natural language to SQL statement conversion solutions are based on conversion models, that is, a large amount of training data (including data table structure information, user's natural query statements, and executable SQL statements corresponding to user's natural query statements) is used to fine-tune the pre-trained model in advance, so that the model learns the mapping from natural language text to executable SQL statements, thereby obtaining a natural language to SQL statement conversion model. Then, when performing a database query, the user's natural query statement is obtained, and the user's natural query statement and data table structure information are input into the trained natural language to SQL statement conversion model to obtain an executable SQL statement.

[0004] Although the current natural language to SQL statement conversion solution can convert the user's natural query statement into an executable SQL statement, in many cases the converted SQL statement does not meet the user's requirements. Summary of the invention

[0005] In view of this, the present application provides a natural language to SQL statement conversion method and related devices to solve the problem that the converted SQL statements often do not meet the user's requirements in the current natural language to SQL statement conversion scheme. The technical solution is as follows:

[0006] The first aspect of the present application provides a method for converting a natural language into an SQL statement, comprising:

[0007] When obtaining a first natural query statement of the user, analyzing whether the first natural query statement is ambiguous and / or involves unsearchable fields in combination with a data table in a database;

[0008] If the first natural query statement has no ambiguity and does not involve unsearchable fields, generating an executable SQL statement according to the first natural query statement;

[0009] If the first natural query statement is ambiguous and / or involves unsearchable fields, a clarification request containing ambiguous information and / or unsearchable fields is issued to the user; when a second natural query statement re-issued by the user in response to the clarification request is obtained, an executable SQL statement is generated based on the second natural query statement.

[0010] In a possible implementation, the method for converting natural language to SQL statements further includes:

[0011] When obtaining a second natural query statement re-proposed by the user in response to the clarification request, analyzing whether the second natural query statement is ambiguous and / or involves unsearchable fields in combination with the data table;

[0012] If the second natural query statement has no ambiguity and does not involve unsearchable fields, the step of generating an executable SQL statement according to the second natural query statement is executed.

[0013] In a possible implementation, analyzing whether the first natural query statement is ambiguous and / or involves unsearchable fields in combination with a data table in a database includes:

[0014] Parsing the first natural query statement in combination with a data table in a database to obtain a parsing result, wherein the parsing result includes a number of query conditions, a number of query objects, table fields corresponding to the number of query conditions, and table fields corresponding to the number of query objects;

[0015] Performing concept regularization processing on the parsing result to obtain a concept regularization result, wherein the concept regularization processing refers to obtaining corresponding elements from the dictionary items of the corresponding table fields for the query conditions corresponding to the table fields whose values ​​are dictionary items in the table fields contained in the parsing result as specific concept values ​​of the query conditions;

[0016] Determine, based on the concept regularization result, whether the first natural query statement is ambiguous and / or involves unsearchable fields;

[0017] The sending of a clarification request containing ambiguous information and / or unsearchable fields to the user includes:

[0018] Based on the concept regularization result, a clarification request containing ambiguous information and / or unsearchable fields is issued to the user.

[0019] In a possible implementation, determining, according to the concept regularization result, whether the first natural query statement is ambiguous and / or involves unsearchable fields includes:

[0020] If at least one of the query conditions corresponds to multiple table fields, or at least one of the query objects corresponds to multiple table fields, it is determined that the first natural query statement is ambiguous.

[0021] If at least one of the query conditions corresponds to an empty table field, or at least one of the query objects corresponds to an empty table field, it is determined that the first natural query statement involves an unsearchable field.

[0022] In a possible implementation, generating an executable SQL statement according to the first natural query statement includes:

[0023] An executable SQL statement is generated based on the first natural query statement and in combination with the concept regularization result.

[0024] In a possible implementation, generating an executable SQL statement according to the first natural query statement and in combination with the concept regularization result includes:

[0025] Inputting the first natural query statement into a pre-trained natural language to SQL conversion model to obtain a temporary SQL statement output by the natural language to SQL conversion model;

[0026] Generate an executable SQL statement according to the temporary SQL statement and the concept regularization result.

[0027] In a possible implementation, generating an executable SQL statement according to the temporary SQL statement and the concept regularization result includes:

[0028] Parsing the temporary SQL statement into a syntax tree;

[0029] The temporary SQL statement is processed into an executable SQL statement according to the syntax tree and the concept regularization result.

[0030] In a possible implementation, the processing of the temporary SQL statement into an executable SQL statement according to the syntax tree and the concept regularization result includes:

[0031] Determine a target node by traversing the syntax tree, wherein the target node is a node representing a query condition whose value of a corresponding table field is a dictionary item;

[0032] Obtaining a specific concept value of the query condition represented by the target node from the concept regularization result;

[0033] According to the storage form of the value of the table field corresponding to the query condition represented by the target node in the database and the specific concept value of the query condition represented by the target node, the temporary SQL statement is modified to obtain an executable SQL statement.

[0034] In a possible implementation, the method for converting natural language to SQL statements further includes:

[0035] Interpreting the temporary SQL statement to obtain an interpretation result;

[0036] The interpretation result and the concept regularization result are displayed so that the user can determine whether the executable SQL statement meets the requirements based on the interpretation result and the concept regularization result.

[0037] In a possible implementation, the method for converting natural language to SQL statements further includes:

[0038] If the user modifies the interpretation result, the concept regularization result is modified according to the interpretation result modified by the user to obtain a modified concept regularization result;

[0039] Regenerate a temporary SQL statement according to the modified interpretation result of the user;

[0040] Regenerate an executable SQL statement based on the regenerated temporary SQL statement and the modified concept regularization result.

[0041] A second aspect of the present application provides a natural language to SQL statement conversion device, comprising: an analysis and processing module and an SQL statement generation module;

[0042] The analysis and processing module is used for, when obtaining a first natural query statement of a user, analyzing whether the first natural query statement is ambiguous and / or involves unsearchable fields in combination with a data table in a database, and if the first natural query statement is ambiguous and / or involves unsearchable fields, sending a clarification request containing ambiguous information and / or unsearchable fields to the user;

[0043] The SQL statement generation module is used to generate an executable SQL statement based on the first natural query statement when there is no ambiguity in the first natural query statement and when no unsearchable fields are involved; and to generate an executable SQL statement based on a second natural query statement re-proposed by the user in response to the clarification request when there is ambiguity in the first natural query statement and / or when an unsearchable field is involved.

[0044] In a possible implementation, the analysis and processing module includes: a semantic understanding module, a concept regularization module and an agent module;

[0045] The semantic understanding module is used to parse the first natural query statement in combination with the data table in the database to obtain a parsing result, wherein the parsing result includes a number of query conditions, a number of query objects, table fields corresponding to the query conditions respectively, and table fields corresponding to the query objects respectively;

[0046] The concept regularization module is used to perform concept regularization processing on the parsing result to obtain a concept regularization result, wherein the concept regularization processing refers to obtaining corresponding elements from the dictionary items of the corresponding table fields for the query conditions corresponding to the table fields whose values ​​are dictionary items in the table fields contained in the parsing result as the specific concept values ​​of the query conditions;

[0047] The intelligent agent module is used to determine whether the first natural query statement is ambiguous and / or involves unsearchable fields based on the concept regularization results. If the first natural query statement is ambiguous and / or involves unsearchable fields, a clarification request containing ambiguous information and / or unsearchable fields is issued to the user based on the concept regularization results.

[0048] A third aspect of the present application provides an electronic device, comprising at least one processor and a memory connected to the processor, wherein:

[0049] The memory is used to store computer programs;

[0050] The processor is used to execute the computer program so that the electronic device can implement the steps of any one of the above-mentioned methods for converting natural language into SQL statements.

[0051] In a fourth aspect, the present application provides a computer storage medium, which carries one or more computer programs. When the one or more computer programs are executed by an electronic device, the electronic device can implement the steps of any one of the above-mentioned natural language to SQL statement conversion methods.

[0052] A fifth aspect of the present application provides a computer program product, comprising computer-readable instructions, which, when executed on an electronic device, enables the electronic device to implement the steps of any one of the above-mentioned methods for converting a natural language into a SQL statement.

[0053] By means of the above technical scheme, the natural language to SQL statement conversion method provided by the present application does not directly convert the natural query statement into an executable SQL statement when obtaining the natural query statement of the user, but first analyzes the natural query statement of the user in combination with the data table in the database to see whether there is ambiguity and / or involves unsearchable fields. If the natural query statement of the user is not ambiguous and does not involve unsearchable fields, the natural query statement of the user is converted into an executable SQL statement. If the natural query statement of the user is ambiguous and / or involves unsearchable fields, a clarification request containing ambiguous information and / or unsearchable fields is issued to the user to request the user to clarify. When the natural query statement re-proposed by the user in response to the clarification request is obtained, the natural query statement re-proposed by the user in response to the clarification request is converted into an executable SQL statement. The natural language to SQL statement conversion method provided by the present application can obtain an executable SQL statement that meets the user's requirements. BRIEF DESCRIPTION OF THE DRAWINGS

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

[0055] Figure 1 A schematic diagram of a hardware structure of a terminal provided in an embodiment of the present application;

[0056] Figure 2 A schematic diagram of a hardware structure of a server provided in an embodiment of the present application;

[0057] Figure 3 A flowchart of a method for converting a natural language into an SQL statement provided in an embodiment of the present application;

[0058] Figure 4 A flowchart of an embodiment of the present application for analyzing, when obtaining a first natural query statement of a user, whether the first natural query statement is ambiguous and / or involves unsearchable fields in combination with a data table in a database;

[0059] Figure 5 A flowchart of generating an executable SQL statement according to a first natural query statement and a concept regularization result corresponding to the first natural query statement provided in an embodiment of the present application;

[0060] Figure 6 A schematic diagram of the structure of a natural language to SQL statement conversion device provided in an embodiment of the present application. DETAILED DESCRIPTION

[0061] The following describes the embodiments of the present application in conjunction with the drawings in the embodiments of the present application. The terms used in the implementation method section of the present application are only used to explain the specific embodiments of the present application, and are not intended to limit the present application.

[0062] The embodiments of the present application are described below in conjunction with the accompanying drawings. Those skilled in the art will appreciate that, with the development of technology and the emergence of new scenarios, the technical solutions provided in the embodiments of the present application are also applicable to similar technical problems.

[0063] The terms "first", "second", etc. in the specification and claims of the present application and the above-mentioned drawings are used to distinguish similar objects, and need not be used to describe a specific order or sequential order. It should be understood that the terms used in this way can be interchangeable under appropriate circumstances, which is only to describe the distinction mode adopted by the objects of the same attributes when describing in the embodiments of the present application. In addition, the terms "including" and "having" and any of their variations are intended to cover non-exclusive inclusions, so that the process, method, system, product or equipment comprising a series of units need not be limited to those units, but may include other units that are not clearly listed or inherent to these processes, methods, products or equipment.

[0064] Before introducing the natural language to SQL statement conversion method provided by the present application, the system architecture involved in the present application is first explained.

[0065] In one possible implementation, the system architecture involved in the present application may include a terminal and a server, that is, the natural language to SQL statement conversion method provided by the present application can be implemented based on the terminal and the server. In another possible implementation, the system architecture involved in the present application may include a terminal, that is, the natural language to SQL statement conversion method provided by the present application can be implemented based on the terminal.

[0066] Next, the product form of the above-mentioned terminal is described.

[0067] The above-mentioned terminal can be a mobile phone, a tablet computer, a wearable device, a vehicle-mounted device, an augmented reality (AR) / virtual reality (VR) device, a laptop computer, an ultra-mobile personal computer (UMPC), a netbook, a personal digital assistant (PDA), etc., and the embodiments of the present application do not impose any restrictions on this.

[0068] Figure 1 An optional hardware structure diagram of a terminal is shown.

[0069] refer to Figure 1As shown, the terminal may include a radio frequency unit 110, a memory 120, an input unit 130, a display unit 140, a camera 150 (optional), an audio circuit 160 (optional), a speaker 161 (optional), a microphone 162 (optional), an earphone jack 163 (optional), a processor 170, an external interface 180, a power supply 190 and other components. Those skilled in the art will appreciate that Figure 1 This is merely an example of a terminal and does not constitute a limitation on the terminal. The terminal may include more or fewer components than shown in the figure, or a combination of certain components, or different components.

[0070] The input unit 130 can be used to receive input digital or character information, and generate key signal input related to the user settings and function control of the terminal. Specifically, the input unit 130 may include a touch screen 131 (optional) and / or other input devices 132. The touch screen 131 can collect the user's touch operations on or near it (such as the user's operation on or near the touch screen using any suitable object such as fingers, joints, stylus, etc.), and drive the corresponding connection device according to a pre-set program. The touch screen can detect the user's touch action on the touch screen, convert the touch action into a touch signal and send it to the processor 170, and can receive and execute the command sent by the processor 170; the touch signal at least includes the touch point coordinate information. The touch screen 131 can provide an input interface and an output interface between the terminal and the user. In addition, the touch screen can be implemented using multiple types such as resistive, capacitive, infrared, and surface acoustic waves. In addition to the touch screen 131, the input unit 130 can also include other input devices. Specifically, other input devices 132 may include, but are not limited to, one or more of a physical keyboard, function keys (such as a volume control key, a switch key, etc.), a trackball, a mouse, a joystick, and the like.

[0071] The display unit 140 may be used to display information input by a user or information provided to a user, various menus of the terminal, an interactive interface, file display, and / or playback of any multimedia file.

[0072] The memory 120 can be used to store instructions and data. The memory 120 can mainly include an instruction storage area and a data storage area. The data storage area can store various data, such as multimedia files, texts, etc.; the instruction storage area can store software units such as operating systems, applications, instructions required for at least one function, or their subsets and extensions. It can also include a non-volatile random access memory; provide the processor 170 with hardware, software and data resources including management of computing and processing equipment, and support control software and applications. It is also used for the storage of multimedia files, and the storage of running programs and applications.

[0073] The processor 170 is the control center of the terminal. It uses various interfaces and lines to connect various parts of the entire terminal. By running or executing instructions stored in the memory 120 and calling data stored in the memory 120, it executes various functions of the terminal and processes data, thereby controlling the terminal device as a whole. Optionally, the processor 170 may include one or more processing units; preferably, the processor 170 may integrate an application processor and a modem processor, wherein the application processor mainly processes the operating system, user interface and application program, and the modem processor mainly processes wireless communication. It is understandable that the above-mentioned modem processor may not be integrated into the processor 170. In some embodiments, the processor and the memory may be implemented on a single chip, and in some embodiments, they may also be implemented separately on separate chips. The processor 170 may also be used to generate corresponding operation control signals, send them to corresponding components of the computing and processing device, read and process data in the software, especially read and process data and programs in the memory 120, so that each functional module therein performs corresponding functions, thereby controlling the corresponding components to act according to the requirements of the instructions.

[0074] Among them, the memory 120 can be used to store software codes related to the conversion method from natural language to SQL statements. The processor 170 can call the software codes stored in the memory 120, and can also schedule other units (such as the above-mentioned input unit 130 and display unit 140) to implement corresponding functions.

[0075] The radio frequency unit 110 (optional) can be used to receive and send information or receive and send signals during a call. For example, after receiving the downlink information of the base station, it is sent to the processor 170 for processing; in addition, the designed uplink data is sent to the base station. Generally, the radio frequency unit 110 includes but is not limited to an antenna, at least one amplifier, a transceiver, a coupler, a low noise amplifier (LowNoiseAmplifier, LNA), a duplexer, etc. In addition, the radio frequency unit 110 can also communicate with network devices and other devices through wireless communication. The wireless communication can use any communication standard or protocol, including but not limited to Global System of Mobile communication (Global System of Mobile communication, GSM), General Packet Radio Service (General PacketRadio Service, GPRS), Code Division Multiple Access (Code Division Multiple Access, CDMA), Wideband Code Division Multiple Access (Wideband Code Division Multiple Access, WCDMA), Long Term Evolution (Long Term Evolution, LTE), email, Short Messaging Service (SMS), etc.

[0076] In the embodiment of the present application, the radio frequency unit 110 can send data to other devices, and can also receive data sent by other devices. It should be understood that the radio frequency unit 110 is optional, and can be replaced by other communication interfaces, such as a network port.

[0077] The terminal also includes a power supply 190 (such as a battery) for supplying power to various components. Preferably, the power supply can be logically connected to the processor 170 through a power management system, so that the power management system can manage charging, discharging, power consumption and other functions.

[0078] The terminal also includes an external interface 180, which may be a standard Micro USB interface or a multi-pin connector, and may be used to connect the terminal to communicate with other devices, or to connect a charger to charge the terminal.

[0079] Although not shown, the terminal may further include a flashlight, a wireless fidelity (WiFi) module, a Bluetooth module, sensors with different functions, etc., which will not be described in detail here.

[0080] Next, the product form of the above server is described.

[0081] Figure 2 A structural diagram of the above server is provided, such as Figure 2As shown, the server includes a bus 201, a processor 202, a communication interface 203 and a memory 204. The processor 202, the memory 204 and the communication interface 203 communicate with each other via the bus 201.

[0082] The bus 201 may be a peripheral component interconnect (PCI) bus or an extended industry standard architecture (EISA) bus. The bus may be divided into an address bus, a data bus, a control bus, etc. For ease of representation, Figure 2 Only one thick line is used in the diagram, but this does not mean that there is only one bus or only one type of bus.

[0083] The processor 202 may be any one or more of a central processing unit (CPU), a graphics processing unit (GPU), a microprocessor (MP), or a digital signal processor (DSP).

[0084] The memory 204 may include a volatile memory, such as a random access memory (RAM). The memory 204 may also include a non-volatile memory, such as a read-only memory (ROM), a flash memory, a hard drive (HDD), or a solid state drive (SSD).

[0085] The memory 204 may be used to store software codes related to the method of converting natural language into SQL statements, and the processor 202 may call the software codes stored in the memory 204 or schedule other units to implement corresponding functions.

[0086] It should be understood that the above-mentioned terminals and servers can be centralized or distributed devices, and the processors in the above-mentioned terminals and servers (such as processor 170 and processor 202) can be hardware circuits (such as application specific integrated circuits (ASIC), field-programmable gate arrays (FPGA), general-purpose processors, digital signal processors (DSP), microprocessors or microcontrollers, etc.), or a combination of these hardware circuits. For example, the processor can be a hardware system with an instruction execution function, such as a CPU, DSP, etc., or a hardware system without an instruction execution function, such as an ASIC, FPGA, etc., or a combination of the above-mentioned hardware systems without an instruction execution function and hardware systems with an instruction execution function.

[0087] In the process of implementing this case, it was found that in actual business scenarios, users' natural query statements are often ambiguous and / or involve unsearchable fields. For example, in the existing character information table, the fields in the character information table include "ID number", "name", For the four fields of "contact information" and "occupation", the user's natural query statement is "help me check the name, ID number and income of all people whose occupation is intermediary". Since the character information table does not contain the field of "income status", the user's natural query statement involves searchable and unsearchable fields. For another example, in the existing event table, the fields of the event table include four fields: "event ID", "event name", "event type", and "event cause". Among them, the values ​​of "event type" and "event cause" are both dictionary items. Assume that the value of "event type" is [online shopping problem, physical store shopping problem,...], and the value of event cause is [payment problem, return problem,...], the user's query statement is "help me check recent events about problems with goods during shopping". Since the "problems with goods" in the user's natural query statement can correspond to "online shopping problem" in the value of "event type", it can also correspond to "return problem" in the value of "event cause", the user's natural query statement is ambiguous.

[0088] The current natural language to SQL conversion solutions only focus on understanding natural query statements and data table structures, without considering that users' natural query statements are often ambiguous and / or involve unsearchable fields. As a result, the SQL statements obtained based on the current natural language to SQL conversion solutions often do not meet user requirements.

[0089] In view of the problems existing in the current natural language to SQL conversion scheme, research has been conducted, and through continuous research, a natural language to SQL statement conversion method with better effect is finally proposed. Next, the natural language to SQL statement conversion method provided by this application is introduced through the following embodiments.

[0090] See also Figure 3 , shows a flow chart of a method for converting a natural language into a SQL statement provided in an embodiment of the present application, the method may include:

[0091] Step S301: when a user's first natural query statement is obtained, the first natural query statement is analyzed in combination with a data table in a database to determine whether it is ambiguous and / or involves unsearchable fields.

[0092] The first natural query statement can be parsed in conjunction with the data table in the database to obtain a parsing result including the query condition, the query object, and the table fields corresponding to the query condition and the query object respectively. After obtaining the parsing result, the parsing result can be further processed for concept regularization to clarify the specific concept value of the query condition. Furthermore, it can be determined whether the first natural query statement is ambiguous and / or involves unsearchable fields based on the concept regularization result.

[0093] Step S302a: If the first natural query statement has no ambiguity and does not involve unsearchable fields, an executable SQL statement is generated according to the first natural query statement.

[0094] When the first natural query statement has no ambiguity and does not involve unsearchable fields, the first natural query statement is directly converted into an SQL statement.

[0095] Step S302b: If the first natural query statement is ambiguous and / or involves unsearchable fields, a clarification request containing ambiguous information and / or unsearchable fields is sent to the user.

[0096] When the first natural query statement is ambiguous and / or involves unsearchable fields, the first natural query statement is not converted into an SQL statement, but a clarification request containing ambiguous information and / or unsearchable fields is issued to the user to request the user to clarify.

[0097] Step S303b: when a second natural query statement re-proposed by the user in response to the clarification request is obtained, an executable SQL statement is generated according to the second natural query statement.

[0098] When the user obtains a clarification request, a natural query statement will be re-issued in response to the clarification request. Since the clarification request contains ambiguous information and / or unsearchable fields, the natural query statement re-issued by the user in response to the clarification request is usually not ambiguous and does not involve unsearchable fields. In view of this, in a possible implementation, when the user's second natural query statement is obtained, the second natural query statement can be directly converted into an executable SQL statement.

[0099] Taking into account that the natural query statement re-proposed by the user in response to the clarification request may still be ambiguous and / or involve unsearchable fields at some point, in order to ensure that an executable SQL statement that meets the user's requirements can be ultimately generated, in another possible implementation, after obtaining the second natural query statement, the second natural query statement can be first analyzed in combination with the data table in the database to determine whether it is ambiguous and / or involves unsearchable fields; if the second natural query statement is not ambiguous and does not involve unsearchable fields, the second natural query statement is converted into an executable SQL statement; if the second natural query statement is ambiguous and / or involves unsearchable fields, a clarification request containing ambiguous information and / or unsearchable fields can be issued to the user again to request the user to clarify, until a natural query statement that is not ambiguous and does not involve unsearchable fields is obtained.

[0100] The method for converting natural language to SQL statements provided in the embodiment of the present application does not directly convert the natural query statement into an executable SQL statement when obtaining the user's natural query statement, but first analyzes the user's natural query statement in combination with the data table in the database to see whether it is ambiguous and / or involves unsearchable fields. If the user's natural query statement is not ambiguous and does not involve unsearchable fields, the user's natural query statement is converted into an executable SQL statement. If the user's natural query statement is ambiguous and / or involves unsearchable fields, a clarification request containing ambiguous information and / or unsearchable fields is issued to the user to request the user to clarify. When the natural query statement re-proposed by the user in response to the clarification request is obtained, the natural query statement re-proposed by the user in response to the clarification request is converted into an executable SQL statement. The method for converting natural language to SQL statements based on the embodiment of the present application can obtain executable SQL statements that meet user requirements.

[0101] In another embodiment of the present application, the specific implementation process of "Step S301: when obtaining the user's first natural query statement, analyzing whether the first natural query statement is ambiguous and / or involves unsearchable fields in combination with the data table in the database" in the above embodiment is introduced.

[0102] See also Figure 4, shows a flow chart of analyzing whether the first natural query statement of the user is ambiguous and / or involves unsearchable fields in combination with a data table in a database when the first natural query statement of the user is obtained, which may include:

[0103] Step S401: when a first natural query statement of a user is obtained, the first natural query statement is parsed in combination with a data table in a database to obtain a parsing result corresponding to the first natural query statement.

[0104] The parsing result includes a number of query conditions, a number of query objects, table fields corresponding to the query conditions, and table fields corresponding to the query objects.

[0105] In this embodiment, the process of parsing the first natural query statement in combination with the data table in the database may include: extracting semantic fragments from the first natural query statement; after obtaining a number of semantic fragments, distinguishing query conditions and query objects for the obtained semantic fragments, thereby obtaining a number of query conditions and a number of query objects; after obtaining a number of query conditions and a number of query objects, the table fields corresponding to the query conditions and the table fields corresponding to the query objects may be determined from the table fields included in the data table. Through the above process, a parsing result including a number of query conditions, a number of query objects, the table fields corresponding to the query conditions and the table fields corresponding to the query objects may be obtained.

[0106] Next, taking the user's first natural query statement as "Incidents that occurred this year regarding problems with goods during shopping, what are the genders, ages, jobs, and incomes of the parties involved?" and the data table being Table 1 below as an example, the process of parsing the first natural query statement in combination with the data table is further explained.

[0107] Table 1 Data table example

[0108]

[0109] First, semantic segments are extracted from the user's first natural query sentence "Incidents that occurred this year regarding problems with goods during shopping, what are the gender, age, work situation, and income of the parties involved?", and "this year", "problems with goods", "gender", "age", "work situation", and "income situation" are obtained. Then, the obtained semantic segments are distinguished by query conditions and query objects, among which "this year" and "problems with goods" are query conditions, and "gender", "age", "work situation", and "income situation" are query objects. Then, the table fields corresponding to the query conditions and the table fields corresponding to the query objects are determined from the table fields contained in Table 1. The table fields corresponding to the query condition "this year" are "event_time" in the event table, the table fields corresponding to the query condition "problems with goods" are "event_type" and "reason" in the event table, the table fields corresponding to the query object "gender" are "gender" in the character information table, and the table fields corresponding to the query object "age situation" are "birthday" in the character information table. The table field corresponding to the query object "work situation" is "occupation" in the character information table, and there is no corresponding table field for the query object "income situation" (that is, the table field corresponding to the query object "income situation" is an empty field). Through the above process, the table fields corresponding to several query conditions ("this year", "there are problems with the goods"), several query objects ("gender", "age situation", "work situation", "income situation"), and several query conditions ("this year", "there are problems with the goods") and the table fields corresponding to several query objects ("gender", "age situation", "work situation", "income situation") can be obtained. The following Table 2 shows an example of the presentation form of the analysis result.

[0110] Table 2 Analysis result example

[0111]

[0112] Among them, "condition" indicates the query condition, "select_column" indicates the query object, Key&Value indicates the specific content of the query condition or query object, "event.event_time" indicates the "event_time" field in the event table "event", and the same applies to "event.event_type" and "event.reason". "person.gender" indicates the "gender" field in the person information table "person", and the same applies to "person.birthday" and "person.occupation". It should be noted that "null" in the columns where "Key" and "Value" are located means that the value is empty, and "null" in the column where "Table.Column" is located means an empty field, that is, there is no corresponding table field.

[0113] Step S402: performing concept regularization processing on the parsing result corresponding to the first natural query statement to obtain a concept regularization result corresponding to the first natural query statement.

[0114] The concept regularization processing refers to obtaining corresponding elements from the dictionary items of the corresponding table fields as the specific concept values ​​of the query conditions corresponding to the table fields whose values ​​are dictionary items in the table fields contained in the parsing results.

[0115] The values ​​of some table fields in the data table may be dictionary items, and the dictionary items may be multi-level. For example, the occupation field in the personnel table has values ​​including agent / real estate agent, agent / financial agent, agent / human resource agent, student / middle school student, student / college student, etc. The dictionary items of the occupation field in this example are divided into two levels. Users may query the first level (for example, "query people whose occupation is agent") or the second level (for example, "query people whose occupation is college student"). The current natural language to SQL conversion solution has the problem of inaccurate understanding of concepts (for example, it is impossible to accurately match the query conditions with the elements in the dictionary items of the field). In order to generate SQL statements that meet user requirements, this application aligns the query conditions corresponding to the table fields whose values ​​are dictionary items in the table fields contained in the parsing results to the corresponding elements in the dictionary items of the corresponding table fields to clarify the specific concept values ​​of the query conditions.

[0116] In the above example, the table fields corresponding to the query condition "there are problems with the goods" are "event.event_type" and "event.reason". Refer to Table 1. The values ​​of "event.event_type" and "event.reason" are both dictionary items. Therefore, "there are problems with the goods" is aligned to the corresponding elements in the dictionary items. For example, "there are problems with the goods" is aligned to "online shopping problems" in the dictionary item of "event.event_type", and "there are problems with the goods" is aligned to "return problems" in the dictionary item of "event.reason". "Online shopping problems" is the specific concept value of "there are problems with the goods" on "event.event_type", and "return problems" is the specific concept value of "there are problems with the goods" on "event.reason".

[0117] By conceptually regularizing the analytical results in Table 2 above, we can obtain the conceptual regularization results shown in Table 3 below.

[0118] Table 3 Example of concept regularization results

[0119]

[0120] The concept regularization result corresponding to the first natural query statement includes the parsing result corresponding to the first natural query statement and the specific concept value of the query condition corresponding to the table field whose value is a dictionary item in the parsing result corresponding to the first natural query statement.

[0121] Step S403: Determine whether the first natural query statement is ambiguous and / or involves unsearchable fields based on the concept regularization result corresponding to the first natural query statement.

[0122] Specifically, based on the concept regularization result corresponding to the first natural query statement, the process of determining whether the first natural query statement is ambiguous and / or involves unsearchable fields may include: determining whether at least one of several query conditions corresponds to multiple table fields, or whether at least one of several query objects corresponds to multiple table fields. If at least one of several query conditions corresponds to multiple table fields, or at least one of several query objects corresponds to multiple table fields, then it is determined that the first natural query statement is ambiguous; otherwise, it is determined that the first natural query statement is not ambiguous; determining whether at least one of several query conditions corresponds to an empty field, or whether at least one of several query objects corresponds to an empty field. If at least one of several query conditions corresponds to an empty field, or at least one of several query objects corresponds to an empty field, then it is determined that the first natural query statement involves unsearchable fields. Otherwise, it is determined that the first natural query statement does not involve unsearchable fields.

[0123] For the example of the first natural query statement above, "For incidents that occurred this year regarding problems with goods during shopping, what are the gender, age, work situation, and income of the parties involved?", according to Table 3, there are two fields corresponding to the query condition "problems with goods". Therefore, the first natural query statement is ambiguous. Since the query object "income situation" corresponds to an empty field, the first natural query statement involves unsearchable fields.

[0124] If the first natural query statement is ambiguous and / or involves unsearchable fields, a clarification request containing ambiguous information and / or unsearchable fields may be issued to the user based on the concept regularization result corresponding to the first natural query statement.

[0125] For the example of the first natural query sentence above, "For incidents involving problems with goods during shopping that occurred this year, what is the gender, age, work situation, and income of the parties involved?", since it is ambiguous and involves unsearchable fields, the following clarification request can be issued based on the concept regularization results in Table 3:

[0126] "There are ambiguities in your query, and fields that cannot be queried, please check:

[0127] 1. There is a problem with the goods: You may be referring to the event type as an online shopping problem, or the event reason as a return problem;

[0128] 2. Income: This field does not exist in your database. "

[0129] When a user receives a clarification request, a natural query statement can be re-proposed for the clarification request, such as "In the online shopping incidents that occurred this year, what is the gender, age, and work status of the parties involved?" Then, an executable SQL statement can be generated based on the natural query statement re-proposed by the user for the clarification request.

[0130] If it is determined that the first natural query statement has no ambiguity and does not involve unsearchable fields, an executable SQL statement is generated according to the first natural query statement.

[0131] In another embodiment of the present application, a specific implementation process of generating an executable SQL statement according to a first natural query statement is described.

[0132] In one possible implementation, after obtaining the concept regularization result corresponding to the first natural query statement and determining that the first natural query statement is not ambiguous and does not involve unsearchable fields, an executable SQL statement can be generated based on the first natural query statement and the concept regularization result corresponding to the first natural query statement.

[0133] In another possible implementation, after obtaining the concept regularization result corresponding to the first natural query statement and determining that the first natural query statement has no ambiguity and does not involve unsearchable fields, the concept regularization result corresponding to the first natural query statement can be displayed to the user first so that the user can observe whether there are any problems with the concept regularization result. If there are any problems, the user can modify the concept regularization result. For the concept regularization result in Table 3, assuming that the user proposes that "there is a problem with the goods" should correspond to the event cause field, and the regularization value is "return problem", then Table 3 is updated to the following Table 4. If the user modifies the concept regularization result, the concept regularization result modified by the user is used as the final concept regularization result, and then an executable SQL statement is generated based on the first natural query statement and the final concept regularization result.

[0134] Table 4 Example of modified concept regularization results

[0135]

[0136] Next, the implementation process of generating an executable SQL statement based on the first natural query statement and the concept regularization result corresponding to the first natural query statement is introduced.

[0137] See also Figure 5 , showing a flow chart of generating an executable SQL statement according to a first natural query statement and a concept regularization result corresponding to the first natural query statement, which may include:

[0138] Step S501: Generate a temporary SQL statement according to the first natural query statement.

[0139] In a possible implementation, the first natural query statement may be input into a pre-trained natural language to SQL conversion model, and the natural language to SQL conversion model generates a temporary SQL statement according to the first natural query statement. In this embodiment, the natural language to SQL conversion model may be a small Seq-to-Seq model or a large model.

[0140] In order to reduce the difficulty and length of SQL statement generation, the natural language to SQL conversion model in this embodiment does not consider concept regularization or the storage form of table fields. It should be noted that in actual business scenarios, there are two storage forms for table field values ​​in data tables, one is plain text storage and the other is coded storage. Taking the table field "event_type" as an example, for plain text storage, the value of the table field "event_type" is stored in plain text in the database. For coded storage, the encoding of the value of the table field "event_type" will be stored in the data, and the mapping relationship between the encoding and the plain text will be stored in a dedicated data table.

[0141] An example of a temporary SQL statement generated by the solution provided by the present application is given below. At the same time, an example of an SQL statement generated by an existing solution is also given for comparison.

[0142] Assuming that the first natural query statement is "query events whose event type is online shopping, export id, event name and time", and the value of the event type is stored in plain text in the database, the SQL statements generated by using the existing solution and the solution provided by this application are shown in the following table:

[0143] Table 5 SQL statement examples

[0144]

[0145] By comparison, it is not difficult to find that the length of the SQL statement generated by the solution provided by the present application is similar to that of the SQL statement generated by the existing solution. However, it should be noted that the existing solution is used to directly generate the final executable SQL statement (the natural language to SQL conversion model in the existing solution directly generates the final executable SQL statement). Since the model in the existing solution needs to perform concept regularization in the process of generating SQL statements, and the model is very prone to errors in concept regularization, the final generated SQL statement does not meet the user's requirements. The present application does not directly generate the final executable SQL statement, but first generates a temporary SQL statement (the natural language to SQL conversion model in the solution provided by the present application generates a temporary SQL statement). The generation of the temporary SQL statement does not consider the dictionary items behind the field (that is, concept regularization is not considered), and the SQL statement is directly generated according to the user's natural query statement, that is, the present application separates concept regularization from the process of generating SQL statements by the model.

[0146] Assuming that the first natural query statement is "query events whose event type is online shopping, export id, event name and time", and the value of the event type is stored in the database in a coded manner, the SQL statements generated by using the existing solution and the solution provided by the present application are shown in the following table:

[0147] Table 6 SQL statement examples

[0148]

[0149] When the value of the event type is stored in the database as a code, by comparing the SQL statements generated by the existing solution and the solution provided by the present application, it can be seen that in addition to the problems mentioned above, the existing solution needs to perform an additional joint query with the coding table ("code" in Table 6), and the length of the SQL statement generated by it is nearly twice as long as the SQL statement generated by the solution provided by the present application. In other words, it is more difficult for the model in the existing solution to generate SQL statements, while it is less difficult for the model in the present application to generate SQL statements.

[0150] Since the natural language to SQL conversion model in the present application does not require concept regularization or a joint coding table in the process of generating temporary SQL statements, it is relatively easy to generate SQL statements.

[0151] Step S502: Generate an executable SQL statement according to the concept regularization result corresponding to the temporary SQL statement and the first natural query statement.

[0152] After obtaining the temporary SQL statement in step S501, step S502 processes the temporary SQL statement into an executable SQL statement. When processing the temporary SQL statement into the executable SQL statement, the concept regularization result corresponding to the first natural query statement is referred to.

[0153] In a possible implementation, the process of generating an executable SQL statement according to the concept regularization result corresponding to the temporary SQL statement and the first natural query statement may include:

[0154] Step S5021: Parse the temporary SQL statement into a syntax tree.

[0155] Step S5022: Process the temporary SQL statement into an executable SQL statement according to the concept regularization result corresponding to the syntax tree and the first natural query statement.

[0156] In one possible implementation, the process of processing a temporary SQL statement into an executable SQL statement based on the concept regularization results corresponding to the syntax tree and the first natural query statement may include: determining a target node by traversing the syntax tree, wherein the target node is a node representing a query condition whose value is a dictionary item in the corresponding table field; obtaining the specific concept value of the query condition represented by the target node from the concept regularization results corresponding to the first natural query statement; modifying the temporary SQL statement based on the storage form in the database of the value of the field corresponding to the query condition represented by the target node and the specific concept value of the query condition represented by the target node to obtain an executable SQL statement.

[0157] Exemplarily, the first natural query statement is "query events whose event type is online shopping, export id, event name and time". The temporary SQL statement generated according to the natural query statement is the SQL statement in the second column of Table 5. After parsing it into a syntax tree, the node representing the query condition "online shopping" can be determined by traversing the syntax tree, and the specific concept value of "online shopping" is obtained from the concept regularization result. Assuming that the specific concept value of "online shopping" is "online shopping problem", the temporary SQL statement is modified according to the storage form of the value of "event type" in the database and the specific concept value of "online shopping" to obtain the final executable SQL statement.

[0158] Table 7 Examples of temporary SQL statements and executable SQL statements

[0159]

[0160] Table 8 Examples of temporary SQL statements and executable SQL statements

[0161]

[0162] Table 7 is an example of a temporary SQL statement and a final executable SQL statement generated for the first natural query statement when the value of the event type is stored in plain text in the database. Table 8 is an example of a temporary SQL statement and a final executable SQL statement generated for the first natural query statement when the value of the event type is stored in encoding in the database.

[0163] Through step S502, the temporary SQL statement can be processed into a final executable SQL statement. Through the above process, it is not difficult to find that compared with the existing solution, the solution of the present application omits the table join (JOIN) operation.

[0164] In addition, it should be noted that the above-mentioned embodiment focuses on the implementation process of analyzing whether the first natural query statement is ambiguous and / or involves unsearchable fields in combination with the data table in the database, and also focuses on the implementation process of generating an executable SQL statement based on the first natural query statement. The implementation process of analyzing whether the second natural query statement is ambiguous and / or involves unsearchable fields in combination with the data table in the database is similar to the implementation process of analyzing whether the first natural query statement is ambiguous and / or involves unsearchable fields in combination with the data table in the database, and the embodiments of the present application will not be repeated here. The implementation process of generating an executable SQL statement based on the second natural query statement is similar to the implementation process of generating an executable SQL statement based on the first natural query statement, and the embodiments of the present application will not be repeated here.

[0165] In another embodiment of the present invention, the method for converting natural language to SQL statements may also include: after obtaining an executable SQL statement for a first natural query statement, querying based on the executable SQL statement to obtain a query result; after obtaining the query result, the query result may be displayed to a user.

[0166] Optionally, the method for converting natural language to SQL statements may also include: interpreting a temporary SQL statement to obtain an interpretation result; displaying the interpretation result and a concept regularization result corresponding to the first natural query statement, so that the user can determine whether the executable SQL statement meets the requirements based on the interpretation result and the concept regularization result.

[0167] Considering that in some application scenarios, the query results have more content and it is difficult for users to verify the query results. Therefore, users can verify the executable SQL statements. However, it is very difficult for non-professional users to verify the executable SQL statements. In view of this, the present application can interpret the temporary SQL statements (since the temporary SQL statements are generated according to the user's natural query statements, they are closer to natural language in form and easier to interpret), and then display the interpretation results to the user. Since the final executable SQL statement is generated based on the temporary SQL statement with reference to the concept regularization result corresponding to the first natural query statement, the concept regularization result corresponding to the first natural query statement can be displayed at the same time for the user's reference when verifying. Table 9 below shows an example of a temporary SQL statement and the interpretation result of the temporary SQL statement.

[0168] Table 9 Examples of temporary SQL statements and their interpretation results

[0169]

[0170] If the user finds that there is a problem with the interpretation result, the user can modify it. After the user modifies the interpretation result, the concept regularization result corresponding to the first natural query statement can be modified according to the user's modified interpretation result. Then, according to the user's modified interpretation result, a temporary SQL statement can be regenerated. Based on the regenerated temporary SQL statement and combined with the modified concept regularization result, an executable SQL statement can be regenerated, and a query can be performed based on the regenerated executable SQL statement.

[0171] It should be noted that in addition to being displayed after obtaining the query results, the interpretation results can also be displayed before generating executable SQL statements. If the user finds that there is no problem with the interpretation results, an executable SQL statement is generated based on the temporary SQL statement and the concept regularization result corresponding to the first natural query statement. If the user finds that there is a problem with the interpretation results, the user can modify it. After the user modifies the interpretation results, the concept regularization result corresponding to the first natural query statement can be modified according to the user's modified interpretation results. Then, based on the user's modified interpretation results, a temporary SQL statement is regenerated, and an executable SQL statement is generated based on the regenerated temporary SQL statement and the modified concept regularization result.

[0172] The natural language to SQL conversion method provided in the embodiment of the present application solves the problem that the converted SQL statement does not meet the user's requirements due to ambiguity in the user's natural query statement and / or involvement of unsearchable fields. In addition, the natural language to SQL conversion method provided in the embodiment of the present application makes the process of understanding the user's intention transparent by interacting with the user, greatly improves the reliability and interpretability of the conversion solution, and provides a good user experience.

[0173] The above introduces the method for converting natural language to SQL statements provided in the embodiment of the present application. The following will introduce the device corresponding to the above method for converting natural language to SQL statements.

[0174] See also Figure 6 , Figure 6 A schematic diagram of the structure of a natural language to SQL statement conversion device provided in an embodiment of the present application, the natural language to SQL statement conversion device may include: an analysis and processing module 601 and an SQL statement generation module 602.

[0175] The analysis and processing module 601 is used to analyze whether the first natural query statement of the user is ambiguous and / or involves unsearchable fields in combination with the data table in the database when obtaining the first natural query statement of the user. If the first natural query statement is ambiguous and / or involves unsearchable fields, a clarification request containing ambiguous information and / or unsearchable fields is issued to the user.

[0176] The SQL statement generation module 601 is used to generate an executable SQL statement based on the first natural query statement when the first natural query statement is not ambiguous and does not involve unsearchable fields; and to generate an executable SQL statement based on the second natural query statement when a second natural query statement re-proposed by the user in response to a clarification request is obtained when the first natural query statement is ambiguous and / or involves unsearchable fields.

[0177] In a possible implementation, the analysis and processing module 601 may include: a semantic understanding module, a concept regularization module and an agent module, wherein the agent module is responsible for interacting with the user.

[0178] The semantic understanding module is used to parse the first natural query statement in combination with the data table in the database to obtain a parsing result, wherein the parsing result includes a number of query conditions, a number of query objects, table fields corresponding to the query conditions respectively, and table fields corresponding to the query objects respectively.

[0179] The concept regularization module is used to perform concept regularization processing on the parsing results to obtain concept regularization results, wherein concept regularization processing refers to obtaining corresponding elements from the dictionary items of the corresponding table fields as the specific concept values ​​of the query conditions corresponding to the table fields whose values ​​are dictionary items in the table fields contained in the parsing results.

[0180] The intelligent agent module is used to determine whether the first natural query statement is ambiguous and / or involves unsearchable fields based on the concept regularization results. If the first natural query statement is ambiguous and / or involves unsearchable fields, a clarification request containing ambiguous information and / or unsearchable fields is issued to the user based on the concept regularization results.

[0181] In a possible implementation, the analysis and processing module 601 is further configured to analyze, in conjunction with the data table, whether the second natural query statement is ambiguous and / or involves unsearchable fields when obtaining the second natural query statement re-proposed by the user in response to the clarification request.

[0182] The SQL statement generating module 601 is specifically configured to generate an executable SQL statement according to the second natural query statement if the second natural query statement has no ambiguity and does not involve unsearchable fields.

[0183] In a possible implementation, when the agent module determines whether the first natural query statement is ambiguous and / or involves unsearchable fields based on the concept regularization result, it is specifically configured to:

[0184] If at least one of the query conditions among the plurality of query conditions corresponds to multiple table fields, or at least one of the query objects among the plurality of query objects corresponds to multiple table fields, it is determined that the first natural query statement is ambiguous;

[0185] If at least one of the query conditions among the plurality of query conditions corresponds to a table field that is an empty field, or at least one of the query objects among the plurality of query objects corresponds to a table field that is an empty field, it is determined that the first natural query statement involves an unsearchable field.

[0186] In a possible implementation, when the SQL statement generating module 601 generates an executable SQL statement according to the first natural query statement, it is specifically used to:

[0187] Based on the first natural query statement and combined with the concept regularization result, an executable SQL statement is generated.

[0188] In a possible implementation, when the SQL statement generation module 601 generates an executable SQL statement according to the first natural query statement and in combination with the concept regularization result, it is specifically used to:

[0189] Inputting the first natural query statement into a pre-trained natural language to SQL conversion model to obtain a temporary SQL statement output by the natural language to SQL conversion model;

[0190] Generate executable SQL statements based on temporary SQL statements and concept regularization results.

[0191] In a possible implementation, when the SQL statement generation module 601 generates an executable SQL statement according to the temporary SQL statement and the concept regularization result, it is specifically used to:

[0192] Parse the temporary SQL statement into a syntax tree;

[0193] According to the syntax tree and concept regularization results, the temporary SQL statement is processed into an executable SQL statement.

[0194] In a possible implementation, when the SQL statement generation module 601 processes the temporary SQL statement into an executable SQL statement according to the syntax tree and the concept regularization result, it is specifically used to include:

[0195] Determine a target node by traversing the syntax tree, wherein the target node is a node representing a query condition whose value of a corresponding table field is a dictionary item;

[0196] Obtain the specific concept value of the query condition represented by the target node from the concept regularization result;

[0197] According to the storage form of the value of the table field corresponding to the query condition represented by the target node in the database and the specific concept value of the query condition represented by the target node, the temporary SQL statement is modified to obtain an executable SQL statement.

[0198] In a possible implementation, the agent module is further used to:

[0199] Interpret the temporary SQL statement and obtain the interpretation result;

[0200] The interpretation results and concept regularization results are displayed so that users can determine whether the executable SQL statements meet the requirements based on the interpretation results and concept regularization results.

[0201] In a possible implementation, the SQL statement generating module 601 is further used to:

[0202] Modify the concept regularization result according to the interpretation result modified by the user to obtain a modified concept regularization result;

[0203] Regenerate temporary SQL statements based on the interpretation results modified by the user;

[0204] Regenerate executable SQL statements based on the regenerated temporary SQL statements and the modified concept regularization results.

[0205] The natural language to SQL statement conversion device provided in the embodiment of the present application can convert the user's natural query statement into an executable SQL statement that meets the user's requirements. In addition, the natural language to SQL conversion device provided in the embodiment of the present application makes the process of understanding the user's intention transparent by interacting with the user, greatly improving the reliability and interpretability of the device, and providing a good user experience.

[0206] An embodiment of the present application also provides an electronic device, which may include: at least one processor, at least one communication interface, at least one memory and at least one communication bus.

[0207] In the embodiment of the present application, the number of the processor, the communication interface, the memory, and the communication bus is at least one, and the processor, the communication interface, and the memory communicate with each other through the communication bus;

[0208] The processor may be a central processing unit (CPU), or an application-specific integrated circuit (ASIC), or one or more integrated circuits configured to implement the embodiments of the present application;

[0209] The memory 503 may include a high-speed RAM memory, and may also include a non-volatile memory, such as at least one disk memory;

[0210] The memory stores a program, and the processor can call the program stored in the memory, and the program is used to implement the steps of the method for converting natural language to SQL statements provided in the above embodiment.

[0211] An embodiment of the present application also provides a computer storage medium, which carries one or more computer programs. When the one or more computer programs are executed by an electronic device, the electronic device can implement the steps of the natural language to SQL statement conversion method provided in the above embodiment.

[0212] An embodiment of the present application also provides a computer program product, including computer-readable instructions. When the computer-readable instructions are executed on an electronic device, the electronic device implements the steps of the method for converting natural language to SQL statements provided in the above embodiment.

[0213] It should also be noted that the device embodiments described above are merely schematic, wherein the units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place, or they may be distributed over multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the scheme of this embodiment. In addition, in the drawings of the device embodiments provided by the present application, the connection relationship between the modules indicates that there is a communication connection between them, which may be specifically implemented as one or more communication buses or signal lines.

[0214] Through the description of the above implementation mode, the technicians in the field can clearly understand that the present application can be implemented by means of software plus necessary general hardware, and of course, it can also be implemented by special hardware including special integrated circuits, special CPUs, special memories, special components, etc. In general, all functions completed by computer programs can be easily implemented by corresponding hardware, and the specific hardware structure used to implement the same function can also be various, such as analog circuits, digital circuits or special circuits. However, for the present application, software program implementation is a better implementation mode in more cases. Based on such an understanding, the technical solution of the present application is essentially or the part that contributes to the prior art can be embodied in the form of a software product, which is stored in a readable storage medium, such as a computer floppy disk, a U disk, a mobile hard disk, a ROM, a RAM, a disk or an optical disk, etc., including a number of instructions to enable a computer device (which can be a personal computer, a training device, or a network device, etc.) to execute the methods described in each embodiment of the present application.

[0215] In the above embodiments, all or part of the embodiments may be implemented by software, hardware, firmware or any combination thereof. When implemented by software, all or part of the embodiments may be implemented in the form of a computer program product.

[0216] The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, the process or function described in the embodiment of the present application is generated in whole or in part. The computer may be a general-purpose computer, a special-purpose computer, a computer network, or other programmable devices. The computer instructions may be stored in a computer-readable storage medium, or transmitted from one computer-readable storage medium to another computer-readable storage medium. For example, the computer instructions may be transmitted from a website site, a computer, a training device, or a data center by wired (e.g., coaxial cable, optical fiber, digital subscriber line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.) mode to another website site, computer, training device, or data center. The computer-readable storage medium may be any available medium that a computer can store or a data storage device such as a training device, a data center, etc. that includes one or more available media integrations. The available medium may be a magnetic medium, (e.g., a floppy disk, a hard disk, a tape), an optical medium (e.g., a DVD), or a semiconductor medium (e.g., a solid-state drive (SSD)), etc.

Claims

1. A method for converting natural language to SQL statements, characterized in that: include: When obtaining a first natural query statement of the user, analyzing whether the first natural query statement is ambiguous and / or involves unsearchable fields in combination with a data table in a database; The analyzing whether the first natural query statement is ambiguous and / or involves unsearchable fields in combination with the data table in the database includes: parsing the first natural query statement in combination with the data table in the database to obtain a parsing result; performing concept regularization processing on the parsing result to obtain a concept regularization result, wherein the concept regularization processing refers to obtaining corresponding elements from the dictionary items of the corresponding table fields as specific concept values ​​of the query conditions corresponding to the table fields whose values ​​are dictionary items in the table fields contained in the parsing result; and determining whether the first natural query statement is ambiguous and / or involves unsearchable fields based on the concept regularization result; If the first natural query statement has no ambiguity and does not involve unsearchable fields, generating an executable SQL statement according to the first natural query statement; If the first natural query statement is ambiguous and / or involves unsearchable fields, a clarification request containing ambiguous information and / or unsearchable fields is issued to the user according to the concept regularization result; when a second natural query statement re-issued by the user in response to the clarification request is obtained, an executable SQL statement is generated according to the second natural query statement; The step of generating an executable SQL statement according to the first natural query statement includes: Inputting the first natural query statement into a pre-trained natural language to SQL conversion model to obtain a temporary SQL statement output by the natural language to SQL conversion model, wherein the generation process of the temporary SQL statement does not need to perform concept regularization and joint coding table processes; An executable SQL statement is generated according to the temporary SQL statement and the concept regularization result, wherein the concept regularization result is obtained by performing concept regularization processing on the parsing result corresponding to the first natural query statement.

2. The method for converting natural language to SQL statements according to claim 1, characterized in that: Also includes: When obtaining a second natural query statement re-proposed by the user in response to the clarification request, analyzing whether the second natural query statement is ambiguous and / or involves unsearchable fields in combination with the data table; If the second natural query statement has no ambiguity and does not involve unsearchable fields, the step of generating an executable SQL statement according to the second natural query statement is executed.

3. The method for converting natural language to SQL statements according to claim 1, characterized in that: The parsing result includes a number of query conditions, a number of query objects, table fields corresponding to the query conditions respectively, and table fields corresponding to the query objects respectively.

4. The method for converting natural language to SQL statements according to claim 3, characterized in that: The determining, according to the concept regularization result, whether the first natural query statement is ambiguous and / or involves unsearchable fields includes: If at least one of the query conditions corresponds to multiple table fields, or at least one of the query objects corresponds to multiple table fields, it is determined that the first natural query statement is ambiguous. If at least one of the query conditions corresponds to an empty table field, or at least one of the query objects corresponds to an empty table field, it is determined that the first natural query statement involves an unsearchable field.

5. The method for converting natural language to SQL statements according to claim 1, characterized in that: The step of generating an executable SQL statement according to the temporary SQL statement and the concept regularization result includes: Parsing the temporary SQL statement into a syntax tree; According to the syntax tree and the concept regularization result, the temporary SQL statement is processed into an executable SQL statement.

6. The method for converting natural language to SQL statements according to claim 5, characterized in that: The processing of the temporary SQL statement into an executable SQL statement according to the syntax tree and the concept regularization result includes: Determine a target node by traversing the syntax tree, wherein the target node is a node representing a query condition whose value of a corresponding table field is a dictionary item; Obtaining a specific concept value of the query condition represented by the target node from the concept regularization result; According to the storage form of the value of the table field corresponding to the query condition represented by the target node in the database and the specific concept value of the query condition represented by the target node, the temporary SQL statement is modified to obtain an executable SQL statement.

7. The method for converting natural language to SQL statements according to claim 1, characterized in that: Also includes: Interpreting the temporary SQL statement to obtain an interpretation result; The interpretation result and the concept regularization result are displayed so that the user can determine whether the executable SQL statement meets the requirements based on the interpretation result and the concept regularization result.

8. The method for converting natural language to SQL statements according to claim 7, characterized in that: Also includes: If the user modifies the interpretation result, the concept regularization result is modified according to the interpretation result modified by the user to obtain a modified concept regularization result; Regenerate a temporary SQL statement according to the modified interpretation result of the user; Regenerate an executable SQL statement based on the regenerated temporary SQL statement and the modified concept regularization result.

9. A natural language to SQL statement conversion device, characterized in that: include: Analysis and processing module and SQL statement generation module; The analysis and processing module is used for, when obtaining a first natural query statement of a user, analyzing whether the first natural query statement is ambiguous and / or involves unsearchable fields in combination with a data table in a database, and if the first natural query statement is ambiguous and / or involves unsearchable fields, sending a clarification request containing ambiguous information and / or unsearchable fields to the user; The SQL statement generation module is configured to generate an executable SQL statement according to the first natural query statement when the first natural query statement is not ambiguous and does not involve unsearchable fields; and, when a second natural query statement re-proposed by the user in response to the clarification request is obtained and the second natural query statement is ambiguous and / or involves unsearchable fields, generate an executable SQL statement according to the second natural query statement; The SQL statement generation module generates an executable SQL statement according to the first natural query statement, including: The SQL statement generation module inputs the first natural query statement into a pre-trained natural language to SQL conversion model to obtain a temporary SQL statement output by the natural language to SQL conversion model, wherein the generation process of the temporary SQL statement does not need to perform concept regularization and joint coding table processes; generates an executable SQL statement according to the temporary SQL statement and the concept regularization result, wherein the concept regularization result is obtained by performing concept regularization processing on the parsing result corresponding to the first natural query statement; The analysis and processing module includes: a semantic understanding module, a concept regularization module and an intelligent agent module; The semantic understanding module is used to parse the first natural query statement in combination with the data table in the database to obtain a parsing result; The concept regularization module is used to perform concept regularization processing on the parsing result to obtain a concept regularization result, wherein the concept regularization processing refers to obtaining corresponding elements from the dictionary items of the corresponding table fields for the query conditions corresponding to the table fields whose values ​​are dictionary items in the table fields contained in the parsing result as the specific concept values ​​of the query conditions; The intelligent agent module is used to determine whether the first natural query statement is ambiguous and / or involves unsearchable fields based on the concept regularization results. If the first natural query statement is ambiguous and / or involves unsearchable fields, a clarification request containing ambiguous information and / or unsearchable fields is issued to the user based on the concept regularization results.

10. The natural language to SQL statement conversion device according to claim 9, characterized in that: The parsing result includes a number of query conditions, a number of query objects, table fields corresponding to the query conditions respectively, and table fields corresponding to the query objects respectively.

11. An electronic device, characterized in that: The method comprises at least one processor and a memory connected to the processor, wherein: The memory is used to store computer programs; The processor is used to execute the computer program so that the electronic device can implement the steps of the method for converting a natural language into an SQL statement as described in any one of claims 1 to 8.

12. A computer storage medium, characterized in that: The storage medium carries one or more computer programs, and when the one or more computer programs are executed by an electronic device, the electronic device can implement the steps of the natural language to SQL statement conversion method as described in any one of claims 1 to 8.

13. A computer program product, characterized in that It includes computer-readable instructions, and when the computer-readable instructions are executed on an electronic device, the electronic device implements the steps of the method for converting a natural language into a SQL statement as described in any one of claims 1 to 8.