Query statement generation method and device and related equipment

CN122838423APending Publication Date: 2026-09-29HUAWEI TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202510370557.2
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-03-26
Publication Date
2026-09-29

AI Technical Summary

Technical Problem

但是,人工智能模型的准确程度有限,导致基于人工智能模型生成的SQL查询语句不够准确,影响用户与数据库之间的交互

Benefits of technology

[0018]第七方面,本申请提供了一种包含指令的操作步骤的计算机程序产品,当其在计算设备集群(该计算设备集群包括至少一个计算设备)上运行时,使得计算设备集群执行上述第一方面或第一方面的任一种实现方式所述的方法的操作步骤。

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122838423A_ABST
    Figure CN122838423A_ABST
Patent Text Reader

Abstract

The application provides a query statement generation method and device and related equipment belonging to the computer technology field. In the method, a computing device first acquires a natural language query statement that needs to be converted into SQL. The computing device determines a natural language case statement matched with the natural query statement according to a hierarchical matching strategy. The hierarchical matching strategy defines two matching modes with different accuracies, namely, accurate matching with higher accuracy and approximate matching. The natural language case statement is a case statement generated based on historical natural language query statements. The computing device acquires an SQL case statement corresponding to the natural language case statement. The SQL case statement has a relatively standard syntax and high accuracy, and can correctly express the meaning of the query statement. Finally, the computing device converts the natural language query statement by using the SQL case statement, and the converted SQL query statement can correctly express the query intention of the user and meet the interaction requirement of the user and the database.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of computer technology, and in particular to a method, apparatus, device, storage medium, and computer program product for generating query statements. Background Technology

[0002] Natural Language to Structured Query Language (NL2SQL) is a technology that converts natural language queries into structured query language (SQL) queries. NL2SQL aims to enable database users (e.g., non-technical users) to interact with databases and retrieve data using everyday natural language by combining Natural Language Processing (NLP) and database querying.

[0003] Currently, with the rapid development of artificial intelligence (AI) technology, it is possible to convert natural language queries into SQL queries using AI models. However, the accuracy of AI models is limited, resulting in inaccurate SQL queries generated based on these models, which affects the interaction between users and the database. Summary of the Invention

[0004] In view of this, this application provides a method, apparatus, device, storage medium, and computer program product for generating query statements. The aim is to adopt a hierarchical matching strategy, first determine natural language case statements that are relatively well matched with natural language query statements, and then use the corresponding SQL case statements to convert them into SQL query statements. This achieves the generation of SQL query statements that can effectively reflect the query intent using highly accurate SQL case statements, thereby improving the accuracy of SQL query statements and meeting the needs of interaction between users and databases.

[0005] Firstly, this application provides a method for generating a query statement executed by a computing device. The computing device first obtains a natural language query statement that needs to be language-converted. Following a hierarchical matching strategy, the computing device first performs a highly precise match on the natural language query statement. If no matching natural language example statement is found through precise matching, an approximate match is performed to determine the matching natural language example statement. Prioritizing precise matching allows for the identification of more similar natural language example statements, which is beneficial for quickly generating a more accurate SQL query statement using the corresponding SQL example statements. In cases where precise matching fails to identify a matching natural language example statement, approximate matching expands the matching scope, resulting in slightly less similar natural language example statements, which further facilitates the generation of a more accurate SQL query statement using the corresponding SQL example statements. Finally, the computing device converts the natural language query statement into a structured query language query statement based on the structured query language example statement corresponding to the natural language example statement. On the one hand, SQL example statements have relatively standardized syntax and accurate semantic expression, allowing for the rapid generation of high-quality SQL queries by referring to them. On the other hand, generating SQL queries by referring to SQL example statements eliminates the need to call AI models to process natural language queries, reducing the frequency and cost of calling AI models.

[0006] In one possible implementation, following a hierarchical matching strategy, the computing device retrieves natural language sample statements from a sample statement library. These sample statements can be historically input natural language query statements that can serve as matching samples. The computing device performs precise matching between the natural language query statements and the sample statements, i.e., a word-to-word comparison. The precisely matched sample statements are then used as natural language case statements. Through a more precise matching method, more similar natural language case statements are identified. The corresponding SQL case statements effectively represent the query intent of the natural language query statements. By converting the natural language query statements using the corresponding SQL case statements, high-quality SQL query statements can be obtained, improving the accuracy of the generated SQL query statements.

[0007] In another possible implementation, if the natural language query fails to match precisely with any of the natural language sample statements in the sample statement library, an approximate match is performed. The computing device obtains natural language template statements from the template statement library. These template statements can be obtained by template-processing historical natural language queries. Template-processing improves the generalization of natural language template statements and expands their matching range. The computing device performs an approximate match between the natural language query and the natural language template statements. The computing device uses the approximate match natural language template statements as natural language case statements. This allows for the expansion of the matching range and increases the probability of obtaining natural language case statements even when a precise match has not been achieved. This improves the success rate of generating SQL queries using SQL case statements, which in turn helps to improve the accuracy of subsequent SQL query generation.

[0008] In one possible implementation, during the approximate matching process, the computing device first templates the natural language query statement to obtain a template statement to be matched. The method of templateizing the natural language query statement is the same as the method of generating the natural language template statement. The template statement to be matched obtained after templateization has the same statement format as the natural language template statement, facilitating the matching of the template statement to be matched with the natural language template statement. The computing device compares the statement features of the template statement to be matched with the statement features of the natural language template statement. This comparison of statement feature dimensions helps to match natural language template statements that are similar in statement structure and semantic expression. Then, referring to the corresponding SQL template statement of the natural language template statement, the query statement is transformed to obtain a more accurate and higher-quality SQL query statement.

[0009] In one possible implementation, during the template processing of the natural language query statement, the computing device first determines the correspondence between the tokens included in the natural language query statement and the table content of the first table to be queried. The table content includes one or more of the table's name, fields, and field values. Determining the correspondence between the tokens included in the natural language query statement and the table content of the first table to be queried can be achieved through schema-linking. The table content has pre-set template text. The template text is pre-set text that conforms to the format requirements of the template statement. The computing device replaces the tokens corresponding to the table content with the corresponding template text, obtaining the template statement to be matched. By template processing the natural language query statement, a template statement to be matched that is consistent with the natural language template statement in terms of statement format is obtained. This facilitates the calculation of the matching degree between the natural language query statements, identifies natural language template statements that are more similar in terms of statement structure and semantic expression, further improves the effectiveness of the SQL template statement referenced for conversion, and thus improves the quality of the SQL query statement.

[0010] In one possible implementation, time-related table content corresponds to multiple candidate template texts. Each candidate template text can be set according to the semantic requirements of expressing time. During the template processing of natural language query statements, for the time text included in the natural language query statement, based on the semantics of the time text, the template text required for this template processing is first determined from the multiple candidate template texts corresponding to the table content, and then the determined template text is used to replace the time text. The template statement to be matched obtained after template processing better meets the semantic expression requirements of the natural language query statement, and thus it is possible to determine a more matching natural language template statement based on the template statement to be matched, which is beneficial for generating high-quality and accurate SQL query statements.

[0011] In one possible implementation, an SQL sample statement is used to generate an SQL query statement. During the SQL query generation process, if the natural language query statement includes time text, the time values ​​in the SQL sample statement need to be adjusted to generate an SQL query statement that matches the query intent of the natural language query statement. Specifically, the computing device determines a first time value for the natural language query statement based on the time text included in the natural language query statement. The first time value represents the time period related to the data to be queried by the natural language query statement. The computing device replaces the second time value included in the SQL sample statement with the first time value to obtain the converted SQL query statement. Based on the time-related semantics of the natural language query statement, the second time value of the SQL sample statement is flexibly adjusted to make the resulting SQL query statement more consistent with the time-related query requirements of the natural language query statement, achieving high-quality conversion of the natural language query statement into an SQL query statement and improving the accuracy and quality of the SQL query statement.

[0012] In one possible implementation, an SQL template statement is used to generate an SQL query statement. The SQL template statement includes template text. The template text is then replaced with the corresponding table content to obtain an SQL query statement containing the specific content. This allows the use of the SQL template statement to convert general template text into the specific table content of the first table that the natural language query statement aims to retrieve. By replacing the specific content while maintaining the statement structure of the SQL template statement, a high-quality SQL query statement that meets the query requirements is generated.

