Structured query statement generation method and device and computer equipment

By splitting user questions into atomic questions, using comparison tables and twin neural network matching, and abstracting them into parameterized templates to generate target structured query statements, the problem of low accuracy in converting natural language into SQL statements is solved, and efficient and accurate data query is achieved.

CN120705168APending Publication Date: 2025-09-26CHINA TOBACCO ZHEJIANG IND CO LTD
View PDF 0 Cites 1 Cited by

Patent Information

Application Number
CN202510857262.8
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-06-24
Publication Date
2025-09-26

AI Technical Summary

Technical Problem

The accuracy of converting natural language into SQL statements in the existing technology is low, especially when faced with complex domain-specific terms or non-standard expressions, it is difficult to achieve accurate conversion.

Method used

The original question input by the user is split into multiple atomic questions, and similarity matching is performed through a preset comparison table and a twin neural network to determine the target natural language statement and the initial structured query statement, which are abstracted into a parameterizable template, and the target structured query statement is generated based on the template and the atomic question.

Benefits of technology

It improves the efficiency and accuracy of converting natural language into structured query statements in SQL format, ensures that the generated query statements match the data model of the database, and improves the efficiency and accuracy of data query.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120705168A_ABST
    Figure CN120705168A_ABST
Patent Text Reader

Abstract

The invention relates to a structured query statement generation method and device and computer equipment. The method comprises the steps of obtaining an original question input by a user, and splitting the original question into at least one atomic question; performing similarity matching on each atomic question and natural language statements in a preset comparison table, and determining a target natural language statement corresponding to the atomic question and an initial structured query statement corresponding to the target natural language statement; wherein the comparison table comprises a plurality of preset corresponding relations between structured query statements and natural language statements; the initial structured query statement is abstracted into a parameterizable template, a target structured query statement corresponding to the atomic problem is generated based on the parameterizable template and the corresponding atomic problem, and the parameterizable template carries structural information of the initial structured query statement. By adopting the method, the accuracy and efficiency of converting the natural language into the SQL statement can be improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the technical field of natural language processing and database query, and in particular to a method, apparatus and computer equipment for generating structured query statements. Background Art

[0002] ChatBI (Chat Business Intelligence) is a tool that combines natural language processing (NLP), machine learning (ML), and other artificial intelligence technologies. Its purpose is to enable users to interact with business intelligence (BI) systems through natural language conversations, thereby gaining data analysis results and insights. The ChatBI process is as follows: users enter queries in natural language. The system uses natural language processing (NLP) technology to identify intent and extract entities, converting the natural language into structured query logic (such as Structured Query Language (SQL) statements) and executing the query by connecting to a specified data source. Query results are formatted and visualized, then presented to users as charts or reports.

[0003] To obtain accurate query results, the first prerequisite is to convert the user's natural language query statements into precise query SQL statements. Although Text2SQL technology has made significant progress in academia, with many research papers demonstrating its potential in converting natural language queries into SQL statements, applying Text2SQL technology to actual engineering development still faces several challenges. First, natural language itself is highly complex and ambiguous. The same sentence may be interpreted in multiple ways, especially when involving domain-specific terminology or non-standard expressions. This uncertainty makes it very difficult to accurately convert natural language into SQL statements. Second, different databases have different data schemas, including table structures, field names, etc., and the Text2SQL system also struggles to adapt to various different data schemas.

[0004] Currently, no effective solution has been proposed to address the problem of low accuracy in converting natural language into SQL statements in existing technologies. Summary of the Invention

[0005] Based on this, it is necessary to provide a method, device and computer equipment for generating structured query statements to address the above technical problems.

[0006] In a first aspect, the present application provides a method for generating a structured query statement. The method comprises:

[0007] Obtaining an original question input by the user, and splitting the original question into at least one atomic question;

[0008] Performing similarity matching between each atomic question and a natural language statement in a preset comparison table to determine a target natural language statement corresponding to the atomic question and an initial structured query statement corresponding to the target natural language statement; wherein the comparison table includes a plurality of preset correspondences between structured query statements and natural language statements;

[0009] The initial structured query statement is abstracted into a parameterizable template, and a target structured query statement corresponding to the atomic question is generated based on the parameterizable template and the corresponding atomic question, wherein the parameterizable template carries the structural information of the initial structured query statement.

