Query statement generation method, data analysis method, equipment, medium and product
Alternative prompt words are generated by matching pre-constructed data sets and professional noun thesaurus, and combined with structured query statements to generate large models and domain-specific language error correction processing, solving the problem of high SQL usage and insufficient accuracy of NL2SQL, improving the operation simplicity and accuracy of data analysis tools.
Patent Information
- Application Number
- CN202510363367.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-03-26
- Publication Date
- 2025-07-11
AI Technical Summary
In the prior art, SQL is difficult to use, traditional data analysis tools have a large operating load and cannot meet the needs of diversified data analysis, and the accuracy of NL2SQL is difficult to guarantee.
The user problems are matched through the pre-constructed data set and the professional noun database, alternative prompt words are generated, structured query statements are input to generate a large model, intermediate structured query statements are converted, and error correction is used to use preset domain-specific languages and database tables to generate target query statements.
Improve the accuracy and usability of query statements to ensure that the generated query statements better meet users' data analysis needs.
Smart Images

Figure CN120296031A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of data analysis, and particularly to a query statement generation method, a data analysis method, a device, a medium and a product. Background Art
[0002] With the advent of the big data era, data analysis has become an indispensable important part in the fields of enterprise decision-making, market research, user behavior analysis, etc. Currently, a large amount of information is stored in databases in a structured or semi-structured form, and the analysis and acquisition of such data require interactive operations with the database through the Structured Query Language (SQL).
[0003] However, for non-professionals, the use of SQL is too difficult, and traditional data analysis tools often have problems such as high operation load, high learning cost, and inability to meet diverse data analysis requirements. Even though there are currently some data analysis software that support NL2SQL, that is, converting natural language (NL) to SQL, their accuracy is often difficult to guarantee and cannot meet the requirements of data analysis. Summary of the Invention
[0004] The present invention provides a query statement generation method, a data analysis method, a device, a medium and a product, which improve the usability and accuracy of the generated query statement, enhance the coincidence degree between the information contained in the query statement and the usage scenario, and enable the generated query statement to better meet the data analysis requirements in the query scenario required by users.
[0005] In a first aspect, an embodiment of the present invention provides a query statement generation method, including:
[0006] Matching the received user question according to a pre-constructed data set and a pre-constructed professional noun thesaurus to determine alternative prompt words;
[0007] Constructing a target prompt word sentence based on each alternative prompt word and inputting the target prompt word sentence into a large model for generating a structured query statement to determine an intermediate structured query statement;
[0008] Converting the intermediate structured query statement into an intermediate query body according to a preset domain-specific language, and performing error correction processing on the intermediate query body based on the pre-constructed data set and the database table corresponding to the pre-constructed data set, and determining a target query statement according to the intermediate query body after error correction processing.
[0009] In a second aspect, an embodiment of the present invention further provides a data analysis method, including:
[0010] Receiving a user question;
[0011] Process the user's question through the query statement generation method of any embodiment of the present invention to determine the target query statement;
[0012] Query the target database according to the target query statement to determine the target data;
[0013] Perform rendering processing on the target data and display the obtained analysis results.
[0014] In a third aspect, an embodiment of the present invention further provides an electronic device, including:
[0015] At least one processor; and a memory communicatively connected to the at least one processor;
[0016] Wherein, the memory stores a computer program executable by the at least one processor, and the computer program is executed by the at least one processor so that the at least one processor can implement the query statement generation method or the data analysis method of any embodiment of the present invention.
[0017] In a fourth aspect, an embodiment of the present invention further provides a storage medium containing computer-executable instructions, and the computer-executable instructions are used to execute the query statement generation method or the data analysis method of any embodiment of the present invention when executed by a computer processor.
[0018] In a fifth aspect, an embodiment of the present invention further provides a computer program product, including a computer program, and the computer program is used to execute the query statement generation method or the data analysis method of any embodiment of the present invention when executed by a processor.
[0019] A query statement generation method, a data analysis method, a device, a medium, and a program product provided by an embodiment of the present invention match a received user question according to a pre-constructed data set and a pre-constructed professional term thesaurus to determine alternative prompt words; construct a target prompt word sentence based on each alternative prompt word, and input the target prompt word sentence into a structured query statement generation large model to determine an intermediate structured query statement; convert the intermediate structured query statement into an intermediate query body according to a preset domain-specific language, and perform error correction processing on the intermediate query body based on the pre-constructed data set and the database table corresponding to the pre-constructed data set, and determine a target query statement according to the intermediate query body after error correction processing. By adopting the above technical solution, when receiving a user question that requires data analysis, first match the user question based on the pre-constructed data set and professional term thesaurus to obtain alternative prompt words that are applicable to the structured query statement generation large model and contain more scenario information, and then input the target prompt word sentence constructed based on each alternative prompt word into the structured query statement generation large model, so that the scenario matching degree and accuracy of the intermediate structured query statement output by the structured query statement generation large model based on the target prompt word sentence are higher. At the same time, since there may be differences in understanding in the structured query statement generation large model, errors may inevitably occur. Therefore, after obtaining the intermediate structured query statement, it will be structurally converted according to the preset domain-specific language to obtain an intermediate query body, and the data in the pre-constructed data set and the database table corresponding to the data set are used to perform secondary error correction processing on the possible generation errors in the intermediate query body, and the intermediate query body after error correction processing is processed to obtain a target query statement that can finally meet the query requirements of the database table, improving the usability and accuracy of the generated target query statement, increasing the matching degree of the information contained in the target query statement and the usage scenario, and enabling the generated target query statement to better meet the data analysis requirements in the query scenario required by the user.
[0020] It should be understood that the content described in this part is not intended to identify the key or important features of the embodiments of the present application, nor is it used to limit the scope of the present application. Other features of the present application will become easily understood through the following description. BRIEF DESCRIPTION OF THE DRAWINGS
[0021] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the following will briefly introduce the drawings required for the description of the embodiments. Obviously, the following drawings are only some embodiments of the present invention. For those of ordinary skill in the art, other drawings can be obtained based on these drawings without creative efforts.
[0022] Figure 1 It is a flowchart of a query statement generation method provided by Embodiment 1 of the present invention;
[0023] Figure 2 It is a flowchart of a query statement generation method provided in the second embodiment of the present invention;
[0024] Figure 3 It is a flowchart of a data analysis method provided in the third embodiment of the present invention;
[0025] Figure 4 It is a schematic structural diagram of a query statement generation device provided in the fourth embodiment of the present invention;
[0026] Figure 5 It is a schematic structural diagram of a data analysis device provided in the fifth embodiment of the present invention;
[0027] Figure 6 It is a schematic structural diagram of an electronic device provided in the sixth embodiment of the present invention. Detailed implementation manners
[0028] In order to enable those skilled in the art to better understand the solution of the present invention, the technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings in the embodiments of the present invention. Obviously, the described embodiments are only a part of the embodiments of the present invention, rather than all the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those of ordinary skill in the art without creative efforts shall fall within the protection scope of the present invention.
[0029] It should be noted that the terms "first", "second", etc. in the specification and claims of the present invention and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that such data can be interchanged under appropriate circumstances so that the embodiments of the present invention described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusion. For example, a process, method, system, product or device including a series of steps or units is not necessarily limited to those steps or units clearly listed, but may include other steps or units not clearly listed or inherent to these processes, methods, products or devices.
[0030] Embodiment 1
[0031] Figure 1The flowchart of a query statement generation method provided by Embodiment 1 of the present invention. The embodiments of the present invention are applicable to the situation of automatically generating query statements for data analysis based on natural language questions input by users. This method can be executed by a query statement generation device, which can be implemented by software and / or hardware, and can be configured in a query statement generation device. Optionally, the query statement generation device can be an electronic device, such as a notebook, a desktop computer, a smart tablet, a robot, etc. The embodiments of the present invention do not limit this.
[0032] As Figure 1 shown, a query statement generation method provided by an embodiment of the present invention specifically includes the following steps:
[0033] S101. Match the received user question according to a pre-constructed data set and a pre-constructed professional noun thesaurus to determine alternative prompt words.
[0034] In this embodiment, the data set can be specifically understood as being pre-configured according to the data contained in the database table that the user needs to analyze, and includes the Chinese name information of the corresponding fields maintained by the user so that the large model can accurately understand the natural language. Optionally, the data set may include dimension names and metric names. Among them, the metric name can be understood as the naming used to indicate the specific category of numerical type data in the database table, such as personal income value, family income value, etc.; among them, the dimension name can be understood as the naming used to indicate the specific category of data stored in text type in the database table, such as name, ethnicity, etc.; that is, it can be understood that the actual data corresponding to the same dimension name in the database table can be directly found through text matching, and if only one value appears in the user's question, the metric to which it belongs cannot be directly matched.
[0035] In this embodiment, the professional noun thesaurus can be specifically understood as a set of professional nouns that are pre-configured with specified synonyms or specific dates for corresponding services based on scenario requirements, so that the large model can more accurately understand the corresponding semantic information. Exemplarily, the professional noun thesaurus may include the professional noun itself, the abbreviation of the professional noun, the specific time name dedicated to the scenario, etc. Among them, the specific time name dedicated to the scenario may include the company anniversary date, etc. It can be understood that the company anniversary dates corresponding to different scenarios are different, so the association relationship between the time information and the specific time name can be completed in the dedicated noun thesaurus in advance, so that when the corresponding specific time name is detected in the user's question, the specific time can be directly matched.
[0036] In this embodiment, the user's question can be specifically understood as a query question given by the user in natural language according to the data analysis scenario required. The alternative prompt words can be specifically understood as those containing information related to the event scenario corresponding to the user's question, which can be used to prompt the large model so that the large model generates dismissal prompt words that more meet the scenario requirements.
[0037] Specifically, when receiving the user's question given based on the data analysis requirement, based on the pre-built dataset and the pre-built professional term library, match the professional terms related to the scenario and the information related to the database table to be analyzed in the user's question of natural language type, and extract the words related to the user's question from the dataset and the professional term library as alternative prompt words based on the matching results with the dataset and the professional term library.
[0038] S102. Construct a target prompt word sentence according to each alternative prompt word, and input the target prompt word sentence into the large model for generating structured query statements to determine an intermediate structured query statement.
[0039] In this embodiment, the target prompt word sentence can be specifically understood as a guiding word text that can be input into the large model for generating structured query statements to guide the large model for generating structured query statements to generate an SQL statement that meets the user's question requirements based on the input information. The large model for generating structured query statements can be specifically understood as a generative large language model for generating SQL statements based on the input information. The intermediate structured query statement can be specifically understood as an SQL statement corresponding to the data analysis query requirement of the user's question, which is generated by the large model for generating structured query statements based on the guidance of the input target prompt word sentence.
[0040] Specifically, convert each alternative prompt word into a unified form suitable for input into the large model for generating structured query statements, and integrate and construct the converted alternative prompt words according to the language expression form to obtain a target prompt word sentence. Input the target prompt word sentence into the large model for generating structured query statements, so that the large model for generating structured query statements performs a generation process based on the guidance of the target prompt word sentence, and determine the output result of the large model for generating structured query statements as the intermediate structured query statement.
[0041] Exemplarily, after converting each alternative prompt word into a unified format suitable for input into the large model for generating structured query statements, the converted alternative prompt words can be substituted into a preset prompt word sentence template suitable for the input requirements of the large model for generating structured query statements to construct a target prompt word sentence; or the alternative prompt words can be directly integrated according to the regular text expression requirements to construct a target prompt word sentence, and the embodiments of the present invention do not limit this.
[0042] S103. Convert the intermediate structured query statement into an intermediate query body according to a preset domain-specific language, and perform error correction processing on the intermediate query body based on a pre-constructed data set and the database table corresponding to the pre-constructed data set. Determine the target query statement according to the intermediate query body after error correction processing.
[0043] In this embodiment, the domain-specific language (DSL) can be specifically understood as a programming language specially designed for a specific domain, which can be used to simplify tasks or problems in a specific domain and make them easier to express and solve. In the embodiment of the present invention, the preset domain-specific language can be specifically understood as a language preset based on the data analysis event scenario and having a data structure adapted to the data analysis event scenario.
[0044] In this embodiment, the intermediate query body can be specifically understood as a DSL query body obtained by converting the intermediate structured query statement into the DSL structure.
[0045] Specifically, perform structure conversion on the intermediate structured query statement based on the specific data structure of the preset domain-specific language to obtain an intermediate query body applicable to the current event scenario. At the same time, due to possible errors caused by differences in understanding of the results output by the large model for generating structured query statements, and the pre-constructed data set and the database table corresponding to the pre-constructed data set are information actually adapted to the current event scenario. At this time, match and verify various types of information included in the intermediate query body based on the information in the pre-constructed data set and the database table corresponding to the pre-constructed data set, correct the information that does not belong to the pre-constructed data set and the database table corresponding to the pre-constructed data set, and reverse-convert the intermediate query body after error correction processing into the SQL structure. Finally, obtain a target query statement with higher relevance of the included information to the current event scenario.
[0046] The technical solution of this embodiment matches the received user question according to a pre-constructed data set and a pre-constructed professional term thesaurus to determine alternative prompt words; constructs a target prompt word sentence based on each alternative prompt word, and inputs the target prompt word sentence into a structured query statement generation large model to determine an intermediate structured query statement; converts the intermediate structured query statement into an intermediate query body according to a preset domain-specific language, and performs error correction processing on the intermediate query body based on the pre-constructed data set and the database table corresponding to the pre-constructed data set to determine a target query statement. By adopting the above technical solution, when receiving a user question that requires data analysis, first match the user question based on the pre-constructed data set and professional term thesaurus to obtain alternative prompt words that are applicable to the structured query statement generation large model and contain more scenario information, and then input the target prompt word sentence constructed based on each alternative prompt word into the structured query statement generation large model, so that the scenario matching degree and accuracy of the intermediate structured query statement output by the structured query statement generation large model based on the target prompt word sentence are higher. At the same time, due to possible differences in understanding in the structured query statement generation large model, errors may inevitably occur. Therefore, after obtaining the intermediate structured query statement, it will be structurally converted into an intermediate query body according to the preset domain-specific language, and the possible generation errors in the intermediate query body will be corrected for the second time through the pre-constructed data set and the data in the database table corresponding to the data set, and the processed intermediate query body will be processed to obtain a target query statement that can finally meet the query requirements of the database table, improving the usability and accuracy of the generated target query statement, increasing the matching degree of the information contained in the target query statement with the usage scenario, and enabling the generated target query statement to better meet the data analysis requirements in the query scenario required by the user.
[0047] Embodiment 2
[0048] Figure 2The flowchart of a query statement generation method provided in the second embodiment of the present invention further optimizes on the basis of the above optional technical solutions. Based on the pre-built professional term library, the metric names in the pre-built dataset, and the actual data in the database table corresponding to the pre-built dataset, the received user questions are respectively matched, so that the professional terms, metric names, and the dimension names in the dataset that coincide with the actual data in the database table successfully matched in the user questions can all be extracted as alternative prompt words, improving the correlation and extraction accuracy between the extracted alternative prompt words and the scenario. At the same time, the format conversion and template matching specifically applicable to time type information are added to ensure that the time-related information with higher importance in the user questions can accurately obtain alternative prompt words. After generating the intermediate structured query statement through the structured query statement generation large model and converting it into an intermediate query body containing dimension names, metric names, and dimension filtering conditions, the dimension names and metric names in the intermediate query body are matched and filtered through the dataset, and the dimension filtering conditions in the intermediate query body are replaced through the database table corresponding to the dataset to finally obtain the target query statement, ensuring that the target query statement obtained through the filtering and replacement process is more suitable for querying the database table, improving the usability and accuracy of the generated target query statement, and improving the coincidence degree between the information contained in the target query statement and the usage scenario, so that the generated target query statement can better meet the data analysis requirements in the query scenario required by the user.
[0049] As Figure 2 shown, a query statement generation method provided by an embodiment of the present invention specifically includes the following steps:
[0050] S201. Perform regular matching on the received user question according to the pre-built professional term library, and determine the successfully matched professional terms as alternative prompt words.
[0051] Specifically, for each professional term in the pre-built professional term library, it is matched with the received user question by means of regular expression matching, and the successfully matched professional terms are determined as alternative prompt words.
[0052] S202. Perform text similarity matching on the metric names in the pre-built dataset and the user question, and determine the successfully matched metric names as alternative prompt words.
[0053] Specifically, for each metric name included in the pre-built dataset, the similarity between the metric name and each field in the user question is determined through a text similarity algorithm, and the metric names with similarity exceeding the pre-set metric similarity threshold are determined as successfully matched metric names, and the successfully matched metric names are determined as alternative prompt words.
[0054] Optionally, the preset index similarity threshold can be adaptively set according to the actual situation, such as being set to 0.6, etc., and the embodiments of the present invention do not limit this.
[0055] S203. Perform text similarity matching on the keywords in the user question and the actual data in the database table corresponding to the pre-constructed data set, and determine the dimension name of the actual data that matches successfully in the pre-constructed data set as the alternative prompt word.
[0056] In this embodiment, the keywords in the user question can be specifically understood as the fields extracted from the user question and related to the screening dimensions in the event scenario. Exemplarily, it may include specific personal names, place names, and other similar information, etc., and the embodiments of the present invention do not limit this.
[0057] Specifically, extract the keywords related to the screening dimensions in the event scenario from the user question, and traverse the actual data in the database table corresponding to the pre-constructed data set through the keywords. During the traversal process, determine the similarity between the keywords and the actual data through the text similarity algorithm, and determine the actual data with a similarity exceeding the preset dimension similarity threshold as the successfully matched actual data. Since the dimension names in the data set are summarized based on the commonalities of the actual data, that is, equivalent to the table headers, at this time, the dimension name corresponding to the successfully matched actual data can be determined according to the correspondence between the actual data and the dimension names in the data set, and this dimension name is determined as the alternative prompt word.
[0058] Optionally, the preset dimension similarity threshold can be adaptively set according to the actual situation, such as being set to 0.8, etc., and the embodiments of the present invention do not limit this.
[0059] Exemplarily, the text similarity algorithm in S202 and S203 above can be the N-gram similarity matching algorithm, or other text similarity matching algorithms, and the embodiments of the present invention do not limit this. When the text similarity algorithm adopts the N-gram similarity matching algorithm, this text similarity algorithm can be implemented through an Online Analytical Processing (OLAP) engine, or can be implemented through other data processing engines that can achieve fast response for data volumes in the tens of millions or even larger, and the embodiments of the present invention do not limit this.
[0060] Optionally, when matching the user question according to the pre-constructed data set and the pre-constructed professional noun thesaurus to determine the alternative prompt word, it further includes:
[0061] Extract time information from the user question;
[0062] Perform format conversion on the extracted time information or match it with common time templates to determine alternative prompt words.
[0063] Specifically, for the convenience of the large model for generating structured query statements to understand, when determining alternative prompt words, the time information related to dates and times in the user's question can be extracted and format-converted to a unified format that meets the requirements of the large model for generating structured query statements. At the same time, common time templates can be set according to the user's colloquial time expression needs, match the dates and times with the common time templates, convert the matched time information to a unified format that meets the requirements of the large model for generating structured query statements, and use the information extracted by both methods as alternative prompt words.
[0064] Exemplarily, the content such as "January 1, 2024" can be converted to the form of "2024-01-01" to achieve format conversion. At the same time, colloquial time expressions such as "today", "the current day", and "that day" can be configured as common time templates. When the time information in the user's question contains the above colloquial time expressions, associate their specific dates of the day and convert them in the above format as alternative prompt words.
[0065] It can be understood that the steps of S201 - S203 and the matching of the above time information can be executed simultaneously or in any order, and the embodiments of the present invention do not limit this.
[0066] S204. Construct a target prompt word sentence based on each alternative prompt word, and input the target prompt word sentence into the large model for generating structured query statements to determine an intermediate structured query statement.
[0067] S205. Convert the intermediate structured query statement according to the query body structure of the preset domain-specific language to determine an intermediate query body.
[0068] Among them, the query body structure at least includes a dimension name, an index name, and a dimension filtering condition.
[0069] In this embodiment, the dimension filtering condition can be specifically understood as the specific dimension data included under a dimension name in the dataset, which can be used as a field for filtering all actual data under that dimension name. Exemplarily, if the dimension name is location, the corresponding dimension filtering condition can be Jiangsu Province.
[0070] S206. Match the intermediate query body with the pre-constructed dataset to determine a first matching result.
[0071] In this embodiment, the first matching result can be specifically understood as the matching result obtained by matching the intermediate query body with the dimension names and index names included in the pre-constructed dataset, which is used to indicate whether the intermediate query body contains corresponding information.
[0072] Specifically, traverse and match the dimension names in the intermediate query body with the dimension names in the pre-built data set to determine the dimension names that may fail to match in the intermediate query body, or clarify all the dimension names that match successfully in the intermediate query body; traverse and match the metric names in the intermediate query body with the metric names in the pre-built data set to determine the metric names that may fail to match in the intermediate query body, or clarify all the metric names that match successfully in the intermediate query body. Determine the first matching result by taking the above-mentioned dimension names and metric names that fail to match, or determine the first matching result by taking the above-mentioned dimension names and metric names that match successfully.
[0073] S207. Perform text similarity matching between the intermediate query body and the database table corresponding to the pre-built data set to determine the second matching result.
[0074] In this embodiment, the second matching result can be specifically understood as the result obtained by performing text similarity matching between the intermediate query body and the text in the database table corresponding to the pre-built data set, which is used to indicate whether there is a consistent dimension filtering condition in the intermediate query body.
[0075] Specifically, according to the text similarity algorithm, perform text similarity matching between the dimension filtering conditions in the intermediate query body and the actual data included in the database table corresponding to the pre-built data set, and determine the second matching result based on the text similarity between each actual data and the dimension filtering conditions.
[0076] S208. Screen and replace the intermediate query body according to the first matching result and the second matching result to determine the target query body.
[0077] Specifically, delete the dimension names and metric names that fail to match in the intermediate query body according to the first matching result, and replace the dimension filtering conditions in the intermediate query body with the actual data with the highest text similarity in the database table according to the second matching result to achieve the replacement of the dimension filtering conditions, and determine the intermediate query body after the above two processes are completed as the target query body.
[0078] Optionally, screening and replacing the intermediate query body according to the first matching result and the second matching result to determine the target query body includes:
[0079] Screen out the dimension names and metric names that fail to match in the intermediate query body according to the first matching result;
[0080] Replace the dimension filtering conditions in the intermediate query body according to the second matching result;
[0081] Determine the intermediate query body after screening out the dimension names and metric names that fail to match and completing the replacement of the dimension filtering conditions as the target query body.
[0082] Optionally, replace the dimension filtering conditions in the intermediate query body according to the second matching result, including:
[0083] If the second matching result is exactly the same, do not replace the dimension filtering conditions;
[0084] If the second matching result is not exactly the same, replace the dimension filtering conditions with the data in the database table that is greater than the preset similarity threshold.
[0085] Specifically, if the text similarity in the second matching result is 100%, that is, when the second matching result is exactly the same, it can be considered that the dimension filtering conditions themselves are the information in the database table and can be used as the basis for data analysis and exist in the target query statement. In this case, the dimension filtering conditions do not need to be replaced; if the text similarity in the second matching result is less than 100%, that is, when the second matching result is not exactly the same, in order to make the information contained in the finally determined target query statement belong to the information in the database table, the dimension filtering conditions can be replaced with the data in the database table whose text similarity is greater than the preset similarity threshold.
[0086] S209. Convert the target query body into a structured query statement structure according to the query body structure to determine the target query statement.
[0087] Specifically, to meet the database query requirements, the target query body in DSL structure needs to be re-converted into a structured query statement structure to obtain the target query statement in SQL format.
[0088] It can be understood that S205 - S208 can correspond to the process of converting an SQL statement into a DSL statement. That is, the process of converting the intermediate structured query statement in S205 is equivalent to parsing the intermediate structured query statement and extracting the information of each component in the preset domain-specific language construction system. S206 - S208 is equivalent to the process of screening and replacing the information of each component to obtain a DSL query body applicable to the scenario. S209 is equivalent to converting the DSL query body applicable to the scenario back to the SQL format to complete the construction of the query statement that can be used for data analysis query.
[0089] Optionally, after determining the target query statement, a query for the database table can be implemented based on the target query statement to obtain the data related to the user's question, and finally, the obtained data can be displayed in the form of a chart.
[0090] The technical solution of this embodiment matches the received user questions respectively based on a pre-built professional term library, the index names in a pre-built data set, and the actual data in the database table corresponding to the pre-built data set. In this way, the professional terms, index names, and the dimension names in the data set that coincide with the actual data in the database table successfully matched in the user questions can all be extracted as alternative prompt words, enhancing the correlation and extraction accuracy between the extracted alternative prompt words and the scenario. At the same time, format conversion and template matching specifically applicable to time type information are added to ensure that the time-related information with a higher degree of importance in the user question can accurately obtain alternative prompt words. After generating an intermediate structured query statement through a large model using a structured query statement and converting it into an intermediate query body containing dimension names, index names, and dimension filtering conditions, the dimension names and index names in the intermediate query body are matched and filtered through the data set, and the dimension filtering conditions in the intermediate query body are replaced through the database table corresponding to the data set to finally obtain the target query statement. This ensures that the target query statement obtained through the screening and replacement process can be more adapted to the query of the database table, enhancing the usability and accuracy of the generated target query statement, improving the coincidence degree of the information contained in the target query statement with the usage scenario, and enabling the generated target query statement to better meet the data analysis requirements in the query scenario required by the user.
[0091] Embodiment III
[0092] Figure 3 As shown in the flowchart of a data analysis method provided by Embodiment III of the present invention, the embodiments of the present invention are applicable to the situation of automatically generating a query statement for a natural language question input by a user and completing data query analysis based on the generated query statement. This method can be executed by a data analysis device, which can be implemented by software and / or hardware, and can be configured in a data analysis device. Optionally, the data analysis device can be an electronic device, which can be a notebook, a desktop computer, a smart tablet, a robot, etc. The embodiments of the present invention do not limit this.
[0093] As Figure 3 shown, a data analysis method provided by an embodiment of the present invention specifically includes the following steps:
[0094] S301. Receive a user question.
[0095] S302. Process the user question through the query statement generation method of any embodiment of the present invention to determine the target query statement.
[0096] S303. Query the target database according to the target query statement to determine the target data.
[0097] In this embodiment, the target database can be specifically understood as a database related to the query information required by the user's question.
[0098] S304. Render the target data, and display the obtained analysis results.
[0099] Exemplarily, the data analysis method provided by the embodiments of the present invention can be applied to the scenario of automatic data analysis by a dialogue robot. A specific application example is given here and is exemplified by the following steps:
[0100] 1) The user starts the self-service data analysis tool through the web interface;
[0101] 2) The user constructs a "company sales data" dataset, which includes information such as sales time date, sales amount ct, sales city city, and salesperson salesman. Among them, the sales city and the salesperson can be understood as the dimension names in the dataset, and the sales amount and the sales time can be understood as the metric names in the dataset;
[0102] 3) The user enters the user's question on the robot interface, such as asking "View the sales amount of Zhang San in Shanghai this year?" as the data analysis requirement;
[0103] 4) The robot extracts alternative prompt words for constructing the prompt word sentence from the dataset and the corresponding database table according to the question input by the user, and constructs a reasonable large model prompt word prompt; Exemplarily, the extracted alternative prompt words may include: salesperson = Zhang San, sales area = Shanghai City, calculate the sales amount using ct, sales time = 2024;
[0104] 5) Integrate the question, metadata, and prompt words to ask the large model for generating a structured query statement through the prompt, and the large model returns the SQL; Exemplarily, the SQL can be expressed as: select ct from table where salesman = 'Zhang San' and city = 'Shanghai' and year(date) = 2024;
[0105] 6) The robot parses the SQL returned in step 5) to generate a data analysis query DSL executable by the system; during the generation process of the DSL, the dataset and the database table corresponding to the dataset can be used;
[0106] 7) The robot converts the DSL returned in step 6) into SQL, extracts the corresponding data from the corresponding database based on the SQL, and determines the chart type to be rendered.
[0107] 8) The robot presents the analysis results to the user in the form of a line chart or other types.
[0108] Optionally, the following provides some ways to select rendering chart types: if the data retrieved based on SQL is a single row, it can be displayed in text form; if the data retrieved based on SQL contains geographical dimension fields, it is displayed in map form; if the data retrieved based on SQL contains time dimensions, it is displayed in line chart form; if the data retrieved based on SQL is single-metric and single-dimension data, it is displayed in pie chart form; if none of the above conditions are met, it is displayed in table form.
[0109] Embodiment Four
[0110] Figure 4 is a structural schematic diagram of a query statement generation device provided in Embodiment Four of the present invention. As Figure 4 shown, the query statement generation device includes a prompt word determination module 41, an intermediate statement determination module 42, and a target statement determination module 43.
[0111] Among them, the prompt word determination module 41 is used to match the received user question according to the pre-constructed data set and the pre-constructed professional noun thesaurus to determine alternative prompt words; the intermediate statement determination module 42 is used to construct a target prompt word statement based on each alternative prompt word and input the target prompt word statement into a large model for generating structured query statements to determine an intermediate structured query statement; the target statement determination module 43 is used to convert the intermediate structured query statement into an intermediate query body according to a preset domain-specific language, and perform error correction processing on the intermediate query body based on the pre-constructed data set and the database table corresponding to the pre-constructed data set, and determine the target query statement according to the intermediate query body after error correction processing.
[0112] In the technical solution of the embodiment of the present invention, when receiving a user question that requires data analysis, first, the user question is matched based on a pre-constructed data set and a professional term library to obtain alternative prompt words that can be applied to the large model for generating structured query statements and contain more scenario information. Then, the target prompt word sentences constructed based on each alternative prompt word are input into the large model for generating structured query statements, so that the scenario matching degree and accuracy of the intermediate structured query statements output by the large model for generating structured query statements based on the target prompt word sentences are higher. At the same time, since there may be differences in understanding in the large model for generating structured query statements and errors may inevitably occur, after obtaining the intermediate structured query statement, it will be structurally converted according to a preset domain-specific language to obtain an intermediate query body, and the data in the pre-constructed data set and the database tables corresponding to the data set are used to perform secondary error correction processing on the possible generation errors in the intermediate query body. According to the intermediate query body after error correction processing, a target query statement that can finally meet the query requirements of the database table is obtained, which improves the usability and accuracy of the generated target query statement, increases the matching degree between the information contained in the target query statement and the usage scenario, and enables the generated target query statement to better meet the data analysis requirements in the query scenario required by the user.
[0113] Optionally, the prompt word determination module 41 is specifically configured to:
[0114] Perform regular matching on the received user question according to the pre-constructed professional term library, and determine the successfully matched professional terms as alternative prompt words;
[0115] Perform text similarity matching between the metric names in the pre-constructed data set and the user question, and determine the successfully matched metric names as alternative prompt words;
[0116] Perform text similarity matching between the keywords in the user question and the actual data in the database tables corresponding to the pre-constructed data set, and determine the dimension names of the successfully matched actual data in the pre-constructed data set as alternative prompt words.
[0117] Optionally, the prompt word determination module 41 is further configured to:
[0118] Extract time information from the user question;
[0119] Perform format conversion or common time template matching on the extracted time information to determine alternative prompt words.
[0120] Optionally, the target statement determination module 43 is specifically configured to:
[0121] Convert the intermediate structured query statement according to the query body structure of the preset domain-specific language to determine the intermediate query body;
[0122] Match the intermediate query body with the pre-constructed data set to determine the first matching result;
[0123] Perform text similarity matching between the intermediate query body and the database table corresponding to the pre-constructed data set to determine the second matching result;
[0124] Screen and replace the intermediate query body according to the first matching result and the second matching result to determine the target query body;
[0125] Convert the target query body into a structured query statement structure according to the query body structure to determine the target query statement.
[0126] Optionally, the query body structure at least includes a dimension name, an index name, and a dimension filtering condition; screening and replacing the intermediate query body according to the first matching result and the second matching result to determine the target query body includes:
[0127] Screen out the dimension names and index names that fail to match in the intermediate query body according to the first matching result;
[0128] Replace the dimension filtering condition in the intermediate query body according to the second matching result;
[0129] Determine the intermediate query body after screening out the dimension names and index names that fail to match and completing the replacement of the dimension filtering condition as the target query body.
[0130] Optionally, replacing the dimension filtering condition in the intermediate query body according to the second matching result includes:
[0131] If the second matching result is exactly the same, the dimension filtering condition is not replaced;
[0132] If the second matching result is not exactly the same, replace the dimension filtering condition with the data in the database table that is greater than the preset similarity threshold.
[0133] The query statement generation device provided by the embodiments of the present invention can execute the query statement generation method provided by any embodiment of the present invention, and has corresponding function modules and beneficial effects for executing the method.
[0134] Embodiment Five
[0135] Figure 5 It is a schematic structural diagram of a data analysis device provided by Embodiment Five of the present invention. As Figure 5 shown, the data analysis device includes a problem receiving module 51, a target statement determining module 52, a target data determining module 53, and a result display module 54.
[0136] Among them, the problem receiving module 51 is used to receive user problems; the target statement determining module 52 is used to process the user problems by the query statement generation method of any embodiment of the present invention to determine the target query statement; the target data determining module 53 is used to query the target database according to the target query statement to determine the target data; the result display module 54 is used to perform rendering processing on the target data and display the obtained analysis results.
[0137] The data analysis device provided by the embodiments of the present invention can execute the data analysis method provided by any embodiment of the present invention, and has functional modules and beneficial effects corresponding to the execution of the method.
[0138] Embodiment Six
[0139] Figure 6 It is a schematic structural diagram of an electronic device provided by Embodiment Six of the present invention. The electronic device 60 can be intended to represent various forms of digital computers, such as, laptop computers, desktop computers, workstations, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. The electronic device 60 can also represent various forms of mobile devices, such as, personal digital assistants, cellular phones, smart phones, wearable devices (such as helmets, glasses, watches, etc.) and other similar computing devices. The components shown herein, their connections and relationships, and their functions are only examples and are not intended to limit the implementation of the present invention described and / or claimed herein.
[0140] As Figure 6 shown, the electronic device 60 includes at least one processor 61 and a memory communicatively connected to the at least one processor 61, such as a read-only memory (ROM) 62, a random access memory (RAM) 63, etc. Among them, the memory stores a computer program executable by the at least one processor. The processor 61 can perform various appropriate actions and processes according to the computer program stored in the read-only memory (ROM) 62 or the computer program loaded from the storage unit 68 into the random access memory (RAM) 63. In the RAM 63, various programs and data required for the operation of the electronic device 60 can also be stored. The processor 61, the ROM 62, and the RAM 63 are connected to each other through a bus 64. The input / output (I / O) interface 65 is also connected to the bus 64.
[0141] Multiple components in the electronic device 60 are connected to the I / O interface 65, including: an input unit 66, such as a keyboard, a mouse, etc.; an output unit 67, such as various types of displays, speakers, etc.; a storage unit 68, such as a disk, an optical disc, etc.; and a communication unit 69, such as a network card, a modem, a wireless communication transceiver, etc. The communication unit 69 allows the electronic device 60 to exchange information / data with other devices through a computer network such as the Internet and / or various telecommunication networks.
[0142] The processor 61 can be various general-purpose and / or special-purpose processing components with processing and computing capabilities. Some examples of the processor 61 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various dedicated artificial intelligence (AI) computing chips, various processors running machine learning model algorithms, a digital signal processor (DSP), and any suitable processor, controller, microcontroller, etc. The processor 61 executes the various methods and processes described above, such as the query statement generation method or the data analysis method.
[0143] In some embodiments, the query statement generation method or the data analysis method can be implemented as a computer program, which is tangibly included in a computer-readable storage medium, such as the storage unit 68. In some embodiments, part or all of the computer program can be loaded and / or installed onto the electronic device 60 via the ROM 62 and / or the communication unit 69. When the computer program is loaded into the RAM 63 and executed by the processor 61, one or more steps of the power distribution scheme determination method described above can be executed. Alternatively, in other embodiments, the processor 61 can be configured to execute the query statement generation method or the data analysis method in any other suitable manner (e.g., by means of firmware).
[0144] Optionally, an embodiment of the present invention further provides a computer program product, including a computer program, which implements the query statement generation method or the data analysis method provided in any embodiment of the present invention when executed by a processor.
[0145] The various embodiments of the systems and techniques described above in this specification can be implemented in digital electronic circuitry, integrated circuit systems, field programmable gate arrays (FPGAs), application specific integrated circuits (ASICs), application specific standard products (ASSPs), systems-on-chip (SOCs), complex programmable logic devices (CPLDs), computer hardware, firmware, software, and / or combinations thereof. These various embodiments can include: being implemented in one or more computer programs that are executable and / or interpretable on a programmable system including at least one programmable processor, which can be a special-purpose or general-purpose programmable processor that receives data and instructions from, and transmits data and instructions to, a storage system, at least one input device, and at least one output device.
[0146] The computer programs for implementing the methods of the present invention can be written in any combination of one or more programming languages. These computer programs can be provided to a processor of a general purpose computer, special purpose computer, or other programmable data processing apparatus, such that the computer programs, when executed by the processor, cause the functions / operations specified in the flowchart and / or block diagram to be implemented. The computer programs can be executed entirely on the machine, partly on the machine, as a stand-alone software package partly on the machine and partly on a remote machine or entirely on the remote machine or server.
[0147] In the context of the present invention, a computer-readable storage medium can be a tangible medium that can contain or store a computer program for use by or in connection with an instruction execution system, apparatus, or device. The computer-readable storage medium can include, but is not limited to, electronic, magnetic, optical, electromagnetic, infrared, or semiconductor systems, apparatus, or devices, or any suitable combination of the foregoing. Alternatively, the computer-readable storage medium can be a machine-readable signal medium. More specific examples of a machine-readable storage medium would include an electrical connection based on one or more wires, a portable computer diskette, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or Flash memory), an optical fiber, a portable compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.
[0148] To provide interaction with a user, the systems and techniques described herein can be implemented on a power distribution scheme determination device having: a display device for displaying information to the user (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor); and a keyboard and a pointing device (e.g., a mouse or a trackball) through which the user can provide input to the power distribution scheme determination device. Other kinds of devices can also be used to provide interaction with the user; for example, the feedback provided to the user can be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user can be received in any form (including acoustic input, voice input, or tactile input).
[0149] The systems and techniques described herein can be implemented in a computing system including backend components (e.g., as a data server), or a computing system including middleware components (e.g., an application server), or a computing system including frontend components (e.g., a user computer having a graphical user interface or a web browser through which the user can interact with an implementation of the systems and techniques described herein), or a computing system including any combination of such backend components, middleware components, or frontend components. The components of the system can be interconnected to each other by digital data communication in any form or medium (e.g., a communication network). Examples of communication networks include: local area network (LAN), wide area network (WAN), blockchain network, and the Internet.
[0150] The computing system can include a client and a server. The client and the server are generally far from each other and usually interact through a communication network. The client-server relationship is created by computer programs running on the respective computers and having a client-server relationship with each other. The server can be a cloud server, also known as a cloud computing server or a cloud host, which is a host product in the cloud computing service system, and solves the defects of difficult management and weak business scalability existing in traditional physical hosts and VPS services.
[0151] It should be understood that the various forms of processes shown above can be reordered, added, or deleted steps. For example, the steps recited in the present invention can be executed in parallel, sequentially, or in a different order, as long as the desired results of the technical solution of the present invention can be achieved, and no limitation is made herein.
[0152] The above specific embodiments do not constitute a limitation on the protection scope of the present invention. Those skilled in the art should understand that various modifications, combinations, sub - combinations and substitutions can be made according to design requirements and other factors. Any modifications, equivalent substitutions and improvements made within the spirit and principle of the present invention shall be included within the protection scope of the present invention.
Claims
1. A method for generating a query statement, characterized in that, Including: Match the received user question against a pre - built data set and a pre - built professional term dictionary to determine alternative prompt words; Construct a target prompt word sentence based on each of the alternative prompt words and input the target prompt word sentence into a large model for generating structured query statements to determine an intermediate structured query statement; Convert the intermediate structured query statement into an intermediate query body according to a preset domain - specific language, and perform error correction processing on the intermediate query body based on the pre - built data set and the database table corresponding to the pre - built data set. Determine the target query statement according to the corrected intermediate query body.
2. The query statement generation method according to claim 1, wherein The converting the intermediate structured query statement into an intermediate query body according to a preset domain - specific language includes: Convert the intermediate structured query statement according to the query body structure of the preset domain - specific language to determine the intermediate query body.
3. The query statement generation method according to claim 2, wherein The performing error correction processing on the intermediate query body based on the pre - built data set and the database table corresponding to the pre - built data set and determining the target query statement according to the corrected intermediate query body includes: Match the intermediate query body with the pre - built data set to determine the first matching result; Perform text similarity matching between the intermediate query body and the database table corresponding to the pre - built data set to determine the second matching result; Screen and replace the intermediate query body according to the first matching result and the second matching result to determine the target query body; Convert the target query body into a structured query statement structure according to the query body structure to determine the target query statement.
4. The query statement generation method according to claim 3, wherein The query body structure at least includes a dimension name, an index name, and a dimension filtering condition; The screening and replacing the intermediate query body according to the first matching result and the second matching result to determine the target query body includes: Screen out the dimension names and index names that fail to match in the intermediate query body according to the first matching result; Replace the dimension filtering condition in the intermediate query body according to the second matching result; Determine the intermediate query body after screening out the dimension names and index names that fail to match and completing the replacement of the dimension filtering condition as the target query body.
5. The query statement generation method according to claim 4, wherein The replacing the dimension filtering condition in the intermediate query body according to the second matching result includes: If the second matching result is exactly the same, do not replace the dimension filtering condition; If the second matching result is not exactly the same, replace the dimension filtering condition with the data in the database table that is greater than the preset similarity threshold.
6. The query statement generation method according to claim 1, wherein The matching the received user question against a pre - built data set and a pre - built professional term dictionary to determine alternative prompt words includes: Perform regular matching on the received user question according to the pre - built professional term dictionary, and determine the successfully - matched professional terms as alternative prompt words; Perform text similarity matching between the index names in the pre - built data set and the user question, and determine the successfully - matched index names as alternative prompt words; Perform text similarity matching on the keywords in the user question and the actual data in the database table corresponding to the pre-built data set, and determine the dimension names of the actual data that match successfully in the pre-built data set as alternative prompt words.
7. The query statement generation method according to claim 6, wherein When matching the user question according to the pre-built data set and the pre-built professional noun thesaurus to determine alternative prompt words, it further includes: Extract time information from the user question; Perform format conversion or common time template matching on the extracted time information to determine alternative prompt words.
8. A data analysis method, characterized in that, It includes: Receive the user question; Process the user question through the query statement generation method described in any one of claims 1-7 to determine the target query statement; Query the target database according to the target query statement to determine the target data; Perform rendering processing on the target data and display the obtained analysis results.
9. An electronic device, characterized in that, It includes: At least one processor; And A memory communicatively connected to the at least one processor; wherein, The memory stores a computer program executable by the at least one processor, and the computer program is executed by the at least one processor so that the at least one processor can execute the query statement generation method described in any one of claims 1-7 or the data analysis method of claim 8.
10. A storage medium containing computer-executable instructions, characterized in that, The computer-executable instructions are used to execute the query statement generation method described in any one of claims 1-7 or the data analysis method of claim 8 when executed by a computer processor.
11. A computer program product, including a computer program, where the computer program realizes the query statement generation method described in any one of claims 1-7 or the data analysis method of claim 8 when executed by a processor.
Citation Information
Cited By
Question and answer query method and device based on large model
CN120910222A