[0013] Secondly, this application provides a query statement generation apparatus, comprising modules for executing the query statement generation method in the first aspect or any possible implementation of the first aspect.

[0014] Thirdly, this application provides a computing device, which includes a processor and a memory. The memory stores instructions, and when the computing device is running, the processor executes the instructions stored in the memory to cause the computing device to perform the operation steps of the method described in the first aspect or any possible implementation thereof. It should be noted that the memory can be integrated into the processor or can be independent of the processor. Each computing device may also include a bus. The processor is connected to the memory via the bus. The memory may include readable storage and random access memory.

[0015] Fourthly, this application provides a computing device cluster, which includes at least one computing device, each computing device including a processor and a memory. The memory is used to store instructions. When the computing device cluster is running, the processor in each computing device executes the instructions stored in the memory to cause the computing device cluster to perform the operation steps of the method in the first aspect or any possible implementation of the first aspect. It should be noted that the memory can be integrated into the processor or can be independent of the processor. Each computing device may also include a bus. The processor is connected to the memory via the bus. The memory may include readable storage memory and random access memory.

[0016] Fifthly, this application provides a chip system including a processor and a power supply circuit, the power supply circuit being used to supply power to the processor, and the processor being used for the operation steps of the method in the first aspect or any possible implementation of the first aspect.

[0017] In a sixth aspect, this application provides a computer-readable storage medium storing instructions that, when executed on a computing device cluster (which includes at least one computing device), cause the computing device cluster to perform the operational steps of the method described in the first aspect or any implementation thereof.

[0018] In a seventh aspect, this application provides a computer program product containing operational steps of instructions, which, when run on a computing device cluster (which includes at least one computing device), causes the computing device cluster to perform the operational steps of the method described in the first aspect or any implementation thereof.

[0019] Based on the implementation methods provided in the above aspects, this application can be further combined to provide more implementation methods. Attached Figure Description

[0020] Figure 1 A schematic diagram illustrating an exemplary application scenario provided in this application;

[0021] Figure 2 This application provides another exemplary application scenario diagram;

[0022] Figure 3 A flowchart illustrating a method for generating a query statement provided in this application;

[0023] Figure 4 A flowchart illustrating another method for generating query statements provided in this application;

[0024] Figure 5A flowchart illustrating a method for generating SQL query statements provided in this application;

[0025] Figure 6 A flowchart illustrating another method for generating SQL query statements provided in this application;

[0026] Figure 7 A schematic diagram of the structure of a query statement generation device provided in this application;

[0027] Figure 8 A schematic diagram of the structure of a computing device provided in this application;

[0028] Figure 9 This application provides a schematic diagram of the structure of a computing device cluster;

[0029] Figure 10 This is a schematic diagram of another computing device cluster provided in this application. Detailed Implementation

[0030] To make the objectives, technical solutions, and advantages of this application clearer, a detailed description of this application will be provided below with reference to the accompanying drawings. The terminology used in the embodiments section of this application is only for explaining specific embodiments of this application and is not intended to limit this application.

[0031] In this application, "multiple" refers to two or more. Therefore, "multiple" can also be understood as "at least two." "At least one" can be understood as one or more, such as one, two, or more. For example, "including at least one" means including one, two, or more, and it does not limit which ones are included. For example, including at least one of A, B, and C could mean A, B, C, A and B, A and C, B and C, or A and B and C. "And / or" describes the relationship between related objects, indicating that three relationships can exist. For example, A and / or B can represent: A alone, A and B simultaneously, or B alone. Additionally, the character " / ", unless otherwise specified, generally indicates that the preceding and following related objects have an "or" relationship.

[0032] Unless otherwise stated, the ordinal numbers such as "first" and "second" mentioned in this application are used to distinguish multiple objects, and are not used to limit the order, sequence, priority or importance of multiple objects.

[0033] To facilitate understanding, a brief introduction to the terminology used in this application will be provided first.

[0034] Structured Query Language (SQL) is a standard programming language used for managing and manipulating relational databases. SQL is widely used for database creation, data insertion, data querying, data updating, data deletion, and database management.

[0035] Natural language refers to the language that humans use naturally in their daily lives.

[0036] NL2SQL technology is used to convert natural language into SQL. Based on NL2SQL, user-input natural language queries are converted into SQL queries, enabling data retrieval from the database using SQL statements. Here, "natural language query" is short for query statements described in natural language, and "SQL query" is short for query statements described in SQL. In this way, users can directly query data from the database using natural language queries, eliminating the need to write SQL queries and reducing the difficulty of data retrieval.

[0037] Currently, NL2SQL technology can be implemented based on artificial intelligence (AI) models, such as language models.

[0038] Specifically, based on the user's input natural language query, the system first locates the relevant database tables and their contents. Then, based on these tables and contents, a prompt is generated. This prompt is input to the language model to guide or stimulate it to produce a specific output. Finally, the language model processes the prompt to generate the SQL query. An example of such a language model is the Large Language Model (LLM). A LLM is a deep learning model trained on large amounts of text data. It can generate natural language text or understand the meaning of text. LLMs can handle various natural language tasks, such as text classification, question answering, and dialogue.

[0039] However, language models have limited accuracy, and the SQL queries generated by them often suffer from inaccuracies. Specifically, language models exhibit unstable output, particularly in complex scenarios. For example, complex scenarios might involve semantically complex natural language queries, such as those containing industry-specific terminology or non-standard semantics. Complex scenarios could also involve complex data tables, such as those with semantically similar fields, leading to confusion. Even with post-validation mechanisms to correct the generated SQL queries or providing additional information to aid understanding, the accuracy of language-generated SQL queries in complex scenarios often falls short of user data query needs. Furthermore, using language models is costly. The time required to process prompts using the language model is significant, impacting the real-time nature of user-database interaction.

[0040] Therefore, it is evident that using artificial intelligence models to convert natural language queries into SQL queries suffers from the problem of low accuracy in the generated SQL queries. Furthermore, inaccurate SQL queries prevent users from achieving their query objectives, hindering user-database interaction and failing to meet users' data processing needs.

[0041] Based on this, this application provides a method for converting natural language query statements into SQL query statements. The method provided in this application employs a hierarchical matching strategy to determine natural language example statements that match the natural language query statement. Then, it uses SQL example statements with higher accuracy and standardization corresponding to the natural language example statements to convert the natural language query statement, resulting in a more accurate SQL query statement.

[0042] Specifically, the query statement generation method provided in this application can be executed by a computing device. The computing device first obtains the natural language query statement to be converted into SQL. The computing device then determines the natural language case statements that match the natural language query statement according to a hierarchical matching strategy. The hierarchical matching strategy defines two matching methods with different levels of accuracy: precise matching and approximate matching, both with higher accuracy. For example, the computing device first performs precise matching on the natural language query statement to determine the natural language case statements that match it. If precise matching fails to yield a matching natural language case statement, approximate matching is performed on the natural language query statement to determine the natural language case statements. The natural language case statements are generated based on historical natural language query statements. The computing device then obtains the corresponding SQL case statements. The SQL case statements have relatively standardized syntax and high accuracy, correctly expressing the meaning of the query statement. Finally, the computing device uses the SQL case statements to convert the natural language query statement, obtaining a highly accurate SQL query statement at a low cost. The converted SQL query statement correctly expresses the user's query intent and meets the user's interaction needs with the database.

[0043] See Figure 1 As shown in the diagram, this is a schematic diagram of an exemplary application scenario. The computing device can be deployed in the cloud to provide data processing services to user 101, specifically providing a service to convert natural language queries into SQL queries. For example, in... Figure 1 In the application scenario shown, the computing device can specifically be a computing device 103 (or a cluster of computing devices) located in the cloud. The computing device 103 can provide a client 102 to interact with user 101, such as obtaining a natural language query statement provided by user 101. In practical applications, the client 102 can be, for example, an application running on the user's device, or a web browser provided by the computing device 103. The computing device 103 obtains the natural language query statement. Following a hierarchical matching strategy, the computing device 103 first performs exact matching, and if exact matching fails, performs approximate matching to determine the natural language example statement that matches the natural language query statement. The computing device 103 uses the corresponding SQL example statement to convert the natural language query statement into an SQL query statement. The computing device 103 sends the SQL query statement to the database. The database executes the SQL query statement and obtains the query results. The database then returns the query results to user 101.