[0010] In one embodiment, obtaining an original question input by a user and splitting the original question into at least one atomic question includes:

[0011] If the original question is detected to be a question of the preset target type;

[0012] Search the preset technical knowledge base according to the original question to obtain relevant technical knowledge corresponding to the original question;

[0013] Based on relevant technical knowledge, the preset large language model is guided to decompose the original question into multiple atomic questions.

[0014] In one embodiment, each atomic question is matched with a natural language sentence in a preset comparison table by similarity, including:

[0015] Through the preset twin neural network, the semantic similarity between the atomic question and each natural language sentence in the comparison table is calculated to obtain the semantic similarity between each natural language sentence and the atomic question;

[0016] Determine a natural language sentence whose semantic similarity with the atomic question is greater than a preset similarity threshold as a first target natural language sentence;

[0017] The natural language sentence with the highest semantic similarity to the atomic question among all the first target natural language sentences is determined as the sentence corresponding to the atomic question.

[0018] In one embodiment, after obtaining the semantic similarity between each natural language sentence and the atomic question, the method further includes:

[0019] If the matching result between the atomic question and the natural language sentence is that the semantic similarity between each natural language sentence and the atomic question is less than the similarity threshold;

[0020] The matching results are fed back to the preset device end to modify the atomic problem.

[0021] In one embodiment, the initial structured query statement is abstracted into a parameterizable template, including:

[0022] Identifying constant values ​​in the initial structured query statement and generating a parameter identifier for each constant value;

[0023] Replace the constant values ​​in the initial structured query statement with the preset parameter placeholders;

[0024] A parameterizable template is obtained, wherein the parameterizable template carries a mapping relationship between constant values ​​and parameter identifiers.

[0025] In one embodiment, generating a target structured query statement corresponding to the atomic question based on the parameterizable template and the corresponding atomic question includes:

[0026] Identify key information in the atomic problem, where the key information at least includes key entities in the atomic problem and dependencies between key entities;

[0027] Based on the preset mapping model and the mapping relationship between constant values ​​and parameter identifiers, the key information is mapped to the corresponding parameter positions in the parameterizable template to generate the target structured query statement.

[0028] In one embodiment, after generating the target structured query statement, the method further includes:

[0029] The target structured query statement is sent to the preset device end, and the feedback result corresponding to the target structured query statement provided by the user is obtained.

[0030] In one embodiment, after generating the target structured query statement, the method further includes:

[0031] A correspondence is established between the target structured query statement and the corresponding atomic question, and the correspondence between the target structured query statement and the atomic question is added to a comparison table.

[0032] In a second aspect, the present application further provides a device for generating a structured query statement. The device comprises:

[0033] An acquisition module, used to obtain the original question input by the user and split the original question into at least one atomic question;

[0034] a calculation module configured to perform similarity matching between each atomic question and a natural language statement in a preset comparison table, and to determine an initial structured query statement corresponding to the natural language statement based on the matching results; wherein the comparison table includes a plurality of preset correspondences between structured query statements and natural language statements;

[0035] The generation module is used to abstract the initial structured query statement into a parameterizable template, and generate a target structured query statement corresponding to the atomic question based on the parameterizable template and the corresponding atomic question.

[0036] In a third aspect, the present application further provides a computer device. The computer device includes a memory and a processor, wherein the memory stores a computer program, and when the processor executes the computer program, the following steps are performed:

[0037] Obtaining an original question input by the user, and splitting the original question into at least one atomic question;

[0038] Performing similarity matching between each atomic question and a natural language statement in a preset comparison table to determine a target natural language statement corresponding to the atomic question and an initial structured query statement corresponding to the target natural language statement; wherein the comparison table includes a plurality of preset correspondences between structured query statements and natural language statements;

[0039] The initial structured query statement is abstracted into a parameterizable template, and a target structured query statement corresponding to the atomic question is generated based on the parameterizable template and the corresponding atomic question, wherein the parameterizable template carries the structural information of the initial structured query statement.

[0040] The above-mentioned method, apparatus, and computer device for generating a structured query statement split the original question into at least one atomic question, and perform similarity matching between each atomic question and a natural language statement in a comparison table, determine a target natural language statement corresponding to the atomic question, and an initial structured query statement corresponding to the target natural language statement, abstract the initial structured query statement into a parameterizable template, and generate a target structured query statement corresponding to the atomic question based on the parameterizable template and the corresponding atomic question, wherein the parameterizable template carries the structural information of the initial structured query statement. This application can improve the efficiency and accuracy of converting natural language statements into target structured query statements in SQL format. BRIEF DESCRIPTION OF THE DRAWINGS

