Data query method and apparatus, computer device, and storage medium
By obtaining data query text, extracting keyword sets and building query statement templates, the problem of low data query efficiency in traditional technologies is solved, and efficient data acquisition is achieved for non-technical users.
Patent Information
- Application Number
- PCT/CN2024/140914
- Authority / Receiving Office
- WO · WO
- Patent Type
- Applications
- Current Assignee / Owner
- Priority Date
- 2024-03-21
- Filing Date
- 2024-12-20
- Publication Date
- 2025-09-25
AI Technical Summary
In traditional technologies, data query efficiency is low during the process of converting user-input questions into database query language. It is especially difficult for non-technical personnel to efficiently obtain the required data.
By obtaining the data query text, extracting the keyword set, determining the target data table, and building a query statement template based on the keyword set, filling in the keywords to generate the query statement, fast and accurate data query can be achieved.
It improves the efficiency and accuracy of data queries, enables non-technical users to quickly obtain the required data, and improves the efficiency of query statement generation.
Smart Images

Figure CN2024140914_25092025_PF_FP_ABST
Abstract
Description
Data query method, device, computer equipment and storage medium
[0001] This application claims priority to the Chinese patent application filed with the China Patent Office on March 21, 2024, with application number 202410325663.4 and invention name “Data Query Method, Device, Computer Equipment and Storage Medium”, the entire contents of which are incorporated by reference into this application. Technical Field
[0002] The present application relates to the field of computer technology, and in particular to a data query method, apparatus, computer equipment, storage medium, and computer program product. Background Art
[0003] With the rapid development of the internet, the amount of information and data continues to grow, and the importance of databases has become increasingly prominent. Databases store vast amounts of valuable structured data. Technical personnel primarily interact with databases through database query statements, but for most non-technical personnel, interacting with the database often involves directly entering query queries into information query systems.
[0004] In conventional technology, there is a problem of low data query efficiency in the process of converting a question input by a user into a corresponding database query language to query data. Summary of the Invention
[0005] Based on this, it is necessary to provide a data query method, device, computer equipment, computer-readable storage medium and computer program product that can improve data query efficiency in response to the above technical problems.
[0006] This application provides a data query method. The method includes:
[0007] Get data query text;
[0008] Extract keywords from the data query text to obtain a keyword set corresponding to the data query text;
[0009] Determine the target data table corresponding to the data query text based on the keyword set;
[0010] Based on the data query text, the keyword set and the target field set corresponding to the target data table, a query statement template corresponding to the data query text is constructed;
[0011] Based on the keyword set, a query statement template is filled in to obtain a query statement corresponding to the data query text; the query statement is used to determine the data query result corresponding to the data query text.
[0012] This application also provides a data query device. The device includes:
[0013] Text acquisition module, used to obtain data query text;
[0014] A keyword extraction module is used to extract keywords from the data query text and obtain a keyword set corresponding to the data query text;
[0015] A data table determination module is used to determine the target data table corresponding to the data query text according to the keyword set;
[0016] A template construction module is used to construct a query statement template corresponding to the data query text based on the data query text, the keyword set and the target field set corresponding to the target data table;
[0017] The statement determination module is used to fill in the query statement template based on the keyword set to obtain the query statement corresponding to the data query text; the query statement is used to determine the data query result corresponding to the data query text.
[0018] A computer device includes a memory and a processor. The memory stores a computer program. When the processor executes the computer program, the steps of the above-mentioned data query method are implemented.
[0019] A computer-readable storage medium stores a computer program, which implements the steps of the above-mentioned data query method when executed by a processor.
[0020] A computer program product includes a computer program, which implements the steps of the above data query method when executed by a processor.
[0021] The above-mentioned data query method, device, computer equipment, storage medium and computer program product obtain a data query text and extract a keyword set from the data query text. The target data table targeted by the data query text is determined based on the keyword set. A query statement template corresponding to the data query text is constructed based on the data query text, the keyword set and the target field set corresponding to the target data table. Then, the query statement template is filled in according to the keyword set to obtain the query statement corresponding to the data query text. The data query result corresponding to the data query text can be obtained by executing the query statement. In this way, when the data query text is obtained, the target data table queried by the data query text is determined based on the keyword set corresponding to the data query text, and then a query statement template is constructed according to the target data table and the keyword set. The keyword set is filled into the query statement template, so that the query statement corresponding to the data query text can be obtained quickly and accurately, effectively improving the efficiency of query statement generation, thereby improving the efficiency of data query. BRIEF DESCRIPTION OF THE DRAWINGS
[0022] FIG1 is an application environment diagram of a data query method according to an embodiment;
[0023] FIG2 is a schematic diagram of a flow chart of a data query method in one embodiment;
[0024] FIG3 is a schematic diagram of a process for determining a target data table in one embodiment;
[0025] FIG4 is a structural block diagram of a data query device according to an embodiment;
[0026] FIG5 is a diagram showing the internal structure of a computer device according to one embodiment;
[0027] FIG6 is a diagram showing the internal structure of a computer device in another embodiment. DETAILED DESCRIPTION
[0028] 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.
[0029] The data query method provided in the embodiment of the present application can be applied to the application environment shown in Figure 1. Among them, the terminal 102 communicates with the server 104 through the network. The data storage system can store the data that the server 104 needs to process. The data storage system can be integrated on the server 104, or it can be placed on the cloud or other network servers. 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 TVs, smart car-mounted devices, etc. Portable wearable devices can be smart watches, smart bracelets, head-mounted devices, etc. The server 104 can be implemented as an independent server or a server cluster consisting of multiple servers. The terminal 102 and the server 104 can be directly or indirectly connected via wired or wireless communication, and this application does not limit this.
[0030] Both the terminal and the server can be used independently to execute the data query method provided in the embodiments of the present application.
[0031] The terminal and the server can also be used together to execute the data query method provided in the embodiments of the present application.
[0032] For example, the terminal sends the acquired data query text to the server. The server extracts the keywords in the data query text and obtains the keyword set corresponding to the data query text. The server determines the target data table corresponding to the data query text based on the keyword set. The server constructs a query statement template corresponding to the data query text based on the data query text, the keyword set, and the target field set corresponding to the target data table. The server fills in the query statement template based on the keyword set to obtain the query statement corresponding to the data query text, and the query statement is used to determine the data query result corresponding to the data query text. The server can return the query statement to the terminal, or execute the query statement to obtain the data query result corresponding to the data query text, and send the data query result range value to the terminal.
[0033] In one embodiment, as shown in FIG2 , a data query method is provided. This method is described using a computer device as an example. The computer device may be a terminal or a server. The method may be executed independently by the terminal or server itself, or through interaction between the terminal and the server. The data query method includes the following steps:
[0034] Step S202: Obtain data query text.
[0035] Data query text refers to the text a user enters into the system to query data. It can be any form of natural language text, such as questions, commands, or conversations. For example, in a profit query scenario, a user might enter the question "What are the top five products by revenue for Group A in 2021?" This question constitutes the data query text.
[0036] For example, a database stores a massive amount of valuable structured data. Technical users mainly interact with the database by entering database query statements that comply with database operation rules. For most non-technical users who do not understand database knowledge, they often enter data query text in natural language. The computer device obtains the data query text entered by the user and converts the data query text into corresponding database query statements, so that non-technical users can also have the ability to query data.
[0037] Step S204: extract keywords from the data query text to obtain a keyword set corresponding to the data query text.
[0038] Keywords are the words used to generate data query statements within a data query text. These are the specific words used to describe data tables, data table fields, query conditions, and other information within the data query text. A keyword set is the collection of keywords contained within the data query text.
[0039] Exemplarily, a computer device divides a data query text into multiple text words, extracts keywords used to generate the data query text from each text word, and obtains a keyword set. Specifically, data query samples can be obtained from multiple business fields, and keywords corresponding to the data query samples can be manually labeled to obtain a labeled keyword set corresponding to each data query sample. The data query samples are input into an initial keyword extraction model to obtain a predicted keyword set corresponding to the data query samples. The model loss is calculated based on the difference between the labeled keyword set and the predicted keyword set. The model parameters of the keyword extraction model are adjusted based on the model loss until the model converges, thereby obtaining a keyword extraction model. The data query text is input into the keyword extraction model to obtain a keyword set corresponding to the data query text.
[0040] In one embodiment, the computer device can also extract semantic features corresponding to each text word, and extract text features corresponding to the data query text based on the context information corresponding to the data query text. The text features extracted based on the context information can more accurately represent the text meaning corresponding to the data query text. The text features corresponding to each text word are then compared with the text features corresponding to the data query text to obtain a key index corresponding to each text word. The key index is used to indicate the probability that the text word is a keyword. Based on the key index corresponding to each text word, each keyword corresponding to the data query text is extracted to obtain a keyword set. In this way, determining keywords based on the text features corresponding to the text words and the text features corresponding to the data query text can improve the accuracy of the determined keywords, thereby improving the accuracy of the generated query statement.
[0041] Step S206: determining the target data table corresponding to the data query text according to the keyword set.
[0042] The target data table is the data table being queried by the data query text. For example, for the data query text "What are the top five products by revenue for Group A in 2021?", the target data table corresponding to the data query text is the income statement that records the product revenue information for each group.
[0043] Exemplarily, the computer device compares the keyword set with each candidate data table, and uses the candidate data table with the highest correlation as the target data table corresponding to the data query text. Specifically, the data query text and the data table description information corresponding to each candidate data table can be compared to obtain the first matching degree corresponding to each candidate data table, and the candidate data table corresponding to the maximum first matching degree can be used as the target data table. The keyword set can also be compared with the candidate field set corresponding to each candidate data table to obtain the second matching degree corresponding to each candidate data table, and the candidate data table corresponding to the maximum second matching degree can be used as the target data table. That is, based on at least one of the first matching degree and the second matching point corresponding to the candidate data table, the target matching degree corresponding to each candidate data table is calculated, and the candidate data table corresponding to the maximum target matching degree is used as the target data table.
[0044] Step S208: constructing a query statement template corresponding to the data query text based on the data query text, the keyword set, and the target field set corresponding to the target data table.
[0045] The target field set corresponding to the target data table refers to the set of fields in the target data table. The query statement template is the basic structure of the query statement, containing placeholders to be filled. These placeholders will be replaced by actual strings in subsequent processing. For example, placeholders can be replaced by data table names, data table field names, and query condition values.
[0046] Exemplarily, the computer device extracts the feature vectors corresponding to each keyword in the keyword set based on the data query text, and determines the data table field corresponding to the keyword in the target data table based on the feature vectors corresponding to each keyword. A query statement template corresponding to the data query text is constructed using the data table fields corresponding to each keyword. For example, for the data query text "What are the top 5 products of Group A in terms of revenue in 21 years?", the keyword set is "product, Group A, 21 years, top 5", the keyword "product" corresponds to the data table field "product" in the target data table, the keyword "Group A" corresponds to the data table field "company name" in the target data table, the keyword "21 years" corresponds to the data table field "year" in the target data table, and the keyword "top 5" corresponds to the data table field "operating income" in the target data table.
[0047] Step S210 , based on the keyword set, fill in the query statement template to obtain the query statement corresponding to the data query text; the query statement is used to determine the data query result corresponding to the data query text.
[0048] The query statement refers to a database query statement generated based on the data query text, which is used to perform query operations on the data table. For example, the query statement can be an SQL (Structured Query Language) statement to query databases such as Mysql, SQL Server, Hive, etc., or it can be a non-relational database query statement.
[0049] Exemplarily, a computer device extracts target entities corresponding to keywords in a target data table from a keyword set and populates the target entities corresponding to the keywords into a query statement template to obtain a query statement corresponding to the data query text. The target entity refers to the field value corresponding to the keyword in the target data table. The query statement is executed to obtain a data query result corresponding to the data query text, and the data query result is returned to the sender of the data query text.
[0050] In the above data query method, a data query text is obtained and a keyword set is extracted from the data query text. The target data table targeted by the data query text is determined based on the keyword set. A query statement template corresponding to the data query text is constructed based on the data query text, the keyword set and the target field set corresponding to the target data table. Then, the query statement template is filled in based on the keyword set to obtain the query statement corresponding to the data query text. The data query result corresponding to the data query text can be obtained by executing the query statement. In this way, when the data query text is obtained, the target data table queried by the data query text is determined based on the keyword set corresponding to the data query text, and then a query statement template is constructed based on the target data table and the keyword set. The keyword set is filled into the query statement template, so that the query statement corresponding to the data query text can be obtained quickly and accurately, effectively improving the efficiency of query statement generation, thereby improving the efficiency of data query.
[0051] In one embodiment, the data query method further includes:
[0052] The data query text is input into the query statement generation model to obtain the query statement corresponding to the data query text; the query statement generation model is trained based on multiple data query samples and the sample label sets corresponding to each data query sample; the query statement generation model includes a keyword extraction branch for extracting the keyword set corresponding to the data query text, a template generation branch for generating a query statement template corresponding to the data query text, and a statement generation branch for generating a query statement based on the keyword set and the query statement template.
[0053] The query statement generation model refers to a model used to generate query statements corresponding to data query text. The input data of the query statement generation model is the data query text, and the output data is the query statement corresponding to the data query text. The data query sample refers to data query text obtained from data query corpora corresponding to multiple business fields. The sample label set corresponding to the data query sample includes at least one of a keyword set, a query statement template, and a query statement corresponding to the data query sample.
[0054] Exemplarily, a computer device inputs a data query text into a query statement generation model. First, a keyword extraction branch within the query statement generation model extracts a keyword set corresponding to the data query text. Based on the keyword set, the query statement generation model determines a target data table corresponding to the data query text. The query statement generation model then inputs the data query text, the keyword set, and the target field set corresponding to the target data table into a template generation branch to obtain a query statement template corresponding to the data query text. The query statement generation model extracts the target entities corresponding to each keyword in the target data table, inputs the data query text and the target entities corresponding to each keyword into a statement generation branch to obtain a query statement corresponding to the data query text.
[0055] In the above embodiment, by obtaining data query samples from data query corpora corresponding to multiple different business domains and training a query generation model based on each data query sample, the generalization of the query generation model can be improved, thereby improving the accuracy of the generated query statements. The query generation model first extracts a keyword set through the keyword extraction branch, then generates a query statement template through the template generation branch. Finally, keyword completion is performed on the query statement template using the query statement, enabling rapid and accurate query generation.
[0056] In one embodiment, keywords are extracted from the data query text to obtain a keyword set corresponding to the data query text, including:
[0057] Extract multiple text words from data query text;
[0058] Based on the association between each text word in the data query text, extract the text features corresponding to each text word;
[0059] Determine the target word in each text word based on the text features corresponding to each text word;
[0060] Based on the target word, a keyword set corresponding to the data query text is obtained.
[0061] Here, text words refer to the individual words obtained by segmenting the data query text, that is, the words that make up the data query text. Text features refer to feature vectors that represent the semantic information corresponding to text words and the relationship between text words and other text words. Target words refer to keywords contained in the data query text.
[0062] Exemplarily, the computer device preprocesses the data query text and removes irrelevant information such as punctuation marks. A plurality of text words are extracted from the preprocessed data query text. Then, the text features corresponding to each text word are extracted using a pre-trained text feature extraction model. The text feature extraction model is obtained by training based on a large number of corpus samples and can capture the semantic relationship between each text word in the data query text. Based on the text features corresponding to each text word, the text features corresponding to each text word are compared with the text features corresponding to the query text to obtain the key index corresponding to each text word. The key index is used to indicate the probability that the text word is a keyword. Then, based on the key index corresponding to each text word, each keyword corresponding to the data query text is extracted to obtain a keyword set. Specifically, a text word with a key index greater than a preset threshold can be used as a keyword.
[0063] In the above embodiment, keywords are determined based on the text features corresponding to the text words and the text features corresponding to the data query text, taking into account the semantic information of the text words themselves and the context information corresponding to the text words in the data query text, which can improve the accuracy of the determined keywords and thus improve the accuracy of the generated query statements.
[0064] In one embodiment, as shown in FIG3 , determining the target data table corresponding to the data query text according to the keyword set includes:
[0065] Step S302: Obtain data table description information corresponding to each of the plurality of candidate data tables.
[0066] Step S304 : calculating the text similarity between the data query text and the data table description information corresponding to each candidate data table, and obtaining the first matching degree corresponding to each candidate data table.
[0067] Step S306 : Compare the keyword set with the candidate field sets corresponding to the candidate data tables to obtain the second matching degrees corresponding to the candidate data tables.
[0068] Step S308 : The first matching degree and the second matching degree corresponding to the same candidate data table are merged to obtain the target matching degree corresponding to each candidate data table.
[0069] Step S310 : determining the target data table corresponding to the data query text based on the target matching degrees corresponding to the candidate data tables.
[0070] Table description information refers to information that uses natural language (such as Chinese or English) to explain and describe the table's content, structure, and field meanings. This information explains the table's basic information and purpose in easy-to-understand text. A candidate table refers to a table stored in a database. A candidate field set refers to the collection of table fields within a candidate table.
[0071] The first match degree refers to the degree of match between the data query text and the candidate data table. The second match degree refers to the degree of match between the keyword set and the candidate field set corresponding to the candidate data table. The target match degree is the degree of match between the candidate data table and the data query text, which is obtained by combining the first and second match degrees. The match degree indicates the probability that the candidate data table is the data table queried by the data query text.
[0072] Exemplarily, a computer device obtains data table description information corresponding to each candidate data table. Text features corresponding to each data table description information and text features corresponding to the data query text are extracted. Text similarities between the text features corresponding to the data table description information and the data query text are calculated to obtain first matching degrees between each candidate data table and the data query text. A keyword set is compared with a candidate field set corresponding to the candidate data table to obtain first matching degrees corresponding to each candidate data table. Specifically, the text features corresponding to each keyword in the keyword set can be extracted and fused to obtain comprehensive text features corresponding to the keyword set, and the text features corresponding to each candidate field in the candidate field set can be extracted and fused to obtain comprehensive text features corresponding to the candidate field set. The similarity between the comprehensive text features corresponding to the keyword set and the comprehensive text features corresponding to the candidate field set is calculated to obtain a second matching degree corresponding to the candidate data table. The first matching degree and the second matching degree corresponding to the same candidate data table are fused to obtain a target matching degree corresponding to each candidate data table. The candidate data table corresponding to the maximum target matching degree is then used as the target data table corresponding to the data query text.
[0073] In the above embodiment, the target data table is jointly determined based on the similarity between the data query text and the data table description information corresponding to the candidate data table, and the similarity between the keyword set and the candidate field set corresponding to the candidate data table. This can improve the accuracy of the determined target data table, thereby improving the accuracy of the generated query statement.
[0074] In one embodiment, a query statement template corresponding to the data query text is constructed based on the data query text, the keyword set, and the target field set corresponding to the target data table, including:
[0075] Extract attribute features corresponding to each keyword in the keyword set based on the data query text;
[0076] Based on the attribute features corresponding to each keyword, determining the return attribute field and the condition attribute field corresponding to the data query text from each target field included in the target field set;
[0077] Generate a query statement template corresponding to the data query text based on the return attribute field and the condition attribute field.
[0078] Attribute features indicate the degree of match between keywords and the return attributes and condition attributes corresponding to the query statement template. Return attributes, in a query statement, indicate the fields to be queried in a data table. Condition attributes, in a query statement, indicate the query conditions. Return attribute fields refer to the data table fields corresponding to the return attributes defined in the data table. Condition attribute fields refer to the fields corresponding to the condition attributes defined in the data table. For example, if the query text is "What are the top five products by revenue for Group A in 21 years?", the keyword set corresponding to the query text is "product, Group A, 21 years, top 5." The query statement template is SELECT product FROM profit table WHERE company name = "candidate word" and year in "candidate word" order by operating income limit "candidate word"; In this case, the first string "product" following SELECT is the return attribute field, the first string "profit table" following FROM is the table identifier, "company name," "year," and "operating income" following WHERE are the condition attribute fields, and "candidate word" is a placeholder that can be replaced by the actual query condition value.
[0079] Exemplarily, a computer device extracts attribute features corresponding to each keyword in a keyword set based on a data query text. Based on the attribute features corresponding to each keyword, the computer device determines keywords corresponding to the return attribute and keywords corresponding to the conditional attribute. Furthermore, from the target field set corresponding to the target data table, the target fields corresponding to the keywords corresponding to the return attribute are retrieved as the return attribute fields, and the target fields corresponding to the keywords corresponding to the conditional attribute are retrieved as the conditional attribute fields. For example, if the data query text is "What are the top five products of Group A in terms of revenue in 2021?", the keyword set corresponding to the data query text is "product, Group A, 2021, top 5." "Product" is a keyword for the return attribute, and the keyword "product" corresponds to the return attribute field "product" in the target data table. "Group A," "2021," and "top 5" are all keywords for the conditional attribute, and the keyword "Group A" corresponds to the conditional attribute field "company name" in the target data table. The statement connective corresponding to the return attribute field and the return attribute field are combined to generate a first clause. For example, in an SQL statement, the connective corresponding to the return attribute field is SELECT. A second clause is generated based on the statement connective corresponding to the data table identifier. The sentence conjunction corresponding to the condition attribute field and the condition attribute field are combined to obtain the third clause. The first clause, the second clause, and the third clause are concatenated to obtain the query statement template corresponding to the data query text.
[0080] In the above embodiment, the return attribute fields and condition attribute fields that constitute the query statement template are first extracted, and then the clauses corresponding to the various attribute fields and data table identifiers are combined based on the corresponding statement conjunctions. Finally, the various clauses are spliced together, which can quickly and accurately generate a query statement template corresponding to the data query text, thereby improving the efficiency and accuracy of data query.
[0081] In one embodiment, based on the keyword set, a query statement template is filled in to obtain a query statement corresponding to the data query text, including:
[0082] Determine the conditional keyword corresponding to the conditional attribute field corresponding to the data query text from the keyword set;
[0083] Based on the data query text and conditional keywords, extract the word features corresponding to the conditional keywords;
[0084] Based on the word features corresponding to the conditional keywords, determine the target entity corresponding to the conditional keywords;
[0085] Fill the target entity into the query statement template to obtain the query statement corresponding to the data query text.
[0086] Conditional keywords are keywords in the keyword set that indicate the field value corresponding to the conditional attribute field (i.e., the query condition value). The word features corresponding to conditional keywords are feature vectors that represent the semantic information of the conditional keywords in the data query text. The target entity refers to the field value corresponding to the conditional keyword in the database. For example, if the data query text is "What are the top 5 products by revenue for Group A in 21?", the query statement template is "SELECT products FROM income statement WHERE company name = "candidate word" and year in "candidate word" order by revenue limit "candidate word";." "A Group," "21 years," and "top 5" are the multiple conditional keywords corresponding to the data query text. The target entity corresponding to "A Group" is "Axx Group," the target entity corresponding to "21 years" is "2021," and the target entity corresponding to "top 5" is "5." Filling the query statement template with the target entities yields the query statement "SELECT products FROM income statement WHERE company name = "Axx Group" and year in ("2021") order by revenue limit 5;."
[0087] Exemplarily, the computer device determines, from the keyword set, the conditional keywords corresponding to the conditional attribute fields corresponding to the data query text, i.e., the keywords corresponding to the conditional attributes. There may be one or more conditional attribute fields, and the computer device determines the conditional keywords corresponding to each conditional attribute field. Furthermore, the computer device extracts the word features corresponding to each conditional keyword, and based on the word features corresponding to each conditional keyword, determines the target entity corresponding to each conditional keyword.
[0088] The computer device fills the target entity corresponding to each condition keyword and the data table identifier corresponding to the target data table into the query statement template to obtain the query statement corresponding to the data query text. The data table identifier refers to the table name of the data table. Specifically, in the query statement template, the data table identifier corresponds to a placeholder, and each condition attribute field corresponds to a placeholder. The placeholder corresponding to the data table identifier is replaced based on the data table identifier, and the placeholder corresponding to the condition attribute field is replaced based on the condition keyword corresponding to the condition attribute field, until the placeholder corresponding to each condition attribute field is replaced by the corresponding condition keyword, and the query statement corresponding to the data query text is obtained.
[0089] In some embodiments, the data query text and conditional keywords are input into the entity prediction model. The entity prediction model first extracts the word features corresponding to the conditional keywords in the data query text, and then predicts the target entity corresponding to the conditional keywords based on the word features corresponding to the conditional keywords. The entity prediction model can be a separate neural network model or a model branch included in the query language generation model. The entity prediction model is trained based on multiple data query samples in the corpus and the sample label sets corresponding to the data query samples. The sample label sets include the keyword sets corresponding to the data query samples, the target entities of each keyword in the keyword set, the query statement templates, and the query statements.
[0090] In some embodiments, based on the word features corresponding to the conditional keyword, the semantic similarity between the conditional keyword and each field value in the target data table is determined, and the field value with the maximum semantic similarity is used as the target entity corresponding to the conditional keyword. In this way, the target entity corresponding to the conditional keyword is determined from each field value included in the target data table, which can improve the accuracy of the determined target entity.
[0091] In the above embodiment, after determining the conditional keywords corresponding to each conditional attribute field, the corresponding word features are further extracted based on the conditional keywords and the data query text. Furthermore, based on the corresponding word features, the target entity corresponding to the keyword is determined. Finally, the target entity is populated into the query statement template. This eliminates ambiguity caused by the diversity of natural language, resulting in a more accurate query statement and improving the accuracy of data queries.
[0092] In one embodiment, determining the target entity corresponding to the conditional keyword based on the word features corresponding to the conditional keyword includes:
[0093] Based on the word features corresponding to the conditional keywords, multiple candidate entities corresponding to the conditional keywords are extracted from the target data table;
[0094] Extract the basic entity features corresponding to each candidate entity from the data table description information corresponding to the target data table;
[0095] Based on the matching degree between the basic entity features corresponding to each candidate entity and the context information corresponding to the data query text, the target entity corresponding to the conditional keyword is determined in each candidate entity.
[0096] Among them, candidate entities refer to candidate field values obtained by mapping conditional keywords to the target data table. Basic entity features refer to feature vectors extracted from candidate entities. They contain information such as semantic information corresponding to the candidate entity and the semantic relationships between the candidate entity and other candidate entities. Contextual information corresponding to the data query text includes the user's query history and query status corresponding to the data query text, which is important for assisting in understanding the data query text.
[0097] Exemplarily, the computer device uses a multi-way recall strategy to extract multiple candidate entities corresponding to the conditional keywords from the various field values contained in the target data table based on the word features corresponding to the conditional keywords. For example, different recall algorithms such as keyword matching, vector retrieval, synonym hits, and topic identification can be used to quickly retrieve multiple candidate entities corresponding to each conditional keyword from the large amount of data contained in the target data table. Furthermore, the basic entity features corresponding to each candidate entity are extracted from the data table description information corresponding to the target data table. Furthermore, the context features corresponding to the data query text are extracted from the context information corresponding to the data query text. Based on the basic entity features and context features corresponding to each candidate entity, the degree of match between each candidate entity and the context information corresponding to the data query text is determined, and the candidate entity with the highest degree of match is used as the target entity corresponding to the conditional keyword.
[0098] In the above embodiment, a multi-path recall strategy is first used to quickly identify a small number of candidate entities corresponding to the conditional keywords in the target data table, significantly narrowing the search scope of the target entity and improving the efficiency of identifying the target entity. Furthermore, based on the matching degree between the basic features corresponding to the candidate entities and the contextual information corresponding to the data query text, the target entity can be quickly and accurately identified from each candidate entity, improving the efficiency and accuracy of data queries.
[0099] In a specific embodiment, the data query method proposed in this application can be applied to an information query system. The data query method includes the following steps:
[0100] 1. Build a corpus
[0101] The information query system extracts various data query samples entered by users when querying database data in the information query system, and annotates the data query samples through SQL experts to obtain sample labels corresponding to each data query sample. Based on each data query sample and the sample label corresponding to the data query sample, a corpus of a general field is obtained. For example, the corpus size can be 10,000 data query samples, of which 8,000 are used as a training set and 2,000 are used as a validation set. The data format of the training sample includes the user's question (i.e., the data query sample) and the sample label. The sample label includes information such as the name of the data table targeted by the question, the field pattern of the data table, and the SQL template. For example, the training sample can be in the following form:
[0102] {Table name: "Income Statement",
[0103] Form fields: "operating income, operating expenses, products, company name, year, operating income, etc."
[0104] Question: "What are the top 5 products in terms of revenue for Group A in 2021?"
[0105] Keywords: "product, A Group, 21 years, top 5",
[0106] SQL template: SELECT products FROM income statement WHERE company name = "candidate word" and year in "candidate word" order by "operating income" limit "candidate word";"}
[0107] 2. Model construction
[0108] The information query system trains an SQL statement generation model based on a constructed corpus. The SQL statement generation model can be a large language model, a deep learning model trained on massive amounts of text data. The SQL statement generation model consists of two branches: keyword recognition and SQL template generation. The training process for each branch primarily involves three steps: data input, encoder operation, and output. During the data input step, the input data for the SQL statement generation model can be any form of natural language text, such as questions, commands, or conversations. The model converts the input data into a "token" format, a data format that the model can understand and process. The encoder incorporates a multi-layer self-attention mechanism that captures the various complex relationships in the text and generates a context-sensitive word vector representation. After processing by the encoder, a prediction sequence is generated, consisting of a series of tokens with the highest probability. The prediction sequence is then converted into natural language text to produce the output data. For the keyword recognition model, the prediction sequence is the individual keywords, while for the SQL template generation model, the prediction sequence is the SQL template. After obtaining the data query text, the data query text is input into the SQL statement generation model to obtain the corresponding keyword set and SQL template. The keyword set is entity aligned and mapped to the standard terminology in the database (i.e., target entity). Finally, the target entity corresponding to each keyword is filled in the SQL template to obtain the final SQL statement.
[0109] In the above-described embodiments, SQL template generation, entity alignment, and SQL statement completion technologies are used to rapidly convert data query text into corresponding SQL statements. This solves the problem of users using natural language to directly query various information query systems, improving query efficiency. By first generating a relatively general SQL draft (i.e., an SQL template) and then combining the excellent generalization capabilities of a large model to perform keyword completion on the SQL draft, the generalization capabilities of NL2SQL (Natural Language to SQL), a technology that converts a user's natural language into executable SQL statements, are enhanced in general domains.
[0110] It should be understood that, although the steps in the flowcharts of the above embodiments are shown in sequence as indicated by the arrows, these steps are not necessarily performed 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 performed in other orders. Moreover, at least a portion of the steps in the flowcharts of the above embodiments may include multiple steps or multiple stages, and these steps or stages are not necessarily performed at the same time, but can be performed at different times. The execution order of these steps or stages is not necessarily to be performed in sequence, but can be performed in turn or alternately with other steps or at least a portion of steps or stages in other steps.
[0111] Based on the same inventive concept, embodiments of the present application also provide a data query device for implementing the aforementioned data query method. The implementation solution provided by this device is similar to the implementation solution described in the aforementioned method. Therefore, the specific limitations of one or more data query device embodiments provided below can be found in the above-mentioned limitations of the data query method and will not be repeated here.
[0112] In one embodiment, as shown in FIG4 , a data query device is provided, comprising: a text acquisition module 402 , a keyword extraction module 404 , a data table determination module 406 , a template construction module 408 , and a statement determination module 410 , wherein:
[0113] The text acquisition module 402 is used to acquire the data query text.
[0114] The keyword extraction module 404 is used to extract keywords from the data query text to obtain a keyword set corresponding to the data query text.
[0115] The data table determination module 406 is configured to determine a target data table corresponding to the data query text according to the keyword set.
[0116] The template construction module 408 is used to construct a query statement template corresponding to the data query text based on the data query text, the keyword set and the target field set corresponding to the target data table.
[0117] The statement determination module 410 is used to fill in the query statement template based on the keyword set to obtain the query statement corresponding to the data query text; the query statement is used to determine the data query result corresponding to the data query text.
[0118] In one embodiment, the data query device also includes a model processing module, which is used to input the data query text into a query statement generation model to obtain a query statement corresponding to the data query text; the query statement generation model is trained based on multiple data query samples and sample label sets corresponding to each data query sample; the query statement generation model includes a keyword extraction branch for extracting a keyword set corresponding to the data query text, a template generation branch for generating a query statement template corresponding to the data query text, and a statement generation branch for generating a query statement based on the keyword set and the query statement template.
[0119] In one embodiment, the keyword extraction module 404 is further configured to:
[0120] Extract multiple text words from the data query text; based on the association relationship between each text word in the data query text, extract the text features corresponding to each text word; based on the text features corresponding to each text word, determine the target word in each text word; and obtain the keyword set corresponding to the data query text based on the target word.
[0121] In one embodiment, the data table determination module 406 is further configured to:
[0122] Obtain data table description information corresponding to multiple candidate data tables respectively; calculate the text similarity between the data query text and the data table description information corresponding to each candidate data table respectively, and obtain the first matching degree corresponding to each candidate data table respectively; compare the keyword set with the candidate field set corresponding to each candidate data table respectively, and obtain the second matching degree corresponding to each candidate data table respectively; fuse the first matching degree and the second matching degree corresponding to the same candidate data table respectively, and obtain the target matching degree corresponding to each candidate data table respectively; determine the target data table corresponding to the data query text based on the target matching degree corresponding to each candidate data table respectively.
[0123] In one embodiment, the template construction module 408 is further configured to:
[0124] Based on the data query text, the attribute features corresponding to each keyword in the keyword set are extracted; based on the attribute features corresponding to each keyword, the return attribute field and the condition attribute field corresponding to the data query text are determined from each target field included in the target field set; based on the return attribute field and the condition attribute field, a query statement template corresponding to the data query text is generated.
[0125] In one embodiment, the statement determination module 410 is further configured to:
[0126] Determine the conditional keywords corresponding to the conditional attribute fields corresponding to the data query text from the keyword set; extract the word features corresponding to the conditional keywords based on the data query text and the conditional keywords; determine the target entity corresponding to the conditional keywords based on the word features corresponding to the conditional keywords; fill the target entity into the query statement template to obtain the query statement corresponding to the data query text.
[0127] In one embodiment, the statement determination module 410 is further configured to:
[0128] Based on the word features corresponding to the conditional keywords, multiple candidate entities corresponding to the conditional keywords are extracted from the target data table; the basic entity features corresponding to each candidate entity are extracted from the data table description information corresponding to the target data table; based on the matching degree between the basic entity features corresponding to each candidate entity and the context information corresponding to the data query text, the target entity corresponding to the conditional keyword is determined among each candidate entity.
[0129] The above-mentioned data query device, when obtaining a data query text, determines the target data table queried by the data query text based on the keyword set corresponding to the data query text, and then constructs a query statement template according to the target data table and the keyword set, and fills the keyword set into the query statement template. It can quickly and accurately obtain the query statement corresponding to the data query text, effectively improve the efficiency of query statement generation, and thus improve the efficiency of data query.
[0130] Each module in the above-mentioned data query device can be implemented in whole or in part by software, hardware, or a combination thereof. Each module can be embedded in or independent of the processor in the computer device in the form of hardware, or can be stored in the memory of the computer device in the form of software, so that the processor can call and execute the corresponding operations of each module.
[0131] In one embodiment, a computer device is provided, which may be a server, and its internal structure diagram may be shown in Figure 5. The computer device includes a processor, a memory, an input / output interface (I / O), and a communication interface. The processor, memory, and I / O interface are connected via a system bus, and the communication interface is connected to the system bus via the I / O interface. 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 such as keyword sets and target data tables. The I / O interface of the computer device is used to exchange information between the processor and external devices. The communication interface of the computer device is used to communicate with external terminals via a network connection. When the computer program is executed by the processor, a data query method is implemented.
[0132] In one embodiment, a computer device is provided, which may be a terminal. Its internal structure diagram may be shown in FIG6 . The computer device includes a processor, memory, an input / output interface, a communication interface, a display unit, and an input device. The processor, memory, and input / output interface are connected via a system bus, and the communication interface, display unit, and input device are connected to the system bus via the input / output interface. The processor of the computer device is configured to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and internal memory. The non-volatile storage medium stores an operating system and a computer program. The internal memory provides an environment for the operation of the operating system and computer program in the non-volatile storage medium. The input / output interface of the computer device is configured to exchange information between the processor and external devices. The communication interface of the computer device is configured to communicate with external terminals via wired or wireless communication, where the wireless communication may be achieved via Wi-Fi, a mobile cellular network, NFC (near-field communication), or other technologies. When executed by the processor, the computer program implements a data query method. The display unit of the computer device is configured to produce a visually visible image and may be a display screen, a projection device, or a virtual reality imaging device. The display screen can be a liquid crystal display screen or an electronic ink display screen, and the input device of the computer device can be a touch layer covering the display screen, or a button, trackball or touchpad set on the computer device casing, or an external keyboard, touchpad or mouse.
[0133] Those skilled in the art will understand that the structures shown in Figures 5 and 6 are merely block diagrams of partial structures related to the solution of the present application, and do 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 figures, or combine certain components, or have a different component arrangement.
[0134] In one embodiment, a computer device is provided, including a memory and a processor. The memory stores a computer program, and the processor implements the steps in the above method embodiments when executing the computer program.
[0135] In one embodiment, a computer-readable storage medium is provided, on which a computer program is stored. When the computer program is executed by a processor, the steps in the above-mentioned method embodiments are implemented.
[0136] In one embodiment, a computer program product or computer program is provided, comprising computer instructions stored in a computer-readable storage medium. A processor of a computer device reads the computer instructions from the computer-readable storage medium and executes the computer instructions, causing the computer device to perform the steps of each of the above-described method embodiments.
[0137] 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, and the collection, use and processing of relevant data must comply with the relevant laws, regulations and standards of relevant countries and regions.
[0138] Those skilled in the art will appreciate that all or part of the processes in the above-mentioned embodiment methods can be implemented by instructing the relevant hardware through a computer program, and 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 embodiments of the above-mentioned methods. Among them, any reference to memory, database or other media used in the embodiments provided in this application may include at least one of non-volatile and volatile memory. Non-volatile memory may 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 may include random access memory (RAM) or external cache memory, etc. By way of illustration and not limitation, RAM can be in various forms, such as static random access memory (SRAM) or dynamic random access memory (DRAM). The database 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 processor involved in the various embodiments provided herein may be, but are not limited to, a general-purpose processor, a central processing unit, a graphics processing unit, a digital signal processor, a programmable logic unit, a data processing logic unit based on quantum computing, and the like.
[0139] 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.
[0140] 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 data query method, characterized in that: The method comprises: Get data query text; Extracting keywords from the data query text to obtain a keyword set corresponding to the data query text; Determine the target data table corresponding to the data query text according to the keyword set; Constructing a query statement template corresponding to the data query text based on the data query text, the keyword set, and the target field set corresponding to the target data table; Based on the keyword set, the query statement template is filled to obtain a query statement corresponding to the data query text; the query statement is used to determine the data query result corresponding to the data query text.
2. The method according to claim 1, characterized in that The method further comprises: Inputting the data query text into a query statement generation model to obtain a query statement corresponding to the data query text; the query statement generation model is trained based on multiple data query samples and sample label sets corresponding to each of the data query samples; The query statement generation model includes a keyword extraction branch for extracting a keyword set corresponding to the data query text, a template generation branch for generating a query statement template corresponding to the data query text, and a statement generation branch for generating a query statement based on the keyword set and the query statement template.
3. The method according to claim 1, characterized in that The step of extracting keywords from the data query text to obtain a keyword set corresponding to the data query text includes: extracting a plurality of text words from the data query text; Extracting text features corresponding to each of the text words based on the association relationship between the text words in the data query text; Determining a target word among the text words based on text features corresponding to the text words; A keyword set corresponding to the data query text is obtained based on the target word.
4. The method according to claim 1, wherein The step of determining a target data table corresponding to the data query text according to the keyword set includes: Obtain data table description information corresponding to multiple candidate data tables; Calculating text similarity between the data query text and the data table description information corresponding to each of the candidate data tables, to obtain a first matching degree corresponding to each of the candidate data tables; Comparing the keyword set with candidate field sets corresponding to the candidate data tables, respectively, to obtain second matching degrees corresponding to the candidate data tables; Merging the first matching degree and the second matching degree corresponding to the same candidate data table to obtain the target matching degree corresponding to each candidate data table; Based on the target matching degrees corresponding to the candidate data tables, the target data table corresponding to the data query text is determined.
5. The method according to claim 1, wherein The step of constructing a query statement template corresponding to the data query text based on the data query text, the keyword set, and the target field set corresponding to the target data table includes: Extracting attribute features corresponding to each of the keywords in the keyword set based on the data query text; Based on the attribute features corresponding to the keywords, the return attribute field and the condition attribute field corresponding to the data query text are determined from the target fields included in the target field set; A query statement template corresponding to the data query text is generated based on the return attribute field and the condition attribute field.
6. The method according to claim 1, characterized in that The step of filling the query statement template based on the keyword set to obtain a query statement corresponding to the data query text includes: Determining, from the keyword set, a condition keyword corresponding to the condition attribute field corresponding to the data query text; Based on the data query text and the conditional keywords, extracting word features corresponding to the conditional keywords; Determining a target entity corresponding to the conditional keyword based on a word feature corresponding to the conditional keyword; Fill the target entity into the query statement template to obtain a query statement corresponding to the data query text.
7. The method according to claim 6, characterized in that The determining the target entity corresponding to the conditional keyword based on the word feature corresponding to the conditional keyword includes: Extracting multiple candidate entities corresponding to the conditional keywords from the target data table based on word features corresponding to the conditional keywords; Extracting basic entity features corresponding to each of the candidate entities from the data table description information corresponding to the target data table; Based on the matching degree between the basic entity features corresponding to each of the candidate entities and the context information corresponding to the data query text, the target entity corresponding to the conditional keyword is determined in each of the candidate entities.
8. A data query device, characterized in that: The device comprises: Text acquisition module, used to obtain data query text; A keyword extraction module, configured to extract keywords from the data query text to obtain a keyword set corresponding to the data query text; A data table determination module, configured to determine a target data table corresponding to the data query text according to the keyword set; A template construction module, configured to construct a query statement template corresponding to the data query text based on the data query text, the keyword set, and the target field set corresponding to the target data table; A statement determination module is used to fill in the query statement template based on the keyword set to obtain a query statement corresponding to the data query text; the query statement is used to determine the data query result corresponding to the data query text.
9. 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 7 are implemented.
10. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 7 are implemented.
11. A computer program product comprising a computer program, characterized in that When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 7 are implemented.
Citation Information
Patent Citations
Data query method and device and electronic equipment
CN111177180A
Structured query language conversion method based on natural language, and related equipment thereof
CN111177184A
Database query method and device, computer equipment and storage medium
CN114253990A
Information query method
CN116595026A
Data query method and device, computer equipment and storage medium
CN117931858A
Cited By
Query statement generation method and device, electronic equipment and storage medium
CN121501828A