[0044] In another example, the aforementioned computing device can be deployed on an enterprise's or user's own computer system, or it can be deployed locally, thereby providing data processing services to users, specifically providing a service to convert natural language queries into SQL queries. Here, the enterprise's or user's own computer system includes multiple computer devices maintained and managed by the enterprise or user. For example, in... Figure 2 In the application scenario shown, the computing device mentioned above can specifically be terminal 202. Terminal 202 can determine the natural language query statement matched by the natural language query statement input by user 201, following a hierarchical matching strategy. First, it performs exact matching; if exact matching fails, it performs approximate matching. Terminal 202 then uses the corresponding SQL example statement to convert the natural language query statement into an SQL query statement. Terminal 202 sends the SQL query statement to the database. The database executes the SQL query statement and obtains the query results. The database returns the query results to terminal 202. Terminal 202 can then display the query results to the user.

[0045] In this embodiment, the specific deployment method of the computing device is not limited.

[0046] In practical applications, the aforementioned computing devices can be implemented through software or through hardware.

[0047] A computing device, as an example of a software functional unit, can include code running on a computing instance. A computing instance can include at least one of a physical host (computing device), a virtual machine, and a container. Furthermore, the aforementioned computing instance can be one or more. For example, a computing device can include code running on multiple hosts / virtual machines / containers. It should be noted that the multiple hosts / virtual machines / containers used to run the code can be distributed within the same region or in different regions. Further, the multiple hosts / virtual machines / containers used to run the code can be distributed within the same availability zone (AZ) or in different AZs, each AZ comprising one or more geographically proximate data centers. Typically, a region can include multiple AZs.

[0048] Similarly, multiple hosts / virtual machines / containers used to run this code can be distributed within the same Virtual Private Cloud (VPC) or across multiple VPCs. Typically, a VPC is set up within a region. Communication between two VPCs within the same region, as well as between VPCs in different regions, requires a communication gateway to be set up within each VPC to enable interconnection between VPCs.

[0049] As an example of a hardware functional unit, a computing device can include at least one computing device, such as a server. Alternatively, a computing device can also be a device implemented using an application-specific integrated circuit (ASIC) or a programmable logic device (PLD). The aforementioned PLD can be implemented using a complex programmable logical device (CPLD), a field-programmable gate array (FPGA), generic array logic (GAL), or any combination thereof.

[0050] The computing device includes multiple computing devices that can be distributed within the same region or in different regions. Similarly, the computing devices can be distributed within the same Availability Zone (AZ) or in different AZs. Likewise, the computing devices can be distributed within the same Virtual Private Cloud (VPC) or multiple VPCs. These multiple computing devices can be any combination of computing devices such as servers, ASICs, PLDs, CPLDs, FPGAs, and GALs.

[0051] Next, various non-limiting implementations of the query statement generation method will be described in detail.

[0052] See Figure 3 As shown, this figure is a flowchart illustrating a query statement generation method provided in this application. The query statement generation method includes steps S301-S303.

[0053] S301: The computing device obtains a natural language query statement.

[0054] Natural language queries are queries described using natural language. Natural language queries can be queries entered by the user. For example, a user-entered natural language query might be: "Project No. 1111 Monthly Sales Gross Profit Inception-to-Date Calculation". Here, Inception-to-Date (ITD) refers to the time period from the start of recording until the time of the user's query.

[0055] Natural language queries need to be converted from natural language to SQL so that data query operations can be performed in the database based on SQL.

[0056] S302: The computing device determines the natural language case statement that matches the natural language query statement according to the hierarchical matching strategy.

[0057] The hierarchical matching strategy is pre-set and indicates the two matching methods that can be used to match natural language queries. The hierarchical matching strategy includes exact matching and approximate matching. Exact matching has higher precision than approximate matching, and it also has higher priority. That is, when matching natural language queries, exact matching is preferred. If an exact matching natural language example sentence is found to match the query, step S303 is executed directly without further approximate matching. If exact matching fails to find a matching natural language example sentence, approximate matching is used to determine the matching natural language example sentence.

[0058] Among them, natural language case statements are query statements described in natural language and used as examples. Natural language case statements are query statements that conform to the rules of syntax and clearly express the query intent.

[0059] This application does not limit the method of generating natural language case statements. As an example, natural language case statements can be generated based on historical natural language query statements. As another example, natural language case statements can be generated manually.

[0060] In addition, considering the difference in matching accuracy between exact matching and approximate matching, the types of natural language example sentences obtained by different matching methods are different.

[0061] In one possible implementation, exact matching involves performing character-level matching between the natural language query language and the natural language sample statements included in the sample statement library. The natural language sample statements are the query statements themselves described in natural language. The natural language example statements obtained through exact matching are the natural language sample statements.

[0062] Approximate matching involves matching natural language query statements with natural language template statements included in a template statement library at the statement feature level. Natural language template statements are generated by templated processing of query statements described in natural language. The natural language example statements obtained through approximate matching are natural language template statements.

[0063] This application provides possible implementations of exact matching and approximate matching, as detailed below.

[0064] Prioritizing exact matching allows for the identification of highly similar natural language (NLP) case statements, facilitating the rapid generation of accurate SQL queries from their corresponding SQL case statements. When exact matching fails to identify matching NLP case statements, approximate matching expands the matching scope, yielding NLP case statements with slightly lower similarity. These approximate NLP case statements then contribute to the generation of more accurate SQL queries. This approach reduces the frequency and cost of calling AI models to process NLP queries.

[0065] S303: The computing device converts the natural language query statement into a structured query language query statement based on the structured query language case statement corresponding to the natural language case statement.

[0066] Natural language case statements have corresponding SQL case statements. SQL case statements serve as examples, using SQL to describe query statements. SQL case statements can be obtained by converting natural language case statements to SQL, or they can be manually written based on natural language case statements.

[0067] After determining the natural language example statement corresponding to the natural language query, the corresponding SQL example statement is obtained. Referring to the SQL example statement, the natural language query can be converted into a corresponding SQL query. This allows for rapid conversion of natural language queries based on existing SQL example statements. Firstly, using SQL example statements to convert natural language queries eliminates the need to call AI models, reducing the cost of using AI models to process natural language queries. Secondly, SQL example statements have relatively standardized syntax and accurately express the query intent. The SQL query obtained using SQL example statements conforms to syntax rules and accurately expresses the query intent, facilitating the retrieval of data from the database that meets the user's query requirements.

[0068] The type of an SQL sample statement is the same as the type of its corresponding natural language sample statement. For example, a natural language sample statement corresponds to an SQL sample statement. An SQL sample statement is a query statement described using SQL. A natural language template statement corresponds to an SQL template statement. An SQL template statement is a statement that is a templated version of a query statement described using SQL.

[0069] The methods for generating SQL queries from natural language query statements differ depending on the type of SQL sample statement. Correspondingly, this application provides possible implementations for generating SQL queries from sample SQL statements in exact matching scenarios, and possible implementations for generating SQL queries from template SQL statements in approximate matching scenarios. Please refer to the separate descriptions of exact matching and approximate matching scenarios below for details.

[0070] The following sections will introduce the implementation methods for determining natural language case statements through exact matching or approximate matching, and generating SQL query statements using SQL case statements.

[0071] The first method involves determining the matching natural language sample statements through precise matching and generating SQL query statements using the SQL sample statements.

[0072] Natural language sample statements can be natural language query statements from historical input. See also: Figure 4 As shown, the system retrieves the user's historical natural language query statements and the corresponding SQL query statements generated after language conversion. Furthermore, it retrieves the user's feedback on the converted SQL query statements.

[0073] If the user's feedback is positive, the historical natural language query statements are used as natural language sample statements, and the historical SQL query statements are used as corresponding SQL sample statements. Positive feedback means that the user considers the converted SQL query statement to be of high quality, accurate, and able to meet their query needs. For example, the feedback result includes a rating score provided by the user for the converted SQL query statement. If the rating score is higher than a certain threshold, the feedback result is positive. Another example is a label provided by the user for the converted SQL query statement. If the feedback result contains a positive sample label, the feedback result is positive.