[0041] Figure 1 FIG1 is an application environment diagram of a method for generating a structured query statement in an embodiment;

[0042] Figure 2 A schematic diagram of a flow chart of a method for generating a structured query statement in one embodiment;

[0043] Figure 3 Schematic diagram of a flow chart of a method for generating a structured query statement in a preferred embodiment;

[0044] Figure 4 is a structural block diagram of a device for generating a structured query statement in one embodiment;

[0045] Figure 5 FIG. 1 is a diagram showing the internal structure of a computer device in one embodiment. DETAILED DESCRIPTION

[0046] In order to make the purpose, technical solutions and advantages of this application more clear, the following further describes this application in detail with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain this application and are not intended to limit this application.

[0047] The method for generating a structured query statement provided in the embodiment of the present application can be applied to Figure 1 In the application environment shown, the terminal 102 communicates with the server 104 via a network. The data storage system can store data that the server 104 needs to process. The data storage system can be integrated on the server 104, or placed on a cloud or other network server. The original question input by the user is obtained and split into at least one atomic question; each atomic question is matched with a natural language statement in a preset comparison table for similarity, and a target natural language statement corresponding to the atomic question and an initial structured query statement corresponding to the target natural language statement are determined; wherein the comparison table includes a correspondence between multiple preset structured query statements and natural language statements; the initial structured query statement is abstracted into a parameterizable template, and a target structured query statement corresponding to the atomic question is generated based on the parameterizable template and the corresponding atomic question, wherein the parameterizable template carries the structural information of the initial structured query statement. The terminal 102 can be, but is not limited to, various personal computers, laptops, smart phones, tablets, Internet of Things devices, and portable wearable devices. The Internet of Things devices can be smart speakers, smart TVs, smart air conditioners, smart car devices, etc. The portable wearable device may be a smart watch, a smart bracelet, a head-mounted device, etc. The server 104 may be implemented as an independent server or a server cluster consisting of multiple servers.

[0048] In one embodiment, Figure 2 As shown, a method for generating a structured query statement is provided, and the method is applied to Figure 1 The following steps are used as an example to illustrate the server in the example:

[0049] Step S210: Obtain the original question input by the user, and split the original question into at least one atomic question.

[0050] Specifically, the original question is a natural language input by the user. After obtaining the original question input by the user, the original question is split into multiple atomic questions, wherein an atomic question refers to a sub-question relative to the original question. The atomic question is similar to the original question but not the same as the original question. In some preferred embodiments, the atomic question is more detailed, precise, and semantically clearer than the original question. For example, assuming the original question is "How is the market performance of Liqun sales in March 2024?" The corresponding atomic questions include but are not limited to: "What is the sales volume of Liqun Class I cigarettes in March 2024? What is the sales volume of Liqun high-priced cigarettes in March 2024? What is the sales volume of Liqun regular cigarettes in March 2024? What is the sales volume of Liqun slim cigarettes in March 2024?" and so on.

[0051] Furthermore, methods for splitting the original problem into multiple atomic problems include, but are not limited to, splitting the original problem with the help of an existing large language model, or manually splitting the original problem, etc.

[0052] In step S220, each atomic question is matched with the natural language sentences in the preset comparison table for similarity, and the target natural language sentence corresponding to the atomic question and the initial structured query sentence corresponding to the target natural language sentence are determined; wherein the comparison table includes the correspondence between multiple preset structured query sentences and natural language sentences.

[0053] Specifically, the comparison table includes multiple preset structured query statements and natural language statements, as well as the corresponding relationships between the structured query statements and the natural language statements. The structured query statements include, but are not limited to, SQL-like query statements. Both the natural language statements and the structured query statements are preset statements, and the natural language statements and their corresponding structured query statements share the same query logic. The structured query statements in the comparison table are generally converted from natural language statements. In actual applications, the comparison table is typically pre-built by relevant technical personnel and stores a large number of common natural language statements and their corresponding structured query statements.

