Natural language conversion method and device and computer equipment
By obtaining and simplifying the structural information of large-scale databases, combining the predictive correlation of BERT model, SQL statements are generated, and the accuracy and success rate of natural language conversion in large-scale databases are solved, and efficient query result generation is achieved.
Patent Information
- Application Number
- CN202311873483.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-12-29
- Publication Date
- 2025-07-08
AI Technical Summary
When facing large-scale databases, the problem of SQL statement generation errors caused by excessive database information in the prior art is that it is impossible to effectively convert user natural language query statements.
By obtaining the structure information of the database, simplifying it with query statements, processing the database information in batches, using the BERT model to predict correlation, and generating SQL statements that can be recognized by the target database.
It improves the success rate and accuracy of natural language conversion, prevents erroneous conversion caused by loss of structural information, and ensures the accuracy of query results.
Smart Images

Figure CN120277090A_ABST
Abstract
Description
Technical Field
[0001] The embodiments of the present application belong to the technical field of semantic recognition, and particularly relate to a natural language conversion method, apparatus, and computer device. Background Art
[0002] Text2SQL is a technology that converts a user's natural language into an executable SQL statement. By applying Text2SQL, it is convenient for an operating object to better understand the true idea contained in the user's natural language and execute it accordingly. Exemplarily, for a database, a user can use natural language to express the idea of querying certain information in the database. By converting the user's natural language into an SQL statement that the database can recognize, the database can find the corresponding information and feedback it to the user.
[0003] However, when facing a large-scale database, since there are extremely many data tables stored in the database and each data table includes a very large number of fields (columns), if the natural language used by the user is converted in the manner of the existing technology, it may exceed the maximum length limit due to excessive database information, and a correct SQL statement cannot be generated. Summary of the Invention
[0004] In view of this, the embodiments of the present application provide a natural language conversion method, apparatus, and computer device to solve the problems existing in the prior art, which can simplify the structure information of a large-scale database and perform natural language conversion based on the simplified structure information to improve the efficiency and accuracy of conversion.
[0005] The first aspect of the embodiments of the present application provides a natural language conversion method, including:
[0006] Receiving a query statement for querying a target database input in natural language;
[0007] Obtaining the structure information of the target database, where the structure information is information that describes the data stored in the target database in a structured language;
[0008] Simplifying the structure information based on the query statement;
[0009] Generating a database statement recognizable by the target database according to the query statement and the simplified structure information.
[0010] The second aspect of the embodiments of the present application provides a natural language conversion apparatus, including:
[0011] A receiving module, configured to receive a query statement for querying a target database input in natural language;
[0012] An acquisition module, configured to acquire structure information of the target database, where the structure information is information describing the data stored in the target database in a structured language;
[0013] A simplification module, configured to simplify the structure information based on the query statement;
[0014] A generation module, configured to generate a database statement recognizable by the target database according to the query statement and the simplified structure information.
[0015] A third aspect of the embodiments of the present application provides a computer device, including a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, the natural language conversion method described in the first aspect above is implemented.
[0016] A fourth aspect of the embodiments of the present application provides a computer-readable storage medium storing a computer program, where when the computer program is executed by a processor, the natural language conversion method described in the first aspect above is implemented.
[0017] A fifth aspect of the embodiments of the present application provides a computer program product, which when running on a computer causes the computer to execute the natural language conversion method described in the first aspect above.
[0018] Compared with the prior art, the embodiments of the present application have the following beneficial effects:
[0019] Applying the natural language conversion method provided by the embodiments of the present application, after a computer device receives a query statement for querying a target database input in natural language, it can acquire the structure information of the target database, where the structure information is information describing the data stored in the target database in a structured language. When facing a large-scale database, the quantity of the above-acquired structure information of the target database may be large, exceeding the maximum quantity of the structure information that the model can process. Therefore, the computer device can simplify the structure information based on the query statement, and generate a corresponding database statement according to the query statement and the simplified structure information. The computer device can use this database statement to query in the target database to obtain the data that the user actually expects to query. Applying the method provided by the embodiments of the present application, the computer device can prevent the adverse effects on natural language conversion caused by the loss of several items in the structure information by simplifying the structure information of the database, which helps to improve the success rate and accuracy of natural language conversion. Description of the Drawings
[0020] To more clearly illustrate the technical solutions in the embodiments of the present application, the following will briefly introduce the accompanying drawings required in the description of the embodiments or the prior art. Obviously, the accompanying drawings in the following description are only some embodiments of the present application. For those of ordinary skill in the art, other drawings can be obtained based on these drawings without creative efforts.
[0021] Figure 1 It is a schematic diagram of a natural language conversion method provided by an embodiment of the present application;
[0022] Figure 2 It is a schematic diagram of another natural language conversion method provided by an embodiment of the present application;
[0023] Figure 3 It is a schematic diagram of predicting relevance provided by an embodiment of the present application;
[0024] Figure 4 It is a schematic diagram of an implementation manner of S206 in a natural language conversion method provided by an embodiment of the present application;
[0025] Figure 5 It is a schematic diagram of a natural language conversion process provided by an embodiment of the present application;
[0026] Figure 6 It is a schematic diagram of a natural language conversion device provided by an embodiment of the present application;
[0027] Figure 7 It is a schematic diagram of a computer device provided by an embodiment of the present application. Detailed implementation manners
[0028] In the following description, for the purpose of illustration rather than limitation, specific details such as specific system structures and technologies are presented to thoroughly understand the embodiments of the present application. However, those skilled in the art should clearly understand that the present application can also be implemented in other embodiments without these specific details. In other cases, the detailed descriptions of well-known systems, devices, circuits, and methods are omitted to avoid unnecessary details from interfering with the description of the present application.
[0029] Generally, when applying the Text2SQL technology to convert the natural language input by the user into an SQL statement, it is necessary to splice the natural language with the sorted database information, and then input the spliced statement into the Text2SQL model, and the Text2SQL model completes the subsequent conversion process. However, various databases in the real world usually have complex structures, the number of data tables stored in the database is large, and each data table includes multiple fields (multiple columns). It is extremely difficult to sort out the information of such a large-scale database, and the resources consumed are also relatively large. On the other hand, most models have certain limitations on the length of the input information. If the natural language and database information are spliced in the manner described above, it may lead to a relatively long spliced information, so that the dimension of the input data of the Text2SQL model exceeds the limit of the model itself for the number of tokens, resulting in incomplete input of database information. In this way, since the data processed by the Text2SQL model itself is incomplete, the final SQL statement output by the model may also be incorrect.
[0030] In view of the above problems, the embodiment of the present application provides a natural language conversion method, which can simplify the structure information of the database in combination with the query statement after obtaining the structure information of the database, reduce the data processing volume of the subsequent model, improve the success rate and accuracy of natural language conversion, and facilitate obtaining an SQL statement that matches the actual needs of the user.
[0031] The technical solution of the present application will be described below through specific embodiments.
[0032] Refer to Figure 1 , which shows a schematic diagram of a natural language conversion method provided by an embodiment of the present application, and specifically may include the following steps:
[0033] S101. Receive a query statement for querying a target database input in natural language.
[0034] This method can be applied to a computer device, that is, the execution subject of the embodiment of the present application is a computer device. By executing each step in the natural language conversion method provided by the embodiment of the present application, the computer device can simplify the structure information of the database, and then generate a language that can be recognized by the operating object in combination with the natural language input by the user and the simplified structure information. For example, convert natural language into SQL language. SQL language is a structured query language applied to databases. Using SQL language, data can be quickly queried in the database to obtain corresponding data records.
[0035] In a possible implementation manner of the embodiment of the present application, the computer device can be an electronic device such as a mobile phone, a tablet computer, or a desktop computer. The computer device can be communicatively connected to a database, and the user can obtain the data to be queried from the database by interacting with the computer device. That is, the computer device can provide an interaction interface for interacting with the user. For example, the interaction operation can be an operation of inputting a query statement in the form of natural language. The interaction operation of the user on the interaction interface can be received and processed by the computer device, and the processed interaction operation can be transmitted to the database, and the database executes the operation corresponding to the interaction operation. For example, the database queries a certain type of data and returns the corresponding query result. The query result can be displayed to the user through the interaction interface of the computer device.
[0036] In the embodiment of the present application, the target database can refer to the database corresponding to the interaction operation of the user on the computer device. Exemplarily, if the user hopes to query a certain type of data, the database storing this type of data is the target database. The target database can be a single database or can include multiple databases, and the quantity thereof can be determined according to the actual requirements of the query, and the embodiment of the present application does not limit this.
[0037] The query statement input by the user in natural language can refer to the original query statement input by the user on the computer device. In a possible implementation manner, the user can directly input a query statement in text form on the computer device; or, the user can also speak the query statement to the computer device in a voice manner, and after the computer device receives the voice information input by the user, it can convert the voice information into text form to obtain a query statement in text form. The embodiment of the present application does not limit the specific manner of how the user inputs the query statement.
[0038] Exemplarily, the query statement can be "What is the number of cases per month?"
[0039] S102. Obtain the structure information of the target database, where the structure information is information describing the data stored in the target database in a structured language.
[0040] In the embodiment of the present application, the structure information of the database can be information describing the data stored in the database in a structured language.
[0041] Exemplarily, the database stores basic information of various cases, including the basic information of each case, the occurrence time, the affiliated community, etc. These basic information can be described in a structured language to obtain the structure information of the database.
[0042] In a possible implementation manner of the embodiments of the present application, the structure information of the database can be obtained by reading the field names and stored data of each field in each data table in the database and processing them. Alternatively, the structure information of the database can also be obtained by acquiring the description information of the database and analyzing the description information. The embodiments of the present application do not limit this. The above description information can be information that provides a general introduction to the data stored in the database.
[0043] S103. Simplify the structure information based on the query statement.
[0044] In the embodiments of the present application, since the scale of the database is large, there are many data tables stored in the database, and each data table contains a very large number of fields. Processing such a large amount of information at the same time is very likely to cause the processed data to exceed the limit of the input token quantity of the model. Therefore, the database information can be processed in batches in combination with the query statement input by the user.
[0045] In a possible implementation manner of the embodiments of the present application, the structure information of the database can be simplified with a single data table as a dimension. Since the data stored in a single data table is relatively limited and the number of fields in the data table is also relatively small, simplifying with a single data table as a dimension can avoid the problem of loss of structure information caused by too many fields.
[0046] Therefore, for the structure information of the target database obtained in step S102, the computer device can divide the structure information into multiple sub-information according to the dimension of a single data table. Each sub-information is respectively used to describe the data stored in a data table.
[0047] In another possible implementation manner of the embodiments of the present application, if the number of fields in a single data table still exceeds the limit, the computer device can also split the information of a single data table into multiple times and process them separately.
[0048] S104. Generate a database statement recognizable by the target database according to the query statement and the simplified structure information.
[0049] In the embodiments of the present application, the computer device can generate a database statement recognizable by the target database according to the user's query statement and the simplified structure information. Exemplarily, the database statement can be an SQL statement.
[0050] In a possible implementation manner of the embodiments of the present application, the computer device can splice the query statement and the simplified structure information, and use the Text2SQL model to process the spliced information to generate the corresponding SQL statement.
[0051] In another possible implementation manner of the embodiment of the present application, since the computer device may process the structure information of the target database with a single data table as a dimension, the obtained simplified structure information may correspondingly include multiple pieces of information. When the computer device generates an SQL statement according to the query statement and the simplified structure information, it may splice the query statement with each piece of simplified structure information, and then use the Text2SQL model to process the spliced information to generate the corresponding SQL statement. In this way, the actually obtained SQL statements may include multiple ones. The computer device may execute the above multiple SQL statements in the database, so as to find the data that meets the actual needs of the user in the database.
[0052] In the embodiment of the present application, after receiving a query statement for querying the target database input in natural language, the computer device may obtain the structure information of the target database, and the structure information may be information that describes the data stored in the target database in a structured language. When facing a large-scale database, the quantity of the obtained structure information of the target database may be relatively large, exceeding the maximum quantity of the structure information that the model can process. Therefore, the computer device may simplify the structure information based on the query statement, and generate the corresponding database statement according to the query statement and the simplified structure information. The computer device may use the database statement to query in the target database to obtain the data that the user actually expects to query. By applying the method provided in the embodiment of the present application, the computer device can prevent the adverse effects on natural language conversion caused by the loss of several items in the structure information by simplifying the structure information of the database, which helps to improve the success rate and accuracy of natural language conversion.
[0053] Refer to Figure 2 , which shows a schematic diagram of another natural language conversion method provided by the embodiment of the present application, and may specifically include the following steps:
[0054] S201. Receive a query statement for querying the target database input in natural language.
[0055] In the embodiment of the present application, the target database may refer to the database corresponding to the interactive operation of the user on the computer device. The target database may be a single database or may include multiple databases. The query statement may refer to the statement input by the user on the computer device, and the query statement may be input into the computer device in the form of text or voice information. For a query statement in voice form, the computer device may use speech-to-text technology to convert it into a query statement in text form.
[0056] S202. Obtain the structure information of the target database, where the structure information is information that describes the data stored in the target database in a structured language.
[0057] In an embodiment of the present application, the structure information of the database can be obtained by reading the field names and the stored data of each field in each data table in the database and processing them. Alternatively, the structure information of the database can also be obtained by obtaining the description information of the database and analyzing the description information. The embodiment of the present application does not limit this. The above description information can be information that provides a general introduction to the data stored in the database.
[0058] In a possible implementation manner of the embodiment of the present application, the structure information of the target database can also be obtained by obtaining the table structure information of multiple data tables stored in the target database and generating it according to the table structure description information of each data table.
[0059] Generally, a database can include multiple data tables. Different data can be stored in each data table, and each data table can also include table structure description information. Among them, the table structure description information can be information that provides a general description of the data stored in the data table in the database.
[0060] In a possible implementation manner of the embodiment of the present application, the table structure description information can exist independently. Exemplarily, the table structure description information can include the data table name, the column names of each column of data included in the data table, and the value range of each column of data, etc. Each data table can have a copy of the table structure description information respectively; or, multiple data tables can share a copy of the table structure description information. When storing data into a data table, the table structure description information can be updated synchronously. The computer device can obtain the structure information of the database by reading the table structure information of each data table and processing it.
[0061] S203. Divide the structure information into multiple sub-information.
[0062] When the target database is a large-scale database, the number of information items included in its structure information is usually large. When converting a query statement into an SQL statement in combination with the structure information, it is easy to cause loss of database information due to reasons such as the number of information items exceeding the quantity limit that the model can handle. For example, information about some data tables or some fields in the data tables is lost. In this way, a correct SQL statement cannot be generated.
[0063] In an embodiment of the present application, in order to reduce the possibility of information item overrun in database structure information, a computer device may divide the database structure information into multiple sub-information for processing. Specifically, the computer device may determine the data tables to which each information item in the database structure information belongs, divide each information item belonging to the same data table into the same sub-information, and then process the structure information of each data table separately. Among them, each sub-information is the structure information corresponding to a data table.
[0064] S204. Determine the relevance between the query statement and each information item in any one of the sub-information respectively.
[0065] In an embodiment of the present application, the query statement may be concatenated with each information item in the sub-information to obtain concatenated information.
[0066] Since each sub-information is the structure information corresponding to a data table, for the sake of simplified processing, it may only include the table name of each data table and the column names of each column included in the data table, that is, the names of each field in the data table. Therefore, each information item in the sub-information is the table name and column names of a single data table. Then, the query statement may be concatenated with it.
[0067] Exemplarily, the query statement is "How many cases are there each month?", the table name of the data table to be processed currently is t_case_info, and the column names of each data column in this data table are rowguid, yearflag, operateusername, belongxiaoqucoid, operatedate, etc. Therefore, the concatenated information obtained after concatenation may be expressed as:
[0068] How many cases are there each month?|t_case_info:rowguid,yearflag,operateusername,belongxiaoqucoid,operatedate,……
[0069] Then, the relevance between the query statement and each information item may be predicted.
[0070] As Figure 3 shown, it is a schematic diagram for predicting relevance provided by an embodiment of the present application. According to Figure 3As shown, the BERT model can be used to predict the relevance between a query statement and information items. Among them, the concatenated information constructed above can be used as the input data of the BERT model. The BERT model can understand the intention of the input and the meanings of table names and corresponding column names in the database, so as to determine whether there is information related to the input in the current data table. When any information item is relevant to the query statement, the information item can be marked. For example, the information item relevant to the query statement can be marked as 1, and other information items without relevance can be marked as 0. As Figure 3 shown, the marked information items are the table name t_case_info and the column name operatedate.
[0071] In the embodiment of the present application, the BERT model can be pre-trained using sample data, and the above sample data can be data related to database queries. Exemplarily, sample data can be collected, and the sample data can include multiple query statements and at least one concatenated statement corresponding to each query statement. The concatenated statement includes multiple information items related to database information. The BERT model can be pre-trained using the sample data. In the pre-trained output data, the information items relevant to the corresponding query statement in each concatenated statement can be marked as 1, and the information items not relevant to the corresponding query statement can be marked as 0. On this basis, the output data can be used to form positive and negative samples to fine-tune the BERT model. For example, a concatenated statement with any information item marked as 1 can form a positive sample with its corresponding query statement, and a concatenated statement with all information items marked as 0 can form a negative sample with its corresponding query statement. Using the positive and negative samples to fine-tune the BERT model can further improve the accuracy of model prediction. It should be noted that the above introduction taking the BERT model as an example is only a possible implementation manner of the embodiment of the present application. The purpose of pre-training and fine-tuning the BERT model is only to predict whether there is relevance between the query statement and the information item. In practical applications, a model with a similar structure or other structures to the BERT model can also be used for pre-training and fine-tuning, and then the fine-tuned model can be applied to the prediction process of the embodiment of the present application. The embodiment of the present application does not limit this.
[0072] The above introduction is made taking a single data table as an example. In practical applications, the number of data tables is large, and all the data tables in the database can be looped through to obtain all the data tables and data columns related to the query statement in the entire database.
[0073] S205. Simplify the structure information according to the relevance.
[0074] In the embodiments of the present application, since the marked information items are relevant to the query statement, when simplifying the structure information, it is necessary to retain such relevant information items. Therefore, the computer device can extract each marked information item, integrate all the obtained data tables and data columns, and constitute the simplified structure information.
[0075] As Figure 3 shown, the finally extracted information item is t_case_info:operatedate, which also means that in the entire database, only this data table and data column are relevant to this problem. Then, what is finally obtained is as Figure 3 shown in the simplified structure.
[0076] S206. Generate a database statement recognizable by the target database according to the query statement and the simplified structure information.
[0077] In the embodiments of the present application, after obtaining the simplified structure information, the computer device can generate a database statement recognizable by the target database in combination with the query statement.
[0078] In a possible implementation manner of the embodiments of the present application, as Figure 4 shown, in S206, generating a database language recognizable by the target database according to the query statement and the simplified structure information may specifically include the following steps S2061-S2064:
[0079] S2061. Concatenate the query statement with the simplified structure information to obtain the to-be-processed input information.
[0080] In the embodiments of the present application, the query statement may be concatenated with the simplified structure information first.
[0081] S2062. Extract the condition information included in the query statement, where the condition information is used to characterize the query purpose for querying the target database.
[0082] In the embodiments of the present application, the computer device can perform semantic analysis on the query statement to extract the potential condition information included in the query statement. This condition information is also a kind of information that can reflect the user's query purpose.
[0083] Alternatively, the computer device can also combine the structure information to determine the potential conditions included in the query statement by matching the query statement with the structure information.
[0084] S2063. Replace the information item associated with the condition information in the to-be-processed input information with the condition information to obtain the structured input information.
[0085] By replacing the information items associated therewith in the input information to be processed with the obtained conditional information, a standard input structure can be obtained.
[0086] S2064. Convert the structured input information into a database language recognizable by the target database.
[0087] By applying the Text2SQL model, the structured input information can be converted into SQL statements.
[0088] It should be noted that the magnitudes of the sequence numbers of the steps in the above embodiments do not indicate the order of execution, and the execution order of each process should be determined according to its function and internal logic, and should not impose any limitation on the implementation process of the embodiments of the present application.
[0089] For the sake of easy understanding, the following introduces the natural language conversion method provided by the embodiments of the present application with a specific example.
[0090] As Figure 5 shown, it is a schematic diagram of a natural language conversion process provided by the embodiments of the present application. In Figure 5 it shows a database, and this database belongs to a large-scale database. For this database and the natural language input related to the query purpose, if directly operating according to the conventional Text2SQL model, splicing the natural language input with the structure information of the database and then inputting it into the Text2SQL model, it may be due to the excessive number of tokens, exceeding the length limit (for example, the input token limit of the general Text2SQL model is generally around 1024, and the excess part will be truncated). In this way, it may lead to incomplete database information (some data tables or column information may be lost), and correct SQL statements cannot be generated. The method provided by the embodiments of the present application can solve this problem.
[0091] As Figure 5 shown, a BERT-based model can be adopted to associate the corresponding natural language input with the database information, filter out the data tables in the database that are irrelevant to this natural language input, as well as some irrelevant data columns, simplify the database structure, and obtain the simplified database structure information. Specifically:
[0092] (1) Construction of the input. The input data of the model can be constructed by splicing the natural language input with the table name of the corresponding table and the column names of each column included in this data table.
[0093] For example, the input data obtained by splicing can be expressed as:
[0094] What is the number of cases per month? | t_case_info:rowguid,yearflag,operateusername,belongxiaoqucoid,operatedate,……
[0095] (2) Input the rating information into the BERT model. The BERT model can understand the intention of the input and the meanings of the table names and corresponding column names in each data table in the database, so as to determine whether there is information related to the input in the current table. If it exists, the relevant information can be marked as 1, and the irrelevant information can be marked as 0.
[0096] (3) Post-processing. During post-processing, the input at the positions marked as 1 can be extracted to obtain the table names and column names related to the natural language input in the table names and column names of this input.
[0097] For example, in the above example, the extracted information is t_case_info:operatedate
[0098] (4) Loop through all the tables in the database to obtain all the tables and columns in the entire database related to this input.
[0099] (5) Integrate all the obtained tables and columns to obtain the simplified database structure information.
[0100] Then, the simplified database structure information can be concatenated with the natural language input and input into the Text2SQL model for generating SQL statements.
[0101] Refer to Figure 6 , which shows a schematic diagram of a natural language conversion device provided by an embodiment of the present application. Specifically, it may include a receiving module 601, an obtaining module 602, a simplifying module 603, and a generating module 604, where:
[0102] The receiving module 601 is configured to receive a query statement for querying a target database input in natural language;
[0103] The obtaining module 602 is configured to obtain the structure information of the target database, where the structure information is information describing the data stored in the target database in a structured language;
[0104] The simplifying module 603 is configured to simplify the structure information based on the query statement;
[0105] The generating module 604 is configured to generate a database statement recognizable by the target database according to the query statement and the simplified structure information.
[0106] In a possible implementation manner of the embodiment of the present application, the simplification module 603 may specifically be used for:
[0107] Divide the structure information into multiple sub-information;
[0108] Determine the relevance between the query statement and each information item in any one of the sub-information respectively;
[0109] Simplify the structure information according to the relevance.
[0110] In the embodiment of the present application, the simplification module 603 may also be used for:
[0111] Determine the data tables to which each information item in the structure information belongs;
[0112] Divide the information items belonging to the same data table into the same sub-information.
[0113] In the embodiment of the present application, the simplification module 603 may also be used for:
[0114] Concatenate the query statement with each information item in the sub-information to obtain concatenated information;
[0115] Predict the relevance between the query statement and each information item;
[0116] When any one of the information items is relevant to the query statement, mark the information item.
[0117] In the embodiment of the present application, the simplification module 603 may also be used for:
[0118] Extract each marked information item to form the simplified structure information.
[0119] In a possible implementation manner of the embodiment of the present application, the acquisition module 602 may specifically be used for:
[0120] Acquire the table structure description information of multiple data tables stored in the target database;
[0121] Generate the structure information of the target database according to the table structure description information of each data table.
[0122] In a possible implementation manner of the embodiment of the present application, the generation module 604 may specifically be used for:
[0123] Concatenate the query statement with the simplified structure information to obtain the to-be-processed input information;
[0124] Extract the conditional information contained in the query statement, where the conditional information is used to characterize the query purpose for querying the target database;
[0125] Use the conditional information to replace the information items associated with the conditional information in the to-be-processed input information to obtain structured input information;
[0126] Convert the structured input information into a database language recognizable by the target database.
[0127] A natural language conversion device provided by an embodiment of the present application. By applying this device, each step in the foregoing method embodiments can be implemented.
[0128] For the device embodiment, since it is basically similar to the method embodiment, the description is relatively simple. For related parts, refer to the description in the method embodiment section.
[0129] Refer to Figure 7 , which shows a schematic diagram of a computer device provided by an embodiment of the present application. As Figure 7 shown, the computer device 700 in the embodiment of the present application includes: a processor 710, a memory 720, and a computer program 721 stored in the memory 720 and operable on the processor 710. When the processor 710 executes the computer program 721, the steps in the foregoing natural language conversion method embodiments are implemented, such as Figure 1 the steps S101 to S104 shown. Alternatively, when the processor 710 executes the computer program 721, the functions of each module / unit in the foregoing device embodiments are implemented, such as Figure 6 the functions of the modules 601 to 604 shown.
[0130] Exemplarily, the computer program 721 can be divided into one or more modules / units. The one or more modules / units are stored in the memory 720 and executed by the processor 710 to complete the present application. The one or more modules / units can be a series of computer program instruction segments capable of performing specific functions, and these instruction segments can be used to describe the execution process of the computer program 721 in the computer device 700. For example, the computer program 721 can be divided into a receiving module, an obtaining module, a simplifying module, and a generating module, and the specific functions of each module are as follows:
[0131] The receiving module is used to receive a query statement for querying the target database input in natural language;
[0132] The obtaining module is used to obtain the structure information of the target database, where the structure information is information that describes the data stored in the target database in a structured language;
[0133] A simplification module, configured to simplify the structure information based on the query statement;
[0134] A generation module, configured to generate a database statement recognizable by the target database according to the query statement and the simplified structure information.
[0135] The computer device 700 may be an electronic device capable of implementing each step in the foregoing method embodiments. The computer device 700 may be a desktop computer, a cloud server, or other devices. The computer device 700 may include, but is not limited to, a processor 710 and a memory 720. Those skilled in the art can understand that Figure 7 This is only an example of the computer device 700 and does not limit the computer device 700. It may include more or fewer components than shown in the figure, or combine some components, or different components. For example, the computer device 700 may further include input / output devices, network access devices, a bus, etc.
[0136] The processor 710 may be a central processing unit (CPU), or may be other general-purpose processors, digital signal processors (DSPs), application specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. The general-purpose processor may be a microprocessor, or the processor may also be any conventional processor, etc.
[0137] The memory 720 may be an internal storage unit of the computer device 700, such as the hard disk or memory of the computer device 700. The memory 720 may also be an external storage device of the computer device 700, such as a plug-in hard disk, a smart media card (SMC), a secure digital (SD) card, a flash card, etc. equipped on the computer device 700. Further, the memory 720 may include both the internal storage unit and the external storage device of the computer device 700. The memory 720 is used to store the computer program 721 and other programs and data required by the computer device 700. The memory 720 may also be used to temporarily store data that has been output or is to be output.
[0138] An embodiment of the present application also discloses a computer device, including a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, the natural language conversion method described in each of the foregoing embodiments is implemented.
[0139] An embodiment of the present application also discloses a computer-readable storage medium storing a computer program, which when executed by a processor, implements the natural language conversion method described in each of the foregoing embodiments.
[0140] An embodiment of the present application also discloses a computer program product, which when running on a computer, causes the computer to execute the natural language conversion method described in each of the foregoing embodiments.
[0141] The foregoing embodiments are only used to illustrate the technical solutions of the present application and are not intended to limit them. Although the present application has been described in detail with reference to the foregoing embodiments, those of ordinary skill in the art should understand that they can still modify the technical solutions described in the foregoing embodiments, or perform equivalent replacements for some of the technical features; and these modifications or replacements do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of the present application, and should all be included in the protection scope of the present application.
Claims
1. A natural language conversion method, characterized in that, Including: Receiving a query statement for querying a target database input in natural language; Obtaining the structure information of the target database, where the structure information is information that describes the data stored in the target database in a structured language; Simplifying the structure information based on the query statement; Generating a database statement recognizable by the target database according to the query statement and the simplified structure information.
2. The method according to claim 1, wherein The simplifying the structure information based on the query statement includes: Dividing the structure information into multiple sub-information; Respectively determining the relevance between the query statement and each information item in any one of the sub-information; Simplifying the structure information according to the relevance.
3. The method according to claim 2, wherein The dividing the structure information into multiple sub-information includes: Determining the data tables to which each information item in the structure information belongs; Dividing each information item belonging to the same data table into the same sub-information.
4. The method according to claim 2 or 3, characterized in that, The respectively determining the relevance between the query statement and each information item in any one of the sub-information includes: Concatenating the query statement with each information item in the sub-information to obtain concatenated information; Predicting the relevance between the query statement and each information item; When any one of the information items is relevant to the query statement, marking the information item.
5. The method according to claim 4, wherein The simplifying the structure information according to the relevance includes: Extracting each marked information item to form the simplified structure information.
6. The method according to any one of claims 1-3 or 5, characterized in that, The obtaining the structure information of the target database includes: Obtaining the table structure description information of multiple data tables stored in the target database; Generating the structure information of the target database according to the table structure description information of each data table.
7. The method according to claim 6, wherein The generating a database language recognizable by the target database according to the query statement and the simplified structure information includes: Concatenating the query statement with the simplified structure information to obtain input information to be processed; Extracting the condition information included in the query statement, where the condition information is used to characterize the query purpose for querying the target database; Replacing the information item associated with the condition information in the input information to be processed with the condition information to obtain structured input information; Converting the structured input information into a database language recognizable by the target database.
8. A natural language conversion device, characterized in that, Including: A receiving module for receiving a query statement for querying a target database input in natural language; An obtaining module for obtaining the structure information of the target database, where the structure information is information that describes the data stored in the target database in a structured language; A simplifying module for simplifying the structure information based on the query statement; A generating module for generating a database statement recognizable by the target database according to the query statement and the simplified structure information.
9. A computer device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that, When the processor executes the computer program, it implements the natural language conversion method according to any one of claims 1-7.
10. A computer-readable storage medium storing a computer program, characterized in that, When the computer program is executed by a processor, it implements the natural language conversion method according to any one of claims 1-7.