[0074] Additionally, user feedback may be negative. Negative feedback refers to a user's opinion that the converted SQL query does not meet their query requirements. If the negative feedback includes the user's modified SQL query, the historical natural language query will be used as the natural language sample statement, and the modified SQL query will be used as the corresponding SQL sample statement.

[0075] It should be noted that this application does not limit the method of converting natural language query statements. For example, an AI model can be used to convert natural language query statements into SQL query statements. Alternatively, SQL query statements can be manually written by technicians based on natural language query statements. Yet another example is SQL query statements obtained through conversion based on conversion rules.

[0076] By utilizing historical natural language and SQL queries, natural language sample statements and corresponding SQL sample statements are generated respectively, fully leveraging the high-quality transformation results of historical queries. As the number of queries increases, the natural language and SQL sample statements are continuously updated to improve the probability of successful and accurate matching.

[0077] Natural language sample statements and SQL sample statements can be stored as sample pairs in a sample statement library. The sample statement library can be, for example, a MySQL database (an open-source relational database management system). As an example, (question, sql) is used to represent a sample pair of natural language sample statements and SQL sample statements. Here, question represents the natural language sample statement, and sql represents the SQL sample statement. The sample statement library can include one or more sample pairs. The sample statement library can be stored on a device where the computing device is deployed. The sample statement library can also be stored on other devices so that the computing device can obtain natural language sample statements and SQL sample statements through interaction with other devices. These other devices can be other computing devices or storage devices; this application does not limit this.

[0078] The above is an introduction to natural language sample statements and SQL sample statements. See also... Figure 4 As shown, precise matching is performed based on the natural language sample sentences included in the sample sentence library. The precise matching process is described below. The precise matching process mainly includes the following three steps, A1-A3.

[0079] A1: Obtain natural language sample statements from the sample statement library.

[0080] From the sample statement library, natural language sample statements that do not exactly match the natural language query statement are selected as the objects of this exact matching. This application does not limit the method of obtaining natural language sample statements. For example, natural language sample statements can be randomly selected from the sample statement library, or they can be selected sequentially.

[0081] A2: Accurately match natural language query statements with natural language sample statements.

[0082] In one possible implementation, exact matching refers to a character-level comparison. Specifically, it involves calculating the character similarity between the natural language query and the natural language sample statement. The character similarity is then used to determine whether the natural language sample statement matches the natural language query.

[0083] For example, a character similarity threshold can be preset. For instance, the character similarity threshold could be 97%.

[0084] If the character similarity between the natural language query and the natural language sample statement is greater than or equal to the character similarity threshold, then the natural language query and the natural language sample statement are determined to be an exact match. Execute A3, and use the natural language sample statement obtained from the exact match as the natural language case statement.

[0085] If the character similarity between the natural language query and the natural language sample statement is less than the character similarity threshold, it is determined that the natural language query and the natural language sample statement cannot be precisely matched. Step A1 can be repeated to obtain natural language sample statements from the sample statement library that have not undergone character similarity calculation with the natural language query for precise matching.

[0086] A3: Use the natural language sample sentences obtained from precise matching as natural language case sentences.

[0087] It should be noted that if there are multiple natural language sample statements in the sample statement library that exactly match the natural language query statement, then the natural language sample statement with the highest character similarity will be used as the natural language case statement.

[0088] After accurately matching and identifying the natural language sample statements that match the natural language query statement, the corresponding SQL sample statements are retrieved from the sample database. Using the SQL sample statements and the natural language query statement, the SQL query statement derived from the natural language query statement is generated.

[0089] In some cases, the sample SQL statement may not involve time, and can be used directly as a SQL query statement.

[0090] In some other possible cases, the SQL sample statement involves time. Since the time involved in the natural language query statement differs from that involved in the natural language sample statement, it is necessary to adjust the time-related values ​​in the SQL sample statement based on the time involved in the natural language query statement to obtain the corresponding SQL query statement.

[0091] For details, see Figure 5 As shown, the first time value of the natural language query statement is determined based on the time text included in the natural language query statement.

[0092] Time text is the text representing time included in a natural language query. Time text can be obtained by performing natural language processing on the natural language query. Based on the time text, the primary time value targeted by the natural language query can be determined. The primary time value can be a single moment or a time period.

[0093] As an example, a user enters the following natural language query in February of year X: "Project No. 1111 Monthly Sales Gross Profit Calculation from Start to Date". The time text consists of "this month" and "from start to date". Based on the time text, the first time value is determined to be: X02. X02 represents February of year X.

[0094] Replace the second time value in the SQL sample statement with the first time value to obtain the SQL query statement.

[0095] Assume that the natural language sample statement that matches the natural language query statement is the same as the natural language query statement. The SQL sample statement corresponding to the natural language sample statement is: SELECT "Accounting for historical cumulative amount" AS "ITD Accounting" FROM "Delivered project profit and loss statement" WHERE "Project code" = '1111' AND "Report item name" = 'Sales gross profit' AND "Accounting period" = Y12.

[0096] Here, "Y12" is the second time value, indicating that the second time value included in the SQL sample statement is "Y12", representing December of year Y. Replacing the second time value with the first time value, the converted SQL query statement is: SELECT "Accounting for historical cumulative amount" AS "ITD Accounting" FROM "Delivered project profit and loss statement" WHERE "Project code" = '1111' AND "Report item name" = 'Sales gross profit' AND "Accounting period" = X02.

[0097] It should be noted that when an SQL query statement includes multiple second time values, each second time value is replaced based on a first time value that has the same semantic meaning as each second time value.

[0098] The above describes the exact matching process and the process of generating SQL queries using sample SQL statements. Below, we will explain the approximate matching process and the process of generating SQL queries using sample SQL statements.

[0099] The second approach involves determining the matching natural language template statement through approximate matching and then using the SQL template statement to generate an SQL query statement.

[0100] First, let's introduce natural language template statements and SQL template statements.

[0101] Natural language template statements can be obtained by templated processing of historical natural language query statements. SQL template statements can be obtained by templated processing of historical SQL query statements obtained after converting historical natural language query statements.

[0102] This application does not limit the source of the historical natural language query statements and the converted SQL query statements. As an example, the historical natural language query statements and the converted SQL query statements can be manually written. See also [link to example]. Figure 4 As shown, historical natural language query statements and the transformed SQL query statements can also be determined based on user feedback. The method of determining based on user feedback is similar to the method of determining natural language sample statements and SQL sample statements described above; see above for details. As another example, historical natural language query statements are natural language sample statements, and historical transformed SQL query statements are SQL sample statements. That is, it is possible to generate natural language template statements using natural language sample statements and SQL template statements using SQL sample statements.

[0103] The following explains the process of generating natural language template statements and generating SQL template statements, which is the process of template generation.

[0104] First: The process of generating natural language template statements.

[0105] The process of template-based processing of historical natural language query statements includes steps B1 and B2.

[0106] B1: Determine the correspondence between the word segments included in the historical natural language query and the table content of the first table.

[0107] Historical natural language queries are related to the target table in the database. Specifically, the word segments included in the historical natural language query correspond to the table content of the target table. The table content includes one or more of the target table's name, fields, and field values.

[0108] In one possible implementation, see Figure 6 As shown, schema-linking is used to process historical natural language queries, determining the correspondence between the tokens included in the historical natural language queries and the content of the target table. The content of the target table includes one or more of the following: the target table name, fields, and field values.

[0109] Schema-linking can be implemented based on artificial intelligence models, such as BERT or large language models. A pre-trained model is invoked to process historical natural language queries, yielding the table content of the target table in the database related to the historical queries.

[0110] Schema-linking can also be implemented using a trie retrieval method. A trie is a tree-like data structure consisting of multiple nodes, each representing a character. All characters on the path from the root node to each node can form a key-value pair (key, value).

[0111] As an example, a trie is constructed based on the various tables in the database, along with the table name, fields, and field values ​​for each table. The trie establishes the mapping between table names, fields, and field values. Information is stored in the trie in key-value pairs (key, value). Here, the key represents either a field or a field value. When the key represents a field, the value includes the table name of the table to which the field belongs and the field name. When the key represents a field value, the value includes the table name of the table to which the field value belongs, the data type of the key, and the name of the field to which the key belongs. The key's data type is the field value.