[0054] In this embodiment, after obtaining multiple atomic questions, each atomic question is matched with the natural language sentences in the comparison table for similarity, so as to determine the target natural language sentence corresponding to the atomic question, wherein the natural language sentence with the highest similarity to the atomic question can be confirmed as the above-mentioned target natural language sentence. In actual application, the similarity between the atomic question and the natural language sentence can be calculated by L2 distance. After determining the target natural language sentence corresponding to the atomic question, the initial structured query sentence corresponding to the target natural language sentence in the comparison table can be clarified. In some preferred embodiments, the natural language sentence corresponds to the structured query sentence one by one.

[0055] Step S230 , abstracting the initial structured query statement into a parameterizable template, and generating a target structured query statement corresponding to the atomic question based on the parameterizable template and the corresponding atomic question, wherein the parameterizable template carries the structural information of the initial structured query statement.

[0056] Specifically, the initial structured query statement is abstracted into a parameterizable template, including but not limited to methods such as parsing the initial structured query statement based on an AST (Abstract Syntax Tree) or abstracting the initial structured query statement into a parameterizable template based on a preset large language model. The parameterizable template helps quickly fill in the required different parameters when similar structured query statements need to be generated, thereby improving development efficiency. In actual applications, the parameterizable template deletes the specific constant values ​​in the initial structured query statement while retaining the format information of the initial structured query statement. Subsequently, the specific entity information in the atomic question can be mapped to the corresponding position in the parameterizable template to complete the construction of the target structured query statement. The structural information includes but is not limited to the format information in the initial structured query statement and data information other than the constant values.

[0057] Then, the named entity recognition method can be used to determine the key entities in the atomic question (such as names of people, places, dates, etc.), and dependency analysis can be used to understand the structure and intention of the atomic question. With the help of a large language model, the key information in the atomic question can be mapped to the corresponding parameter positions in the above-mentioned parameterizable template, so as to generate the above-mentioned target structured query statement corresponding to the atomic question with the help of the parameterizable template. Accordingly, the parameterizable template carries the structural information of the initial structured query statement, but in order to be combined with the atomic question later, the parameterizable template does not include information such as constant values ​​(such as strings, numbers, NULL, etc.).

[0058] Through steps S210 to S230, the present application can accurately generate corresponding structured query statements based on the original question input by the user, thereby improving the accuracy of the query results; further, in actual applications, the structure and fields required by the database are the same or similar to the corresponding natural language statements, and since the target structured query statement in the present application is generated based on the existing initial structured query statement corresponding to the natural language statement, the target structured query statement generated in the present application is not prone to the problem of mismatch with the data model of the database, and on the basis of improving the accuracy of converting the atomic question into the target structured query statement, the efficiency of data query is improved.

[0059] In some embodiments, obtaining an original question input by a user and splitting the original question into at least one atomic question includes:

[0060] If the original question is detected to be a question of the preset target type;

[0061] Search the preset technical knowledge base according to the original question to obtain relevant technical knowledge corresponding to the original question;

[0062] Based on relevant technical knowledge, the preset large language model is guided to decompose the original question into multiple atomic questions.

[0063] Specifically, a preset classification model may be used to evaluate the original question and detect whether the original question is a target type question. In some preferred embodiments, the target type question is generally a more complex question.

[0064] If the original question is detected to be of the target type, the Retrieval-Augmented Generation (RAG) technique can be used to search the preset technical knowledge base based on the original question, thereby obtaining relevant technical knowledge corresponding to the original question. In some preferred embodiments, a multi-vector search engine can be used to adopt a multi-path retrieval strategy, including but not limited to BM25 (Best Matching 25), Embedding, and rule matching methods to achieve fine-grained semantic matching. Exemplary search formulas include:

[0065]

[0066] Among them, E Q With E D They represent the embedding vector of the original question and the embedding vector of the document in the technical knowledge base, q i and d j They are text fragments respectively.

[0067] After obtaining relevant technical knowledge, the large language model is guided to decompose the original question based on the preset hierarchical prompts and relevant technical knowledge, thereby obtaining multiple atomic questions. In actual applications, the logical relationships between the atomic questions can also be marked, such as timing dependencies and conditional branches. The following provides some hierarchical prompt content:

[0068] ;

[0069] The above is the original question from the user.

[0070] You need to break this problem down into a series of subproblems.

[0071] Based on this original question, I retrieved relevant knowledge from the knowledge base as follows:

[0072] ;

[0073] Based on the relevant knowledge provided, the user's original question is broken down into a series of sub-questions. Each sub-question should be clear and unambiguous, and a list of sub-questions is returned in the form of a list.

[0074] In summary, in this embodiment, the original problem is decomposed based on relevant technical knowledge, which can improve the accuracy of generating atomic problems by decomposing the original problem.

[0075] In one embodiment, each atomic question is matched with a natural language sentence in a preset comparison table by similarity, including:

[0076] Through the preset twin neural network, the semantic similarity between the atomic question and each natural language sentence in the comparison table is calculated to obtain the semantic similarity between each natural language sentence and the atomic question;

[0077] Determine a natural language sentence whose semantic similarity with the atomic question is greater than a preset similarity threshold as a first target natural language sentence;

[0078] The natural language sentence with the highest semantic similarity to the atomic question among all the first target natural language sentences is determined as the sentence corresponding to the atomic question.

[0079] Specifically, the above-mentioned comparison table is constructed based on known natural language query questions and their corresponding precise structured query statements. The comparison table includes the correspondence between multiple preset structured query statements and natural language statements. For each entry, metadata information is recorded, such as the data table involved, field type, etc., which is helpful for the subsequent matching and generation process.

[0080] Based on the above preset twin neural network, the semantic similarity between the atomic question and each natural language sentence in the comparison table is calculated. Specifically, when the atomic question and the natural language sentence are input, the twin neural network gives the semantic similarity between the two based on the L2 distance:

[0081]

[0082] Among them, X1 and X2 represent the atomic question and the above natural language sentence respectively, G w It is a twin neural network model.

[0083] A natural language sentence whose semantic similarity with the atomic question is greater than a preset similarity threshold is determined as the first target natural language sentence, wherein the similarity threshold can be set by relevant technical personnel according to actual needs. Then, among all the first target natural language sentences, the natural language sentence with the highest semantic similarity with the atomic question is determined as the target natural language sentence corresponding to the atomic question.

[0084] In one embodiment, after obtaining the semantic similarity between each natural language sentence and the atomic question, the method further includes:

[0085] If the matching result between the atomic question and the natural language sentence is that the semantic similarity between each natural language sentence and the atomic question is less than the similarity threshold;

[0086] The matching results are fed back to the preset device end to modify the atomic problem.

[0087] Specifically, if it is detected that the semantic similarity between the atomic question and all natural language statements is less than the similarity threshold, it indicates that there is no question similar to the atomic question in the comparison table at this time. At this time, the matching result can be fed back to the preset device end for the user to modify the atomic question, or manually generate a corresponding structured query statement based on the atomic question.

[0088] In one embodiment, the initial structured query statement is abstracted into a parameterizable template, including:

[0089] Identifying constant values ​​in the initial structured query statement and generating a parameter identifier for each constant value;

[0090] Replace the constant values ​​in the initial structured query statement with the preset parameter placeholders;

[0091] A parameterizable template is obtained, wherein the parameterizable template carries a mapping relationship between constant values ​​and parameter identifiers.

[0092] Specifically, this embodiment provides a method for abstracting an initial structured query statement into a parameterizable template, including first identifying constant values ​​(such as strings, numbers, NULL, etc.) in the initial structured query statement and generating a unique parameter identifier for each constant value; then replacing the constant values ​​identified in the initial structured query statement with preset parameter placeholders. It is understandable that the parameter placeholders have no actual physical meaning and are only used as placeholders.

[0093] In summary, after replacing the constant values ​​in the initial structured query statement with preset parameter placeholders, a parameterizable template can be obtained. In some preferred embodiments, the parameterizable template carries a mapping relationship between constant values ​​and parameter identifiers, which can subsequently assist in setting the key information in the atomic problem to the corresponding position in the parameterizable template.

[0094] The following is an example of a parameterizable template:

[0095] ;

[0096] ;

[0097] ;

[0098] Among them, "select_fields (select fields)" is used to specify the columns / fields and other data to be retrieved from the database; "FROM orders (data source)" is used to declare the database for query; "where_clause (condition filtering)" is an optional clause used to filter query results that meet the conditions; "group_by_clause (group statistics)" is an optional clause used to group query results according to the specified format; "order_by_clause (result sorting)" is an optional clause used to define the sorting rules of query results; "limit_clause (result limit)" is an optional clause used to limit the number of query results returned.