[0112] For example, consider a Project Delivery Details table in a database, containing representative offices (Representative Office in Location A, Representative Office in Location B). The table name is "Project Delivery Details Table." "Representative Office" is the field name. "Representative Office in Location A," "Representative Office in Location B," etc., are the corresponding field values. The key-value pairs in the trie for the contents of the Project Delivery Details table are: (Representative Office, Project Delivery Details Table_Field Name), (Representative Office in Location A, Project Delivery Details Table_Field Value_Representative Office), (Representative Office in Location B, Project Delivery Details Table_Field Value_Representative Office).

[0113] In this way, key-value pairs with the same key name can share the key name in the trie, thus saving storage space. At the same time, it allows for faster response when querying table content, improving the efficiency of retrieving table content based on word segmentation matching. The trie can also quickly determine whether word segmentation in historical natural language queries matches table content.

[0114] B2: Replace the word segmentation corresponding to the table content with the template text corresponding to the table content to obtain the natural language template statement.

[0115] The template text corresponding to the table content of the target table is pre-set. As an example, different field names have different corresponding template texts. For instance, the template text corresponding to a field name is columnX, where X can be a positive integer used to identify different field names. The template text corresponding to a field value is columnX_value, indicating that the field value is the field value corresponding to columnX. The template text set above is only an example, and this application does not limit the specific content of the template text.

[0116] The template text corresponding to the content of the target table is used to replace the word segmentation in the historical natural language query statement that corresponds to the content of the target table, thereby converting the historical natural language query statement into a natural language template statement.

[0117] In addition, some target tables have multiple candidate template texts corresponding to their content. For example, for time-related field values, multiple candidate template texts can be pre-set according to the time type.

[0118] For example, the database table contains a time-related field called "accounting period". Based on the semantics of "accounting period", four candidate template texts corresponding to the accounting period are pre-set: bilateral accounting period, unilateral accounting period, bilateral cut-off accounting period, and unilateral cut-off accounting period.

[0119] In this context, a bilateral accounting period refers to an accounting period with both an initial and an end date. Using months as the dimension, for example, "the second half of last year" corresponds to a bilateral accounting period. A unilateral accounting period refers to an accounting period with a single end date. For example, "February of last year" corresponds to a unilateral accounting period. A bilateral cutoff accounting period refers to an accounting period with an initial and an end date, where the initial date is the start time of the dimension and the end date is the current time. For example, "up to the current month of this year" corresponds to a bilateral cutoff accounting period. A unilateral cutoff accounting period refers to an accounting period up to the current time. For example, "before February" corresponds to a unilateral cutoff accounting period.

[0120] As an example, a bilateral accounting period can also be represented as Between lower and upper. The candidate template text for a unilateral accounting period is =time. The candidate template text for a bilateral cutoff accounting period is Between 01 and upper, where 01 represents January of the current year. The candidate template text for a unilateral cutoff accounting period is <=time, where lower, upper, and time are determined based on the time text included in historical natural language queries.

[0121] When transforming the content of a target table with multiple candidate template texts, the template text to be replaced is selected from the multiple candidate template texts based on the meaning of the time text corresponding to the content of the target table.

[0122] For example, a historical natural language query might be: "What is the revenue of Project A delivered by Representative Office A up to March of this year?" By segmenting the historical natural language query, we obtain: "Representative Office A", "Project A", "up to March of this year", "revenue", and "how much". Through word segmentation matching, we determine that "up to March of this year" matches "accounting period" in the target table. "Up to March of this year" is time-based text. Based on the semantics of "up to March of this year", it is determined to be a bilateral accounting period, thus the template text corresponding to "accounting period" is determined to be: bilateral accounting period. The above describes the process of generating a natural language template statement. After generating the natural language template statement, further optimization and adjustments can be made.

[0123] In one possible implementation, the generated natural language template statement may also include tokens that have not been converted into template text. Tokens that have not been converted into template text can be filtered.

[0124] Specifically, if the natural language template statement includes removable segments, the removable segments are removed from the natural language template statement to obtain the updated natural language template statement.

[0125] This application does not limit the implementation method of determining deletable word segments. As an example, a deletable word dictionary is pre-set. The deletable word dictionary includes deletable word segments. As an example, deletable word segments include those with low semantic relevance to historical natural language query statements, such as "please query" and "how much", which do not affect the semantics represented by the generated natural language template statement. Furthermore, deletable word segments can also be word segments that meet descriptive conditions. When the descriptive conditions are met, deletable word segments do not affect the semantic expression of the natural language template statement. For example, the descriptive condition is that "project" appears together with "project identifier" and is a deletable word segment. That is, when a project identifier exists, the specific project can be determined based on the project identifier without needing to be determined by the word segment "project", so "project" is a deletable word segment.

[0126] The dictionary of deleted words is used to search for word segments in the natural language template statement that have not been converted into template text. If a deleteable word segment that is the same as the deleted word segment is found, then the deleted word segment is treated as a deleteable word and deleted from the natural language template statement.

[0127] Additionally, it can vectorize natural language template statements to generate a first vector. As an example, an embedding model is used to process the natural language template statement to obtain the first vector.

[0128] The following example, using the historical natural language query "What was the revenue of Project C's products up to March?", illustrates the process of generating natural language template statements.

[0129] The query "What is the revenue amount of Project C's products up to March?" is segmented into words, yielding: "Project C", "up to March", "product", "of", "revenue amount", and "how much". Schema-linking confirms the correspondence between the segmented words in historical natural language queries and the content of the first table, "Delivered Project Revenue Details_By Product". "Project C" corresponds to the "Project" field and its value in the table. "Up to March" corresponds to the "Accounting Period" field value in the table. "Product" corresponds to the "Product" field in the table. "Revenue amount" corresponds to the "Amount" field in the table.

[0130] The template text for the "Project" field name in the table is "column1". The template text for the "Project" field value in the table is "column1_value". The template text for the "Accounting Period" field value and the semantics of "up to March" is "bilateral closing accounting period". The template text for the "Product" field in the table is "column2". The template text for the "Amount" field in the table is "metric1".

[0131] Replacing the word segmentation of the historical natural language query statement with the template text corresponding to the table content of the word segmentation, we obtain: What is (metric1) in (column2) of (accounting period) where (column1=column1_value)?

[0132] Further, by querying the deletable word dictionary, "what is" is determined as a deletable word segmentation. After deleting "what is", a natural language template statement is obtained: (metric1) in (column2) of (double-sided cut-off accounting period) where (column1=column1_value).

[0133] The above is the method for generating natural language template statements. Correspondingly, the present application also provides a possible implementation manner for generating SQL template statements.

[0134] Second: the process of generating SQL template statements.

[0135] See Figure 6 for obtaining historical SQL query statements.

[0136] The historical SQL query statement includes the table content of the target table. Based on the template text corresponding to the table content of the target table, the table content of the target table included in the historical SQL query statement is replaced to obtain an SQL template statement.

[0137] As an example, the historical SQL query statement is: SELECT "product type", SUM("amount") AS "revenue amount" FROM "delivery project revenue details by product" WHERE "project code" = 'project C' AND "accounting period" BETWEEN 01 AND 03 GROUP BY "product type".

[0138] Among them, "product type", which is also "product", corresponds to the template text "column2". The template text corresponding to "amount" is "metric1". "Delivery project revenue details by product" is a table name, and its corresponding template text is "table". "Project code", which is also "project", corresponds to the template text "column1". "Project C" is the field value of "project", and its corresponding template text is "column1_value". "BETWEEN 01 AND 03" is a double-sided cut-off accounting period, and its corresponding template text is "BETWEEN {01} AND {upper}".

[0139] Based on the template text corresponding to the table content, the table content included in the historical SQL query statement is replaced, and the resulting SQL template statement is: SELECT "{column2}", SUM(metric1) FROM "{table}" WHERE "{column1}" = '{column1_value}' AND "accounting period" BETWEEN{01} AND {upper} GROUP BY "{column2}".

[0140] Templated natural language and SQL template statements can summarize table content. During matching, there's no need to consider specific table details, improving the generalization of template statements and expanding their matching range.

[0141] After generating natural language template statements and SQL template statements, these statements can be compared with previously generated natural language template statements and SQL template statements. If the currently generated natural language template statements and SQL template statements do not overlap with previously generated natural language template statements and SQL template statements, then these statements are written into the template statement library.

[0142] Natural language template statements and SQL template statements can be stored as case information in a template statement library. An example template statement library is Elasticsearch (an open-source distributed search and analytics engine). The template statement library can be stored on the device where the computing device is deployed. It can also be stored on other devices so that the computing device can obtain natural language template statements and SQL template statements through interaction with other devices.

[0143] A case information can include the historical natural language query statements used to generate the natural language template statements, the historical SQL query statements used to generate the SQL template statements, the natural language template statements, the SQL template statements, the keywords (key_words) included in the historical natural language query statements, the table name of the table queried by the historical SQL query statements, the domain, and the first vector (vctore) of the natural language template statements.

[0144] Keywords can be pre-defined terms that are important for semantic expression and business operations. A keyword dictionary is pre-set to include these keywords. The keyword dictionary is used to store keywords. As an example, keywords include terms such as percentage, year-on-year, same period, month-on-month, period, and grouping.

[0145] The domain can be based on the user's professional field, the business domain to which the table belongs, and the domain to which the data retrieved by historical natural language queries belong.

[0146] Based on the above introduction to natural language template statements and SQL template statements, it can be seen that natural language template statements can represent a specific type of query statement with specific semantics and structure. The accuracy of natural language template statements is lower than that of natural language sample statements.

[0147] See Figure 4 As shown, when a natural language sample statement cannot be matched by exact matching, approximate matching can be used to find a natural language template statement that is similar to the natural language query statement in terms of syntax and semantics.

[0148] The approximate matching process mainly includes the following three steps, C1-C3.

[0149] C1: When a natural language query statement cannot be precisely matched with a natural language sample statement, a natural language query statement is obtained from the template statement library.

[0150] From the template statement library, natural language template statements that do not undergo approximate matching with the natural language query statement are selected as the objects of this approximate matching. This application does not limit the method of obtaining natural language template statements. For example, natural language template statements can be randomly selected from the template statement library, or they can be selected sequentially.

[0151] C2: Performs approximate matching between natural language query statements and natural language template statements.

[0152] In one possible implementation, approximate matching refers to a comparison method at the statement feature level. Specifically, it calculates the statement feature similarity between the natural language query statement and the natural language template statement. Based on the statement feature similarity, it determines whether the natural language template statement matches the natural language query statement.

[0153] In one possible implementation, the natural language query statement is first templated, converted into a template statement, to obtain the template statement to be matched. Then, the template statement to be matched is matched with the natural language template statement.

[0154] The format requirements for the template statement to be matched are the same as those for the template statement in natural language.

[0155] The method of converting natural language query statements into template statements to be matched is similar to the method of converting historical natural language query statements into natural language template statements described above.

[0156] Specifically, the natural language query is first segmented into words, and the first table queried by the query is determined. Then, the correspondence between the segmented words and the content of the first table is established. The content of the first table includes one or more of the table's name, fields, and field values. Finally, the segmented words corresponding to the table content are replaced with the corresponding template text to obtain the template statement to be matched.

[0157] The template statement to be matched is approximated with the natural language template statement, and the similarity of statement features between the natural language query statement and the natural language template statement is calculated.

[0158] This application does not limit the content included in sentence feature similarity. As an example, sentence feature similarity includes one or more of template similarity, vector similarity, keyword feature similarity, and quantity similarity.

[0159] Template similarity is the similarity of characters between the template statement to be matched and the natural language template statement.

[0160] Vector similarity is the similarity between the first vector of a natural language template statement and the second vector of the template statement to be matched. The second vector of the template statement to be matched can be generated in the same way as the first vector. For example, an embedding model can be used to process the template statement to be matched to obtain the second vector. As an example, cosine similarity can be used to calculate vector similarity.

[0161] Keyword similarity is the similarity between the keywords of the natural language template statement and the keywords of the template statement to be matched. Keywords refer to predefined words that are important for semantic expression or business logic. Keywords can be determined based on a keyword dictionary.

[0162] Quantitative similarity refers to the similarity between the quantitative parameters of a natural language template statement and the quantitative parameters of the template statement to be matched. For example, quantitative parameters include the number of fields, the number of field values, and the number of table contents to be matched.

[0163] It should be noted that when sentence feature similarity includes multiple types such as template similarity, vector similarity, keyword feature similarity, and quantity similarity, a weighted value of each type of similarity can be calculated to obtain the sentence feature similarity. The weights of each type of similarity can be set as needed.

[0164] Based on sentence feature similarity, the natural language template sentences that match the template sentence to be matched can be determined more accurately, thereby improving the accuracy of the matched natural language template sentences.

[0165] In one possible implementation, if the similarity of statement features is greater than or equal to a similarity threshold, then the natural language query statement is determined to be approximately matched with the natural language template statement. Execute C3, and use the approximately matched natural language template statement as the natural language case statement.

[0166] If the similarity of statement features between the natural language query and the natural language template statement is less than the similarity threshold, it is determined that the natural language query and the natural language template statement cannot be precisely matched. Step C1 can be re-executed to obtain natural language template statements from the template statement library that have not undergone statement feature similarity calculation with the natural language query statement for approximate matching.

[0167] C3: Use the natural language template statements obtained from approximate matching as natural language case statements.

[0168] It should be noted that if there are multiple natural language template statements in the template statement library that are approximately matched with the natural language query statement, then the natural language template statement with the highest statement feature similarity will be used as the natural language case statement.

[0169] After approximate matching identifies the natural language template statement that matches the natural language query statement, the corresponding SQL template statement is retrieved from the template database. Using the SQL template statement and the natural language query statement, the SQL query statement derived from the natural language query statement is generated.

[0170] In one possible implementation, the template text included in the SQL template statement is replaced with the table content corresponding to the template text to generate the SQL query statement.

[0171] Taking the above SQL template statement as an example: SELECT "{column2}", SUM(metric1) FROM "{table}" WHERE "{column1}" = '{column1_value}' AND "accounting period" BETWEEN{01} AND {upper} GROUP BY "{column2}". Here, column1, column2, column1_value, BETWEEN{01} AND {upper}, column2, metric1, and table are template text. "BETWEEN{01} AND {upper}" is another way to express "bilateral cut-off accounting period". The other text is fixed text. Replace the template text with the corresponding table content.

[0172] The replaced SQL query is: SELECT "Product Type", SUM("Amount") AS "Revenue Amount" FROM "Delivered Project Revenue Details_Sub-Product" WHERE "Project Code" = 'Project A' AND "Accounting Period" BETWEEN 01 AND 03 GROUP BY "Product Type".

[0173] The above describes the process of exact matching, approximate matching, and generating SQL queries using SQL case statements. Additionally, in some cases, if no natural language case statement is found that matches the natural language query, it means that there is currently no natural language case statement that is close enough to the natural language query. See also... Figure 4 As shown, a language transformation model is used to process natural language queries and generate SQL queries. The language transformation model is used to convert natural language queries into SQL queries. A large language model is an example of such a model.

[0174] This application does not limit the implementation method of generating SQL query statements based on a language conversion model. As an example, schema_linking is called to process natural language query statements and obtain the correspondence between word segmentation and table content. Using the correspondence between word segmentation and table content as reference information, prompt words are generated. A query statement with query logic similar to pandas (an open-source Python data analysis library) is generated using a language conversion model. Then, according to the conversion rules, the query statement with pandas query logic is converted into an SQL query statement.

[0175] The generated SQL query statement can be sent to the database so that the query operation can be executed according to the SQL query statement to obtain the query results. The query results include the data obtained by executing the SQL query statement.

[0176] This application also provides a query statement generation apparatus, wherein the query statement generation apparatus is located in a computing device, such as... Figure 7 As shown, it includes:

[0177] Module 701 is used to obtain natural language query statements;

[0178] The determining module 702 is used to determine natural language example statements that match the natural language query statement according to a hierarchical matching strategy. The hierarchical matching strategy is used to instruct the natural language query statement to be precisely matched. If no natural language example statement is obtained by precise matching, the natural language query statement is approximate matched. The precision of precise matching is higher than the precision of approximate matching.