[0099] In one embodiment, generating a target structured query statement corresponding to the atomic question based on the parameterizable template and the corresponding atomic question includes:

[0100] Identify key information in the atomic problem, where the key information at least includes key entities in the atomic problem and dependencies between key entities;

[0101] Based on the preset mapping model and the mapping relationship between constant values ​​and parameter identifiers, the key information is mapped to the corresponding parameter positions in the parameterizable template to generate the target structured query statement.

[0102] Specifically, the key information in the atomic problem is identified, where the key information includes but is not limited to the key entities in the atomic problem, such as names of people, places, dates, etc.; and the dependency relationships between the key entities. The structure and intention of the atomic problem can be understood through the dependency relationships, and the conditional restrictions can be determined. Then, according to the preset mapping model and the mapping relationship between constant values ​​and parameter identifiers, the key information in the atomic problem is mapped to the corresponding parameter positions in the above-mentioned parameterizable template with the help of a large language model to generate the target structured query statement SQL.

[0103] In some preferred embodiments, a formal method may be used to verify the logical correctness of the target structured query statement, such as using tools such as Apache Calcite and SQLancer to compare the semantic equivalence of the target structured query statement and the atomic question.

[0104] In summary, through this embodiment, a corresponding target structured query statement can be generated based on the parameterizable template and the corresponding atomic question. For the atomic question, the database that needs to be queried is generally the same as the target natural language statement corresponding to the atomic question. Therefore, according to the parameterizable template generated by the initial structured query statement, the corresponding target structured query statement is generated for the atomic question. Its data format and other information generally match the database. It is rare that the generated target structured query statement cannot be executed in the corresponding database, thereby improving the efficiency of subsequent workflows.

[0105] In one embodiment, after generating the target structured query statement, the method further includes:

[0106] The target structured query statement is sent to the preset device end, and the feedback result corresponding to the target structured query statement provided by the user is obtained.

[0107] Specifically, after generating the target structured query statement, the query statement is sent to the preset device end, allowing relevant users to modify the target structured query statement, providing an effective user feedback mechanism, which can promptly correct errors in the generated target structured statement and optimize system performance.

[0108] In one embodiment, after generating the target structured query statement, the method further includes:

[0109] A correspondence is established between the target structured query statement and the corresponding atomic question, and the correspondence between the target structured query statement and the atomic question is added to a comparison table.

[0110] Specifically, after generating the target structured query statement, a correspondence is established between the target structured query statement and the corresponding atomic question, and the correspondence between the target structured query statement and the atomic question is added to a comparison table to enrich the content in the comparison table.

[0111] This embodiment also provides a method for generating a structured query statement. Figure 3 The following is a flow chart of a method for generating a structured query statement in a preferred embodiment, including:

[0112] Step S310: Generate at least one atomic question based on the original question input by the user.

[0113] In step S320, based on the twin neural network, each atomic question is matched with the natural language sentences in the preset comparison table. If it is detected that the similarity between each natural language sentence and the atomic question is less than the preset similarity threshold, jump to step S330 to rewrite the atomic question. If it is detected that there is a natural language sentence with a similarity greater than the similarity threshold, jump to step S340.

[0114] Step S340: taking the natural language sentence with the greatest similarity as the target natural language sentence.

[0115] Step S350: Determine an initial structured query statement corresponding to the target natural language statement.

[0116] Step S360: abstract the initial structured query statement into a parameterizable template.

[0117] Step S370 , mapping the key information in the atomic question to the corresponding parameter positions in the parameterizable template to obtain the target structured query statement.

[0118] Step S380: Establish a feedback mechanism to send the target structured query statement to a preset device end so that the user can modify the target structured query statement.

[0119] Step S390: Establish a corresponding relationship between the modified target structured query statement and its corresponding atomic question, and fill it into the above-mentioned comparison table.

[0120] Through steps S310 to S390, the present application can accurately generate corresponding structured query statements based on the original question input by the user, thereby improving the accuracy of the query results; further, in actual applications, the structure and fields required by the database are the same or similar to the corresponding natural language statements, and since the target structured query statement in the present application is generated based on the existing initial structured query statement corresponding to the natural language statement, the target structured query statement generated in the present application is not prone to the problem of mismatch with the data model of the database, and on the basis of improving the accuracy of converting the atomic question into the target structured query statement, the efficiency of data query is improved.