[0179] The conversion module 703 is used to convert the natural language query statement into a structured query language query statement based on the structured query language example statement corresponding to the natural language example statement.

[0180] It should be understood that the query statement generation device of this application can be implemented by a central processing unit (CPU), an application-specific integrated circuit (ASIC), or a programmable logic device (PLD). The PLD can be a complex programmable logical device (CPLD), a field-programmable gate array (FPGA), a generic array logic (GAL), a data processing unit (DPU), a system-on-chip (SoC), or any combination thereof. It can also be implemented in software. Figures 2 to 6 In the generation method shown, the query statement generation device and its various modules can also be software modules.

[0181] In one possible implementation, the determining module 702 is specifically used for: obtaining natural language sample statements, the natural language sample statements belonging to a sample statement library; performing precise matching between the natural language query statement and the natural language sample statements, the precise matching being used to indicate a comparison method based on word-to-word matching in the sample statement library; and using the natural language sample statements obtained through precise matching as natural language case statements.

[0182] In one possible implementation, the determining module 702 is further configured to: when the natural language query statement and the natural language sample statement cannot be precisely matched, obtain a natural language template statement, the natural language template statement belonging to a template statement library; perform an approximate match between the natural language query statement and the natural language template statement, the natural language template statement being obtained by template processing of the natural language sample statement, the approximate match being used to indicate the matching method based on the template statement library; and use the natural language template statement obtained by the approximate match as a natural language case statement.

[0183] In one possible implementation, the determining module 702 is used to perform approximate matching between the natural language query statement and the natural language template statement, including: the determining module 702 is used to perform template processing on the natural language query statement to obtain a template statement to be matched; and to match the statement features of the template statement to be matched with the statement features of the natural language template statements included in the template statement library.

[0184] In one possible implementation, the determining module 702 is used to perform template processing on the natural language query statement to obtain a template statement to be matched, including: the determining module 702 is used to determine the correspondence between the word segments included in the natural language query statement and the table content of a first table, wherein the first table is the table queried by the natural language query statement, and the table content includes one or more of the name, fields, and field values ​​of the first table; replacing the word segments corresponding to the table content with the template text corresponding to the table content to obtain the template statement to be matched, wherein the template text is a pre-set text that conforms to the template statement format requirements.

[0185] In one possible implementation, the word segmentation is time text, and the determination module 702 is further configured to: determine the template text corresponding to the table content from multiple candidate template texts corresponding to the table content based on the semantics of the time text.

[0186] In one possible implementation, the natural language case statement is a natural language sample statement, and the structured query language case statement is a structured query language sample statement. The conversion module 703 is specifically used to: determine a first time value of the natural language query statement based on the time text included in the natural language query statement; and replace the second time value included in the structured query language sample statement with the first time value to obtain a structured query language query statement.

[0187] In one possible implementation, the natural language case statement is a natural language template statement, and the structured query language case statement is a structured query language template statement. The conversion module 703 is specifically used to: replace the template text included in the structured query language template statement with the table content corresponding to the template text to generate a structured query language query statement.

[0188] The acquisition module 701, determination module 702, and conversion module 703 can all be implemented in software or in hardware. For example, the implementation of the acquisition module 701 will be described below. Similarly, the implementation of the determination module 702 and conversion module 703 can refer to the implementation of the acquisition module 701.

[0189] As an example of a software functional unit, module 701 may include code running on a computing instance. The computing instance may include at least one of a physical host (computing device), a virtual machine, or a container. Further, the aforementioned computing instance may be one or more. For example, module 701 may include code running on multiple hosts / virtual machines / containers. It should be noted that the multiple hosts / virtual machines / containers used to run the code may be distributed within the same region or in different regions. Further, the multiple hosts / virtual machines / containers used to run the code may be distributed within the same availability zone (AZ) or in different AZs, each AZ including one or more geographically proximate data centers. Typically, a region may include multiple AZs.

[0190] Similarly, multiple hosts / virtual machines / containers used to run this code can be distributed within the same Virtual Private Cloud (VPC) or across multiple VPCs. Typically, a VPC is set up within a region. Communication between two VPCs within the same region, as well as between VPCs in different regions, requires a communication gateway to be set up within each VPC to enable interconnection between VPCs.

[0191] As an example of a hardware functional unit, the acquisition module 701 may include at least one computing device, such as a server. Alternatively, the acquisition module 701 may be implemented using a central processing unit (CPU), an application-specific integrated circuit (ASIC), or a programmable logic device (PLD). The PLD may be a complex programmable logical device (CPLD), a field-programmable gate array (FPGA), a generic array logic (GAL), a data processing unit (DPU), a neural network processing unit (NPU), a system-on-chip (SoC), an offload card, an accelerator card, or any combination thereof.

[0192] The multiple computing devices included in the acquisition module 701 can be distributed in the same region or in different regions. Similarly, the multiple computing devices included in the acquisition module 701 can be distributed in the same Availability Zone (AZ) or in different AZs. Likewise, the multiple computing devices included in the acquisition module 701 can be distributed in the same Virtual Private Cloud (VPC) or in multiple VPCs. These multiple computing devices can be any combination of computing devices such as servers, ASICs, PLDs, CPLDs, FPGAs, GALs, DPUs, NPUs, SoCs, offloading cards, and accelerator cards.

[0193] It should be noted that, in other embodiments, the acquisition module 701 can be used to execute any step in the query statement generation method, the determination module 702 can be used to execute any step in the query statement generation method, and the conversion module 703 can be used to execute any step in the query statement generation method. The steps implemented by the acquisition module 701, the determination module 702, and the conversion module 703 can be specified as needed. By implementing different steps in the query statement generation method through the acquisition module 701, the determination module 702, and the conversion module 703, the full functionality of the query statement generation device can be achieved.

[0194] This application also provides a chip system including a processor and a power supply circuit. The power supply circuit supplies power to the processor, which executes the operation steps corresponding to the query statement generation method. For simplicity, further details are omitted here. The processor can be implemented using a GPU, or it can be implemented using computing devices such as a DPU, NPU, XPU, SoC, offload card, or accelerator card.

[0195] This application also provides a computing device 800. For example... Figure 8 As shown, the computing device 800 includes a bus 802, a processor 804, a memory 806, and a communication interface 808. The processor 804, the memory 806, and the communication interface 808 communicate with each other via the bus 802. The computing device 800 can be a server or a terminal device. It should be understood that this application does not limit the number of processors and memories in the computing device 800.

[0196] The 802 bus can be a Peripheral Component Interconnect Express (PCIe) bus, an Extended Industry Standard Architecture (EISA) bus, a Unified Bus (Ubus or UB), a Compute Express Link (CXL) bus, a Cache Coherent Interconnect for Accelerators (CCIX) bus, etc. The Unified Bus is also known as the Lingqu bus. Buses can be divided into address buses, data buses, control buses, etc. For ease of representation, Figure 8 The bus is represented by only one line, but this does not mean that there is only one bus or one type of bus. Bus 804 may include a path for transmitting information between various components of computing device 800 (e.g., memory 806, processor 804, communication interface 808). The unified bus may also be called the Lingqu bus.

[0197] The processor 804 may include any one or more computing devices such as a central processing unit (CPU), a graphics processing unit (GPU), a microprocessor (MP) or a digital signal processor (DSP), an ASIC, an FPGA, a CPLD, an NPU, a SoC, an offload card, or an accelerator card.

[0198] Memory 806 may include volatile memory, such as random access memory (RAM). Processor 804 may also include non-volatile memory, such as read-only memory (ROM), flash memory, hard disk drive (HDD), or solid state drive (SSD). Furthermore, memory 806 may also be implemented using storage class memory (SCM), phase change memory (PCM), or other types of storage media.

[0199] It is worth noting that the same type of storage medium can be configured in the same computing device to realize the function of memory 806, or two or more types of storage media can be configured to realize the function of memory 806. This application does not limit this.

[0200] The memory 806 stores executable program code, which the processor 804 executes to implement the functions of the aforementioned acquisition module 701, determination module 702, and conversion module 703, thereby realizing the query statement generation method. In other words, the memory 806 stores instructions for executing the query statement generation method.

[0201] The communication interface 803 uses transceiver modules, such as, but not limited to, network interface cards and transceivers, to enable communication between the computing device 800 and other devices or communication networks.

[0202] As one possible implementation, the computing device 800 may also include a chip system, which includes a processor and a power supply circuit. The power supply circuit supplies power to the processor, and the processor executes the operation steps corresponding to the query statement generation method. For simplicity, further details are omitted here. The processor can be implemented using a GPU, or it can be implemented using computing devices or AI chips such as a DPU, NPU, XPU, SoC, offloading card, or accelerator card.

[0203] As one possible implementation, the computing device 800 may include multiple types of processors 804, meaning the computing device 800 is a heterogeneous device. For example, the computing device 800 may include a CPU and a GPU, and the operation steps corresponding to the query statement generation method can be executed by at least one of the processors 804. For the sake of brevity, further details will not be provided here.

[0204] This application also provides a computing device cluster. The computing device cluster includes at least one computing device. The computing device can be a server, such as a central server, an edge server, or a local server in a local data center. In some embodiments, the computing device can also be a terminal device such as a desktop computer, a laptop computer, or a smartphone.

[0205] like Figure 9 As shown, the computing device cluster includes at least one computing device 800. The memory 806 of one or more computing devices 800 in the computing device cluster may store the same instructions for generating query statements.

[0206] In some possible implementations, the memory 806 of one or more computing devices 800 in the computing device cluster may also store partial instructions for executing the query statement generation method. In other words, a combination of one or more computing devices 800 can jointly execute the instructions for executing the query statement generation method.

[0207] It should be noted that the memory 806 in different computing devices 800 within the computing device cluster can store different instructions, which are used to execute parts of the functions of the query statement generation device. That is, the instructions stored in the memory 806 of different computing devices 800 can implement the functions of one or more modules among the acquisition module 701, the determination module 702, and the conversion module 703.

[0208] In some possible implementations, one or more computing devices in a computing device cluster can be connected via a network. This network can be a wide area network (WAN) or a local area network (LAN), etc. Figure 10 One possible implementation is shown. For example... Figure 10 As shown, two computing devices 800A and 800B are connected via a network. Specifically, they are connected to the network through communication interfaces in each computing device. In this possible implementation, the memory 806 in computing device 800A stores instructions for executing the functions of the acquisition module 701 and the determination module 702. Simultaneously, the memory 806 in computing device 800B stores instructions for executing the functions of the conversion module 703.

[0209] Figure 10 The connection method between the computing device clusters shown can be such that, considering the query statement generation method provided in this application requires a large amount of data storage and processing, the functions implemented by the conversion module 703 are delegated to the computing device 800B.

[0210] It should be understood that Figure 10 The functions of the computing device 800A shown can also be performed by multiple computing devices 800. Similarly, the functions of the computing device 800B can also be performed by multiple computing devices 800.

[0211] This application also provides a computer program product containing instructions. The computer program product may be a software or program product containing instructions, capable of running on a computing device or stored on any usable medium. When the computer program product is run on at least one computing device, it causes the at least one computing device to execute a query statement generation method.

[0212] This application also provides a computer-readable storage medium. The computer-readable storage medium can be any available medium capable of being stored by a computing device, or a data storage device such as a data center containing one or more available media. The available medium can be a magnetic medium (e.g., floppy disk, hard disk, magnetic tape), an optical medium (e.g., DVD), or a semiconductor medium (e.g., solid-state drive). The computer-readable storage medium includes instructions that instruct a computing device to execute a query statement generation method.

[0213] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, and not to limit them; although the present invention has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features; and these modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the protection scope of the technical solutions of the embodiments of the present invention.

Claims

1. A method for generating query statements, characterized in that, The method is performed by a computing device, and the method includes: Retrieve natural language query statements; According to the hierarchical matching strategy, natural language example statements that match the natural language query statement are determined. The hierarchical matching strategy is used to indicate that the natural language query statement is precisely matched. If no natural language example statement is obtained by precise matching, the natural language query statement is approximate matched. The precision of precise matching is higher than the precision of approximate matching. Based on the structured query language case statement corresponding to the natural language case statement, the natural language query statement is converted into a structured query language query statement.

2. The method according to claim 1, characterized in that, The step of determining the natural language case statements that match the natural language query statement according to the hierarchical matching strategy includes: Obtain natural language sample sentences, which belong to a sample sentence library; The natural language query statement is precisely matched with the natural language sample statement, and the precise matching is used to indicate the comparison method based on word-to-word matching of the sample statement library; The natural language sample sentences obtained through precise matching are used as natural language case sentences.

3. The method according to claim 2, characterized in that, The method further includes: When the natural language query statement cannot be precisely matched with the natural language sample statement, a natural language template statement is obtained, and the natural language template statement belongs to the template statement library. The natural language query statement is approximated by a natural language template statement, which is obtained by templated processing of the natural language sample statement. The approximation matching is used to indicate the matching method based on the template statement library. The natural language template statement obtained through approximate matching is used as the natural language case statement.

4. The method according to claim 3, characterized in that, The step of performing an approximate match between the natural language query statement and the natural language template statement includes: The natural language query statement is templated to obtain the template statement to be matched; The statement features of the template statement to be matched are matched with the statement features of the natural language template statements included in the template statement library.

5. The method according to claim 4, characterized in that, The process of template-processing the natural language query statement to obtain a template statement to be matched includes: Determine the correspondence between the word segments included in the natural language query statement and the table content of the first table, wherein the first table is the table queried by the natural language query statement, and the table content includes one or more of the name, fields, and field values ​​of the first table; Replace the word segment corresponding to the table content with the template text corresponding to the table content to obtain the template statement to be matched. The template text is a pre-set text that conforms to the template statement format requirements.

6. The method according to claim 5, characterized in that, The word segmentation is time-based text, and the method further includes: Based on the semantics of the time text, the template text corresponding to the table content is determined from a variety of candidate template texts corresponding to the table content.

7. The method according to any one of claims 1 to 6, characterized in that, The natural language example statement is a natural language sample statement, and the structured query language example statement is a structured query language sample statement. The step of converting the natural language query statement into a structured query language query statement based on the structured query language example statement corresponding to the natural language example statement includes: Based on the time text included in the natural language query statement, determine the first time value of the natural language query statement; The second time value included in the structured query language sample statement is replaced with the first time value to obtain the structured query language query statement.

8. The method according to any one of claims 1 to 6, characterized in that, The natural language example statement is a natural language template statement, and the structured query language example statement is a structured query language template statement. The step of converting the natural language query statement into a structured query language query statement based on the structured query language example statement corresponding to the natural language example statement includes: The template text included in the Structured Query Language template statement is replaced with the table content corresponding to the template text to generate a Structured Query Language query statement.

9. A query statement generation apparatus, characterized in that, The device is deployed in a computing device, and the device includes: The acquisition module is used to acquire natural language query statements; The determination module is used to determine natural language example statements that match the natural language query statement according to a hierarchical matching strategy. The hierarchical matching strategy is used to instruct the natural language query statement to be precisely matched. If no natural language example statement is obtained by precise matching, the natural language query statement is approximate matched. The precision of precise matching is higher than the precision of approximate matching. The conversion module is used to convert the natural language query statement into a structured query language query statement based on the structured query language example statement corresponding to the natural language example statement.

10. A computing device, characterized in that, The computing device includes a processor and memory; The processor is configured to execute instructions stored in the memory to cause the computing device to perform the operational steps of the method as described in any one of claims 1 to 8.

11. A computing device cluster, characterized in that, It includes at least one computing device, each computing device including a processor and memory; The processor of the at least one computing device is configured to execute instructions stored in the memory of the at least one computing device to cause the cluster of computing devices to perform the operational steps of the method as described in any one of claims 1 to 8.

12. A computer program product containing instructions, characterized in that, When the instruction is executed by the computing device cluster, the computing device cluster causes the computing device cluster to perform the operation steps of the method as described in any one of claims 1 to 8.

13. A computer-readable storage medium, characterized in that, It includes computer program instructions, which, when executed by a cluster of computing devices, perform the operational steps of the method as described in any one of claims 1 to 8.