[0121] It should be understood that, although the various steps in the flowcharts involved in the various embodiments described above are displayed in sequence according to the instructions of the arrows, these steps are not necessarily executed in sequence in the order indicated by the arrows. Unless otherwise specified herein, there is no strict order restriction on the execution of these steps, and these steps can be executed in other orders. Moreover, at least a portion of the steps in the flowcharts involved in the various embodiments described above can include multiple steps or multiple stages, and these steps or stages are not necessarily executed and completed at the same time, but can be executed at different times, and the execution order of these steps or stages is not necessarily to be carried out in sequence, but can be executed in turn or alternately with other steps or at least a portion of steps or stages in other steps.

[0122] Based on the same inventive concept, embodiments of the present application also provide a structured query statement generation device for implementing the structured query statement generation method described above. The implementation solution provided by this device is similar to the implementation solution described in the above method. Therefore, the specific limitations of the one or more structured query statement generation device embodiments provided below can be found in the limitations of the structured query statement generation method described above and will not be repeated here.

[0123] In one embodiment, Figure 4 As shown, a device for generating a structured query statement is provided, comprising: an acquisition module 41, a calculation module 42 and a generation module 43, wherein:

[0124] An acquisition module 41 is configured to acquire an original question input by a user and split the original question into at least one atomic question;

[0125] A calculation module 42 is configured to perform similarity matching between each atomic question and a natural language statement in a preset comparison table, and determine an initial structured query statement corresponding to the natural language statement based on the matching results; wherein the comparison table includes a plurality of preset correspondences between structured query statements and natural language statements;

[0126] The generating module 43 is configured to abstract the initial structured query statement into a parameterizable template, and generate a target structured query statement corresponding to the atomic question based on the parameterizable template and the corresponding atomic question.

[0127] Each module in the above-mentioned structured query statement generation device can be implemented in whole or in part through software, hardware, or a combination thereof. Each of the above modules can be embedded in or independent of a processor in a computer device in the form of hardware, or can be stored in a memory in the computer device in the form of software, so that the processor can call and execute the corresponding operations of each of the above modules.

[0128] In one embodiment, a computer device is provided. The computer device may be a server, and its internal structure diagram may be as follows: Figure 5 As shown. The computer device includes a processor, a memory, and a network interface connected via a system bus. The processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system, a computer program, and a database. The internal memory provides an environment for the operation of the operating system and computer program in the non-volatile storage medium. The database of the computer device is used to store data related to the generation of structured query statements. The network interface of the computer device is used to communicate with an external terminal via a network connection. When the computer program is executed by the processor, a method for generating a structured query statement is implemented.

[0129] Those skilled in the art will understand that Figure 5 The structure shown in the figure is only a block diagram of a part of the structure related to the solution of the present application, and does not constitute a limitation on the computer device to which the solution of the present application is applied. The specific computer device may include more or fewer components than shown in the figure, or combine certain components, or have a different component arrangement.

[0130] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, stored data, displayed data, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties.

[0131] Those skilled in the art will appreciate that all or part of the processes in the above-mentioned embodiments can be implemented by instructing the relevant hardware through a computer program. The computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the above-mentioned embodiments. In particular, any reference to memory, database, or other media used in the embodiments provided in this application can include at least one of non-volatile and volatile memory. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory, optical memory, high-density embedded non-volatile memory, resistive random access memory (ReRAM), magnetic random access memory (MRAM), ferroelectric random access memory (FRAM), phase change memory (PCM), graphene memory, etc. Volatile memory can include random access memory (RAM) or external cache memory, etc. By way of illustration and not limitation, RAM can take various forms, such as static random access memory (SRAM) or dynamic random access memory (DRAM). The databases involved in the various embodiments provided herein may include at least one of a relational database and a non-relational database. Non-relational databases may include, but are not limited to, distributed databases based on blockchains. The processors involved in the various embodiments provided herein may be, but are not limited to, general-purpose processors, central processing units (CPUs), graphics processing units (GPUs), digital signal processors (DSPs), programmable logic devices (PLDs), data processing logic devices based on quantum computing, and the like.

[0132] The technical features of the above embodiments can be combined arbitrarily. To make the description concise, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.

[0133] The above-described embodiments merely represent several implementation methods of the present application. While the descriptions are relatively specific and detailed, they should not be construed as limiting the scope of the present application. It should be noted that a person of ordinary skill in the art may make various modifications and improvements without departing from the spirit of the present application, and these modifications and improvements fall within the scope of protection of the present application. Therefore, the scope of protection of the present application shall be determined by the appended claims.

Claims

1. A method for generating a structured query statement, characterized in that: The method comprises: Obtaining an original question input by a user, and splitting the original question into at least one atomic question; Performing similarity matching on each of the atomic questions with natural language sentences in a preset comparison table to determine a target natural language sentence corresponding to the atomic question and an initial structured query sentence corresponding to the target natural language sentence; wherein the comparison table includes a plurality of preset correspondences between structured query sentences and natural language sentences; The initial structured query statement is abstracted into a parameterizable template, and a target structured query statement corresponding to the atomic question is generated based on the parameterizable template and the corresponding atomic question, wherein the parameterizable template carries structural information of the initial structured query statement.

2. The method according to claim 1, characterized in that The step of obtaining an original question input by the user and splitting the original question into at least one atomic question includes: If it is detected that the original question is a question of the preset target type; Searching a preset technical knowledge base according to the original question to obtain relevant technical knowledge corresponding to the original question; Based on the relevant technical knowledge, a preset large language model is guided to decompose the original question to obtain multiple atomic questions.

3. The method according to claim 1, characterized in that The similarity matching of each of the atomic questions with the natural language sentences in the preset comparison table includes: Calculating semantic similarity between the atomic question and each of the natural language sentences in the comparison table through a preset twin neural network to obtain semantic similarity between each of the natural language sentences and the atomic question; Determine the natural language sentence whose semantic similarity with the atomic question is greater than a preset similarity threshold as a first target natural language sentence; The natural language sentence with the highest semantic similarity to the atomic question among all the first target natural language sentences is determined as the sentence corresponding to the atomic question.

4. The method according to claim 3, characterized in that After obtaining the semantic similarity between each of the natural language sentences and the atomic question, the method further includes: If it is detected that the matching result between the atomic question and the natural language sentence is that the semantic similarity between each of the natural language sentences and the atomic question is less than the similarity threshold; The matching result is fed back to a preset device end to modify the atomic problem.

5. The method according to claim 1, wherein The step of abstracting the initial structured query statement into a parameterizable template includes: Identifying constant values ​​in the initial structured query statement and generating a parameter identifier for each constant value; Replacing the constant value in the initial structured query statement with a preset parameter placeholder; The parameterizable template is obtained, wherein the parameterizable template carries a mapping relationship between the constant value and the parameter identifier.

6. The method according to claim 5, characterized in that The generating a target structured query statement corresponding to the atomic question based on the parameterizable template and the corresponding atomic question includes: Identifying key information in the atomic problem, wherein the key information includes at least key entities in the atomic problem and dependencies between the key entities; Based on a preset mapping model and a mapping relationship between the constant value and the parameter identifier, the key information is mapped to a corresponding parameter position in the parameterizable template to generate the target structured query statement.

7. The method according to claim 6, characterized in that After generating the target structured query statement, the method further includes: The target structured query statement is sent to a preset device end, and a feedback result corresponding to the target structured query statement provided by the user is obtained.

8. The method according to claim 6, characterized in that After generating the target structured query statement, the method further includes: A correspondence is established between the target structured query statement and the corresponding atomic question, and the correspondence between the target structured query statement and the atomic question is added to the comparison table.

9. A device for generating a structured query statement, characterized in that: The device comprises: An acquisition module, configured to acquire an original question input by a user and split the original question into at least one atomic question; a calculation module, configured to perform similarity matching between each of the atomic questions and a natural language statement in a preset comparison table, and determine an initial structured query statement corresponding to the natural language statement based on the matching result; wherein the comparison table includes a plurality of preset correspondences between structured query statements and natural language statements; A generating module is used to abstract the initial structured query statement into a parameterizable template, and generate a target structured query statement corresponding to the atomic question based on the parameterizable template and the corresponding atomic question.

10. A computer device comprising a memory and a processor, wherein the memory stores a computer program, wherein: When the processor executes the computer program, the steps of the method according to any one of claims 1 to 8 are implemented.

Citation Information

Cited By

  • Question and answer interaction method based on multi-source data and storage medium

    CN121579660A