Query statement generation method and device, equipment, medium and program product
Through similarity matching and user confirmation mechanisms, optimized SQL query statements are generated, which solves the problems of database table selection and SQL grammar learning in the existing technology, and improves query accuracy and interaction convenience.
Patent Information
- Application Number
- CN202411185878.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-27
- Publication Date
- 2024-11-29
AI Technical Summary
The prior art cannot intelligently select the most appropriate database table and consider the relationship between tables to generate optimized query statements, and for non-technical personnel, learning SQL syntax is a challenge, increasing the threshold for users and database interactions. .
By obtaining text query information and the data table collection, filter out the data table combination with the association relationship, calculate and select the combination with the largest number of associations, and initiate confirmation instructions to the user to ensure that the matching combination meets the needs and finally generate a structure query language query statement.
It improves the accuracy of data table matching and the accuracy of SQL query statement generation, and lowers the threshold for user-database interaction.
Smart Images

Figure CN119046312A_ABST
Abstract
Description
Technical Field
[0001] The present disclosure relates to the field of computer technology, and in particular to a query statement generation method, device, equipment, medium and program product. Background Art
[0002] In database management systems, Structured Query Language (SQL) is usually used to query and operate databases. Users must understand the database structure and SQL syntax to perform effective queries. However, for non-technical personnel, learning SQL syntax can be a challenge. Therefore, it is necessary to automatically convert user query requests into SQL statements to simplify and naturalize this process, thereby lowering the threshold for user and database interaction. Summary of the invention
[0003] The present disclosure aims to solve one of the technical problems in the related art at least to some extent.
[0004] To this end, the first objective of the present disclosure is to propose a query statement generation method to automatically convert a user's query request into an SQL statement to lower the threshold for interaction between the user and the database.
[0005] The second objective of the present disclosure is to provide a query statement generating device.
[0006] A third objective of the present disclosure is to provide an electronic device.
[0007] A fourth objective of the present disclosure is to provide a computer-readable storage medium.
[0008] A fifth object of the present disclosure is to provide a computer program product.
[0009] To achieve the above-mentioned purpose, the first embodiment of the present disclosure proposes a query statement generation method, including:
[0010] Acquire text query information, perform similarity matching between the text query information and a data table set to obtain a first data table subset that meets similarity requirements, and combine data tables in the first data table subset according to a keyword set corresponding to the text query information to obtain a data table combination set;
[0011] If there is a first data table combination in the data table combination set, determining the association coefficient corresponding to the first data table combination according to the graph database corresponding to the data table set, wherein the first data table combination is a data table combination having an association relationship in the graph database;
[0012] Selecting the first data table combination with the largest correlation coefficient as the second data table combination, initiating a confirmation instruction for the second data table combination, and obtaining a third data table combination that meets the user's needs according to reply information corresponding to the confirmation instruction;
[0013] A first structured query language query statement corresponding to the text query information is generated according to the association relationship of the third data table combination in the graph database.
[0014] Optionally, combining the data tables in the first data table subset according to the keyword set corresponding to the text query information to obtain a data table combination set includes:
[0015] Extracting keywords from the text query information to obtain a keyword set;
[0016] Determine a keyword corresponding to each data table in the first data table subset, and obtain a second data table subset corresponding to any keyword in the keyword set;
[0017] Any data table is selected from each of the second data table subsets for combination to obtain a data table combination set.
[0018] Optionally, the performing similarity matching between the text query information and a data table set to obtain a first data table subset that meets similarity requirements includes:
[0019] Obtain data table information of any data table in the data table set, wherein the data table information includes table name, field name, and field meaning explanation;
[0020] Generate table function content description information corresponding to any data table according to the data table information;
[0021] The text query information is matched with the table function content description information corresponding to each data table in the data table set to obtain a first data table subset that meets the similarity requirement.
[0022] Optionally, before determining the association coefficient corresponding to the first data table combination according to the graph database corresponding to the data table set, the method further includes:
[0023] Obtain the field name of each data table in the data table set and the operation information corresponding to the field name;
[0024] If there are the same field names between any two data tables in the data table set, it is determined that there is an association relationship between the any two data tables, and an initial graph database corresponding to the data table set is generated according to the association relationship, wherein the nodes in the initial graph database are the field names;
[0025] The edge weight is determined according to the operation information, and the edge weight is added to the edge corresponding to the field name in the initial graph database to obtain the graph database corresponding to the data table set.
[0026] Optionally, determining the correlation coefficient corresponding to the first data table combination according to the graph database corresponding to the data table set includes:
[0027] Determine an edge set corresponding to the first data table combination in the graph database;
[0028] The association coefficient corresponding to the first data table combination is determined according to the edge weight corresponding to each edge in the edge set.
[0029] Optionally, after obtaining the graph database corresponding to the data table set, the method further includes:
[0030] At every preset time period, the edge weight is updated according to the operation information and edge weight usage information within the preset time period, wherein the operation information includes field query frequency and field data update frequency.
[0031] Optionally, updating the edge weight according to the operation information and edge weight usage information within the preset time period includes:
[0032] Obtain historical weight retention factor, query frequency impact factor, data update frequency impact factor, and time decay factor;
[0033] Determine the historical weight retention coefficient corresponding to the edge weight according to the historical weight retention factor;
[0034] Determine the field query frequency coefficient corresponding to the edge weight according to the query frequency influencing factor and the field query frequency;
[0035] Determine the field data update frequency coefficient corresponding to the edge weight according to the data update frequency influencing factor and the field data update frequency;
[0036] Determine a time decay parameter corresponding to the edge weight according to the edge weight usage information, and determine a time decay coefficient corresponding to the edge weight according to the time decay factor and the time decay parameter;
[0037] The edge weight is updated according to the historical weight retention coefficient, the field query frequency coefficient, the field data update frequency coefficient and the time decay coefficient.
[0038] Optionally, after obtaining the data table combination set, the method further includes:
[0039] If the first data table combination does not exist in the data table combination set, a query modification instruction is issued, wherein the query modification instruction is used to instruct to modify the text query information.
[0040] Optionally, obtaining a third data table combination that meets user needs according to the reply information corresponding to the confirmation instruction includes:
[0041] If the reply information corresponding to the confirmation instruction is combination confirmation information, the second data table combination is used as a third data table combination that meets the user's needs;
[0042] If the reply information corresponding to the confirmation instruction is combination modification information, the fourth data table combination subset is displayed, and selection information input for the fourth data table combination subset is received, and the fourth data table combination corresponding to the selection information is used as the third data table combination, wherein the fourth data table combination is the first data table combination in the data table combination set except the second data table combination.
[0043] Optionally, after generating a first structured query language query statement corresponding to the text query information, the method further includes:
[0044] Query the data table set according to the first structured query language query statement to obtain a target data table;
[0045] Performing logic analysis on the text query information to obtain a logic analysis result;
[0046] A second structured query language query statement is generated according to the logic analysis result, the target data table and the query field name corresponding to the target data table, wherein the query field name is determined by the keyword.
[0047] To achieve the above-mentioned purpose, a second aspect of the present disclosure provides a query statement generating device, including:
[0048] an information matching unit, configured to obtain text query information, perform similarity matching between the text query information and a data table set to obtain a first data table subset that meets similarity requirements, and combine data tables in the first data table subset according to a keyword set corresponding to the text query information to obtain a data table combination set;
[0049] a coefficient determination unit, configured to determine, if there is a first data table combination in the data table combination set, a correlation coefficient corresponding to the first data table combination according to a graph database corresponding to the data table set, wherein the first data table combination is a data table combination having an association relationship in the graph database;
[0050] A combination confirmation unit, configured to select a first data table combination with a maximum correlation coefficient as a second data table combination, initiate a confirmation instruction for the second data table combination, and obtain a third data table combination that meets the user's needs according to reply information corresponding to the confirmation instruction;
[0051] A statement generating unit is used to generate a first structured query language query statement corresponding to the text query information according to the association relationship of the third data table combination in the graph database.
[0052] To achieve the above-mentioned purpose, a third aspect of the present disclosure provides an electronic device, including: a processor, and a memory communicatively connected to the processor;
[0053] Memory stores computer-executable instructions;
[0054] The processor executes the computer-executable instructions stored in the memory to implement the method shown in any one of the first aspects above.
[0055] To achieve the above-mentioned objectives, an embodiment of the fourth aspect of the present disclosure proposes a computer-readable storage medium, in which computer-executable instructions are stored. When the computer-executable instructions are executed by a processor, they are used to implement the method shown in any one of the above-mentioned first aspects.
[0056] To achieve the above-mentioned objective, a fifth aspect of the present disclosure provides a computer program product, including a computer program, which, when executed by a processor, implements the method shown in any one of the above-mentioned first aspects.
[0057] In summary, the method, apparatus, device, medium and program product provided by the present disclosure, first, by performing similarity matching, generating a data table combination set corresponding to a keyword set corresponding to text query information, screening out data table combinations with correlation relationships, calculating and selecting data table combinations with the largest correlation coefficients, can improve the accuracy of data table matching. Next, by increasing interaction with users, initiating inquiries to users, and allowing users to confirm data table combinations, it can be ensured that the matched data table combinations meet user needs, and the threshold for interaction between users and databases can be lowered. Finally, by generating a first structured query language query statement based on a graph database, the accuracy of SQL query statement generation can be improved.
[0058] Additional aspects and advantages of the present disclosure will be given in part in the following description and in part will be obvious from the following description or learned through practice of the present disclosure. BRIEF DESCRIPTION OF THE DRAWINGS
[0059] The above and / or additional aspects and advantages of the present disclosure will become apparent and easily understood from the following description of the embodiments in conjunction with the accompanying drawings, in which:
[0060] Figure 1 A flowchart of a query statement generation method provided by an embodiment of the present disclosure;
[0061] Figure 2 A schematic diagram of a query result of a graph database provided in an embodiment of the present disclosure;
[0062] Figure 3 A schematic diagram of the structure of a query statement generating device provided in an embodiment of the present disclosure. DETAILED DESCRIPTION
[0063] Embodiments of the present disclosure are described in detail below, and examples of the embodiments are shown in the accompanying drawings, wherein the same or similar reference numerals throughout represent the same or similar elements or elements having the same or similar functions. The embodiments described below with reference to the accompanying drawings are exemplary and are intended to be used to explain the present disclosure, and should not be construed as limiting the present disclosure.
[0064] It should be noted that, in the related technology, although there are some tools and systems that can convert simple natural language into SQL query statements, most of them adopt the following three ideas for conversion:
[0065] The first method is to train a single table. However, the queries generated can only query the specified table, and querying a single table does not meet most business needs.
[0066] The second method is to match the field names, field notes and other information of each table through word vectors, and input the matched information as context to the big model to generate query statements. However, by directly throwing the matched table names, field names and other information to the big model, the graph database is not used to limit the relationship between query tables, resulting in the generated SQL query statements being unexecutable. In addition, when multiple tables have similar fields, directly relying on table descriptions or field matching tables will be inaccurate.
[0067] The third method is to regroup the related tables into one table, so that only a single-table query statement is needed to meet the demand, without the need to implement multi-table joint query. However, in reality, it is not allowed to store the related tables again as one large table.
[0068] In other words, the related technology cannot intelligently select the most appropriate database table, consider the relationship between tables to generate optimized query statements, and lacks interaction with users.
[0069] The present disclosure is described in detail below with reference to specific embodiments.
[0070] In the first embodiment, if Figure 1 As shown, Figure 1This is a flow chart of a method for generating a query statement provided by an embodiment of the present disclosure, which can be implemented by a computer program and can be run on a device for generating a query statement. The computer program can be integrated into an application or run as an independent tool application.
[0071] Among them, the query statement generation method can be applied to technical fields such as natural language processing, database management, graph database, and query language generation.
[0072] The query statement generating device may be an electronic device having a query statement generating function.
[0073] The query statement generating method may be executed by an electronic device.
[0074] For example, the query statement generation method includes the following steps:
[0075] S101, obtaining text query information, performing similarity matching between the text query information and a data table set, obtaining a first data table subset that meets similarity requirements, and combining data tables in the first data table subset according to a keyword set corresponding to the text query information, obtaining a data table combination set;
[0076] According to some embodiments, the text query information refers to relevant query information input by a user when querying and operating a database. The text query information adopts a natural language, which needs to be converted into an SQL query statement.
[0077] In some embodiments, a data table set refers to a set of data tables in a database used by a user to perform a query or operation.
[0078] According to some embodiments, the similarity requirement refers to a requirement adopted by the electronic device when screening the first data table subset from the data table set.
[0079] In some embodiments, the keyword set refers to a set formed by gathering keywords in text query information.
[0080] According to some embodiments, the data table combination set includes at least one data table combination, and each data table combination includes at least one data table in the first data table subset.
[0081] S102, if there is a first data table combination in the data table combination set, determining a correlation coefficient corresponding to the first data table combination according to a graph database corresponding to the data table set;
[0082] According to some embodiments, the first data table combination is a data table combination having an association relationship in a graph database.
[0083] In some embodiments, the graph database is a data management system that uses nodes and edges as basic storage units and is designed with the principle of efficient storage and query of graph data.
[0084] According to some embodiments, the association coefficient is determined by the degree of association between the data tables in the first data table combination. The degree of association may be determined by the association relationship between the data tables in the graph database.
[0085] S103, selecting the first data table combination with the largest correlation coefficient as the second data table combination, initiating a confirmation instruction for the second data table combination, and obtaining a third data table combination that meets the user's needs according to reply information corresponding to the confirmation instruction;
[0086] According to some embodiments, the confirmation instruction is used to instruct to confirm the second data table combination.
[0087] In some embodiments, the reply information refers to the relevant information input by the user in response to the confirmation instruction. The reply information may be, for example, a combination of confirmation information or a combination of modification information.
[0088] According to some embodiments, the third data table combination refers to the data table combination indicated by the reply information, that is, the data table combination that meets the user's needs.
[0089] S104: Generate a first structured query language query statement corresponding to the text query information according to the association relationship of the third data table combination in the graph database.
[0090] According to some embodiments, the first structured query language query statement refers to an SQL query statement for fetching data from a joint table generated based on a combination of the graph database and the third data table.
[0091] In summary, the method provided in this embodiment, first, generates a data table combination set corresponding to the keyword set corresponding to the text query information by performing similarity matching, screens out data table combinations with correlation relationships, calculates and selects the data table combination with the largest correlation coefficient, which can reduce the situation where the keywords corresponding to multiple data tables are the same, and the direct reliance on table descriptions or field matching tables will be inaccurate, and can improve the accuracy of data table matching. Then, by increasing the interaction with the user, inquiries are made to the user, and the user is asked to confirm the data table combination, it can be ensured that the matched data table combination meets the user's needs, and the threshold for user and database interaction can be lowered. Finally, by generating a first structured query language query statement based on the graph database, the accuracy of SQL query statement generation can be improved.
[0092] This embodiment also provides another query statement generation method, which can be executed by an electronic device.
[0093] For example, the query statement generation method may include the following steps:
[0094] S201, obtaining text query information, performing similarity matching between the text query information and table function content description information corresponding to each data table in the data table set, and obtaining a first data table subset that meets the similarity requirement;
[0095] According to some embodiments, the similarity requirement may be, for example, that the similarity between the text query information and the data table is greater than a first similarity threshold. The first similarity threshold does not specifically refer to a fixed threshold. The first similarity threshold may be adjusted according to an actual application scenario.
[0096] In some embodiments, the table function content description information refers to text information used to describe the table function content.
[0097] In some embodiments, when similarity matching is performed between text query information and table function content description information corresponding to each data table in the data table set, the matching method used includes but is not limited to text2vec vector calculation, cosine similarity, and the like.
[0098] Taking a scenario as an example, when the text query information input by the user is obtained as "Please check what are the most purchased products by female users?", Table A "User Information Table" containing the user's name, gender, and user identity (identity, id), Table B "Purchase Flow Table" containing the user's user id, purchased products, and purchase time, and Table C "Return Flow Table" containing the user's user id, purchased products, and return reasons can be matched in the data table collection.
[0099] According to some embodiments, before similarity matching is performed between the text query information and the table function content description information corresponding to each data table in the data table set, the data table information of any data table in the data table set can be obtained, wherein the data table information includes the table name, field name, and field meaning explanation; and the table function content description information corresponding to any data table can be generated according to the data table information. Therefore, the accuracy of generating the table function content description information can be improved.
[0100] In some embodiments, after obtaining the table function content description information corresponding to any data table, the table function content description information can be stored in a document vector library, which can facilitate similarity matching between text query information and the table function content description information.
[0101] In some embodiments, table names, field names, and field meaning explanations may be obtained through an interface of a database management system.
[0102] According to some embodiments, a large language model (LLM) may be used to generate table action content description information corresponding to a data table. LLM refers to a large-scale language model built based on deep learning technology. LLM is a powerful natural language processing tool that can understand and generate text. Therefore, the convenience of generating table action content description information can be improved.
[0103] For example, first, the following information can be entered into the large model:
[0104] "I have an {employee information} table, which includes the following fields:
[0105] {ID}, described as {employee's ID},
[0106] {Name}, described as {employee's name},
[0107] {DEP}, described as {employee's department}
[0108] Please generate a text describing this table based on the above information"
[0109] Then, the big model can generate an answer based on the above information: "The employee information table contains information about employee ID, employee name, and employee department, and is used to record the basic information of the company's employees."
[0110] In some embodiments, a sample set in the same data format as the above information can be used to fine-tune the large model, thereby improving the accuracy of generating the table function content description information.
[0111] It should be noted that, during the subsequent use of the database, each time a new data table is connected, the table name, field name, and field meaning explanation of the new data table can be obtained through the interface of the database management system, and the corresponding table function content description information can be generated through the large model, and the table function content description information is stored in the document vector library.
[0112] S202, extracting keywords from the text query information to obtain a keyword set;
[0113] According to some embodiments, methods of keyword extraction include but are not limited to large model extraction, text keyword extraction model extraction, etc.
[0114] Taking a scenario as an example, by performing keyword extraction on the text query information of "Please check what products are purchased most by female users?", two keywords "female users" and "purchase products" can be obtained.
[0115] S203, determining a keyword corresponding to each data table in the first data table subset, and obtaining a second data table subset corresponding to any keyword in the keyword set;
[0116] According to some embodiments, a semantic model may be used to perform similarity matching, thereby obtaining keywords matched to each data table in the first data table subset.
[0117] In some embodiments, the semantic model refers to a new type of data model that adds new data constructors and data processing primitives based on the relational model to express complex structures and rich semantics. The semantic model can be, for example, a Bidirectional Encoder Representation from Transformers (BERT) model.
[0118] S204, selecting any data table from each second data table subset for combination to obtain a data table combination set;
[0119] Taking a scenario as an example, after determining that the gender in Table A corresponds to the keyword "female user", and the purchased products in Tables B and C correspond to the keyword "purchased products", it can be obtained that the second data table subset corresponding to the keyword "female user" includes Table A, and the second data table subset corresponding to the keyword "purchased products" includes Table B and Table C, so that the data table combinations: AB, AC can be obtained.
[0120] S205, if the first data table combination does not exist in the data table combination set, issuing a query modification instruction;
[0121] According to some embodiments, the first data table combination is a data table combination that has an associated relationship in the graph database. If the first data table combination does not exist in the data table combination set, it means that the SQL query statement generated according to the data table combination set is not executable, so the text query information needs to be adjusted.
[0122] In some embodiments, the query modification instruction is used to instruct modification of text query information.
[0123] S206, if the first data table combination exists in the data table combination set, determine the edge set corresponding to the first data table combination in the graph database, and determine the association coefficient corresponding to the first data table combination according to the edge weight corresponding to each edge in the edge set;
[0124] According to some embodiments, the field name of each data table in the data table set and the operation information corresponding to the field name can be obtained; if the same field name exists between any two data tables in the data table set, it is determined that there is an association relationship between any two data tables, and an initial graph database corresponding to the data table set is generated based on the association relationship; the edge weight is determined based on the operation information, and the edge weight is added to the edge corresponding to the field name in the initial graph database to obtain the graph database corresponding to the data table set. Therefore, by modeling the field association relationship through the graph database, the association relationship between the fields can be found more quickly, the field data involved in the query can be retrieved in advance, and data support can be provided for generating more accurate SQL query statements. In addition, the weight relationship is established using the graph database to calculate and select the data table combination with the highest weight, which can improve the efficiency and accuracy of the data table combination selection.
[0125] In some embodiments, the key value in the data table field can be obtained. If the key value is the same between two data tables, the field name corresponding to the key value is regarded as the same field name. In this case, the node in the initial graph database is the field name, and the edge in the initial graph database can record the associated key value between the two nodes.
[0126] In some embodiments, the operation information refers to relevant information when operating a data table, including but not limited to field query frequency, field data update frequency, etc.
[0127] In some embodiments, when adding edge weights to the edges corresponding to the field names in the initial graph database, the edges can be dynamic weight edges set between nodes. In this case, the graph database has two types of edges, one is an edge that records the associated key value between two nodes, and the other is a dynamic weight edge. Dynamic weight edges can be added to the two data tables when the field names in the two data tables are queried at the same time or the two data tables are updated at the same time (except for the tables with scheduled data storage).
[0128] Take a scenario as an example. Figure 2 This is a schematic diagram of the structure of an initial graph database provided by an embodiment of the present disclosure. Figure 2 As shown, both Table A "User Information Table" and Table B "Purchase Flow Table" include the same field name "User ID", which means that Table A and Table B can be associated through "User ID".
[0129] It should be noted that during the subsequent use of the database, each time a new data table is connected, the graph database can be updated according to the new data table. When a change in the table structure of any data table is detected, the edge association information can be automatically updated.
[0130] According to some embodiments, after obtaining the graph database corresponding to the data table set, the edge weights can be updated at preset intervals according to the operation information and edge weight usage information within the preset interval. Therefore, in the subsequent use of the database, query statements can be generated according to the updated edge weights, which can improve the accuracy of query statement generation.
[0131] In some embodiments, edge weight usage information refers to relevant information generated when edge weights are used.
[0132] According to some embodiments, the historical weight retention factor, the query frequency influencing factor, the data update frequency influencing factor, and the time decay factor can be obtained; according to the historical weight retention factor, the historical weight retention coefficient corresponding to the edge weight is determined; according to the query frequency influencing factor and the field query frequency, the field query frequency coefficient corresponding to the edge weight is determined; according to the data update frequency influencing factor and the field data update frequency, the field data update frequency coefficient corresponding to the edge weight is determined; according to the edge weight usage information, the time decay parameter corresponding to the edge weight is determined, and according to the time decay factor and the time decay parameter, the time decay coefficient corresponding to the edge weight is determined; the edge weight is updated according to the historical weight retention coefficient, the field query frequency coefficient, the field data update frequency coefficient, and the time decay coefficient. Therefore, by establishing a dynamic weight relationship, introducing the field query frequency, the field data update frequency, and the time decay factor, the intelligent adjustment of the edge weight can be achieved.
[0133] In some embodiments, edge weights may be updated according to the following formula:
[0134] W(t+1)=α*W(t)+β*F(t)+δ*T(t)-ε*D(t)
[0135] Where t is time, W(t+1) is the edge weight after update, W(t) is the edge weight before update, α is the historical weight retention factor, α*W(t) is the historical weight retention coefficient, β is the query frequency influence factor, F(t) is the query frequency function used to calculate the field query frequency, β*F(t) is the field query frequency coefficient, δ is the data update frequency influence factor, T(t) is the data update frequency function used to calculate the field data update frequency, δ*T(t) is the field data update frequency coefficient, ε is the time decay factor, D(t) is the time decay function used to calculate the time decay parameter, and ε*D(t) is the time decay coefficient.
[0136] In some embodiments, for field query frequency, field names that frequently appear together in queries can have their corresponding edge weights increased. That is, the field query frequency within a preset time length can be calculated using a normalized function, for example, F(t) = the number of times two data tables are queried together / the total number of times data tables in the database are queried within a preset time length.
[0137] In some embodiments, with respect to the frequency of field data updates, data tables corresponding to field names that are frequently updated simultaneously may have a stronger logical association. That is, the data update frequency function used to calculate the frequency of field data updates within a preset time period may be, for example, T(t) = log(number of simultaneous updates + 1).
[0138] In some embodiments, for time decay, the weight of edges that have not been used for a long time can be gradually reduced. The degree of reduction can be determined according to the weight update time and can be set to a constant, that is, the corresponding relationship between the weight update time and the time decay parameter can be calibrated and the required time decay parameter can be found in the corresponding relationship.
[0139] S207, selecting the first data table combination with the largest correlation coefficient as the second data table combination, initiating a confirmation instruction for the second data table combination, and obtaining a third data table combination that meets the user's needs according to reply information corresponding to the confirmation instruction;
[0140] According to some embodiments, when the third data table combination that meets the user's needs is obtained according to the reply information corresponding to the confirmation instruction, if the reply information corresponding to the confirmation instruction is combination confirmation information, the second data table combination can be used as the third data table combination that meets the user's needs; if the reply information corresponding to the confirmation instruction is combination modification information, a fourth data table combination subset can be displayed, and selection information input for the fourth data table combination subset can be received, and the fourth data table combination corresponding to the selection information can be used as the third data table combination, wherein the fourth data table combination is the first data table combination in the data table combination set except the second data table combination. Therefore, by initiating a query to the user and asking the user to confirm or modify, it can be ensured that the matched query field meets the user's needs.
[0141] In some embodiments, the reply information corresponding to the confirmation instruction may also be field modification information, modification information for text query information, etc. The field modification information may be, for example, deleting relevant fields in the second data table combination, adding relevant fields in the second data table combination, etc. If the reply information is modification information for text query information, the text query information may be modified, and S201 to S207 may be re-executed.
[0142] Take a scenario as an example. Figure 2The data table combination shown is the first data table combination with the largest correlation coefficient. In this case, a confirmation instruction for the second data table combination can be initiated to inform the user that the gender in Table A "User Information Table" and the purchased products in Table B "Purchase Flow Table" will be taken for the user to choose to modify or accept. When choosing to modify, other combinations of related edges will be given, for example, the gender in Table A "User Information Table" and the purchased products in Table C "Return Flow Table".
[0143] S208, generating a first structured query language query statement corresponding to the text query information according to the association relationship of the third data table combination in the graph database;
[0144] Take a scenario as an example. Figure 2 The data table combination shown is the data table combination that has been confirmed by the user to meet the user's needs. Figure 2 By looking at the relationship between the fields in Table A, you will find that Table A "User Information Table" and Table B "Purchase Flow Table" are connected through the "User ID" field, and you can generate the following first structured query language query statement:
[0145] SELECT user information table.gender as gender, purchase flow table.product as product
[0146] FROM user information table
[0147] JOIN purchase flow table ON user information table.user id = purchase flow table.user id.
[0148] S209, querying the data table set according to the first structured query language query statement to obtain a target data table;
[0149] According to some embodiments, the target data table refers to a data table obtained after querying the data table set according to the first structured query language query statement.
[0150] For example, the data selected in the data table collection by "SELECT user information table.gender as gender, purchase flow table.product as product" is Figure 2 The target data table is obtained after the first structured query language query statement corresponding to the data table combination is queried in the data table set.
[0151] S210, performing logic analysis on the text query information to obtain a logic analysis result, and generating a second structured query language query statement according to the logic analysis result, the target data table, and the query field name corresponding to the target data table.
[0152] According to some embodiments, the query field name is determined by a keyword. For example, the gender in Table A "User Information Table" corresponds to the keyword "female user", and the purchased products in Table B "Purchase Flow Table" correspond to the keyword "purchased products", then the gender in Table A "User Information Table" and the purchased products in Table B "Purchase Flow Table" can be used as the query field name.
[0153] In some embodiments, a large model for generating single-table query information according to input may be used to perform logical analysis on the text query information to generate a second structured query language query statement.
[0154] For example, you can input into the big model: "Assuming that table D already has fields {gender}, {product} information, what SQL query statement should be used to implement the question {Please query what products are most purchased by female users?}" and then you can get the output of the big model:
[0155] SELECT product, COUNT(*)AS number of purchases
[0156] FROM table D
[0157] WHERE Gender = 'Female'
[0158] GROUP BY product
[0159] ORDER BY number of purchases DESC
[0160] LIMIT 1;
[0161] Afterwards, replace the entire table D with the data selected in the data table set by "SELECT user information table.gender as gender, purchase flow table.product as product" in step S209.
[0162] In some embodiments, after obtaining the second structured query language query statement, the second structured query language query statement can be used to replace the first structured query language query statement to query the data table. Since this is equivalent to a query statement generated only for information in one table, the accuracy of the query result of the query statement can be improved.
[0163] In summary, the method provided in this embodiment firstly obtains text query information, performs similarity matching between the text query information and the table function content description information corresponding to each data table in the data table set, and obtains a first data table subset that meets the similarity requirement; therefore, the accuracy and efficiency of similarity matching can be improved. Next, keywords are extracted from the text query information to obtain a keyword set; the keywords corresponding to each data table in the first data table subset are determined to obtain a second data table subset corresponding to any keyword in the keyword set; any data table is selected from each second data table subset for combination to obtain a data table combination set; therefore, a data table combination corresponding to the text query information can be generated. Then, if the first data table combination does not exist in the data table combination set, a query modification instruction is issued; if the first data table combination exists in the data table combination set, the edge set corresponding to the first data table combination in the graph database is determined, and the correlation coefficient corresponding to the first data table combination is determined according to the edge weight corresponding to each edge in the edge set, and the first data table combination with the largest correlation coefficient is selected as the second data table combination; therefore, the combination with the correlation relationship can be screened, and the combination with the largest correlation coefficient can be calculated and selected, which can reduce the situation where the keywords corresponding to multiple data tables are the same, and the situation where the table description or field matching table is directly inaccurate can be reduced, and the accuracy of data table matching can be improved. Then, by initiating a confirmation instruction for the second data table combination, the third data table combination that meets the user's needs is obtained according to the reply information corresponding to the confirmation instruction; therefore, the interaction with the user can be increased, and inquiries can be initiated to the user to allow the user to confirm the data table combination, which can ensure that the matched data table combination meets the user's needs. Finally, a first structured query language query statement corresponding to the text query information is generated according to the association relationship of the third data table combination in the graph database; a query is performed in the data table set according to the first structured query language query statement to obtain a target data table; a logical analysis is performed on the text query information to obtain a logical analysis result, and a second structured query language query statement is generated according to the logical analysis result, the target data table, and the query field name corresponding to the target data table; therefore, an SQL statement for a single table can be generated, which can improve the accuracy of SQL statement generation.
[0164] In order to implement the above embodiment, the present disclosure also proposes a query statement generating device.
[0165] like Figure 3 As shown, the query statement generating device 300 includes:
[0166] The information matching unit 301 is used to obtain text query information, perform similarity matching between the text query information and a data table set to obtain a first data table subset that meets the similarity requirement, and combine data tables in the first data table subset according to a keyword set corresponding to the text query information to obtain a data table combination set;
[0167] A coefficient determination unit 302 is used to determine the correlation coefficient corresponding to the first data table combination according to the graph database corresponding to the data table set if there is a first data table combination in the data table combination set, wherein the first data table combination is a data table combination having an association relationship in the graph database;
[0168] The combination confirmation unit 303 is used to select the first data table combination with the largest correlation coefficient as the second data table combination, initiate a confirmation instruction for the second data table combination, and obtain a third data table combination that meets the user's needs according to the reply information corresponding to the confirmation instruction;
[0169] The statement generating unit 304 is used to generate a first structured query language query statement corresponding to the text query information according to the association relationship of the third data table combination in the graph database.
[0170] Optionally, the information matching unit 301 is used to combine the data tables in the first data table subset according to the keyword set corresponding to the text query information to obtain the data table combination set, specifically for:
[0171] Extract keywords from the text query information to obtain a keyword set;
[0172] Determine a keyword corresponding to each data table in the first data table subset, and obtain a second data table subset corresponding to any keyword in the keyword set;
[0173] Any data table is selected from each second data table subset for combination to obtain a data table combination set.
[0174] Optionally, the information matching unit 301 is used to perform similarity matching between the text query information and the data table set, and when obtaining a first data table subset that meets the similarity requirement, specifically to:
[0175] Get the data table information of any data table in the data table set, where the data table information includes table name, field name, and field meaning explanation;
[0176] Generate table function content description information corresponding to any data table according to the data table information;
[0177] The text query information is matched with the table function content description information corresponding to each data table in the data table set to obtain a first data table subset that meets the similarity requirement.
[0178] Optionally, before determining the association coefficient corresponding to the first data table combination according to the graph database corresponding to the data table set, the coefficient determination unit 302 is further used to:
[0179] Get the field name of each data table in the data table collection and the operation information corresponding to the field name;
[0180] If there are the same field names between any two data tables in the data table set, it is determined that there is an association relationship between any two data tables, and an initial graph database corresponding to the data table set is generated according to the association relationship, wherein the nodes in the initial graph database are field names;
[0181] Determine the edge weights based on the operation information, and add edge weights to the edges corresponding to the field names in the initial graph database to obtain a graph database corresponding to the data table set.
[0182] Optionally, when the coefficient determination unit 302 is used to determine the correlation coefficient corresponding to the first data table combination according to the graph database corresponding to the data table set, it is specifically used to:
[0183] Determine an edge set corresponding to a first data table combination in a graph database;
[0184] According to the edge weight corresponding to each edge in the edge set, the association coefficient corresponding to the first data table combination is determined.
[0185] Optionally, after obtaining the graph database corresponding to the data table set, the coefficient determination unit 302 is further used to:
[0186] At every preset time, the edge weight is updated according to the operation information and edge weight usage information within the preset time, wherein the operation information includes the field query frequency and the field data update frequency.
[0187] Optionally, when the coefficient determination unit 302 is used to update the edge weight according to the operation information within a preset time period and the edge weight usage information, it is specifically used to:
[0188] Obtain historical weight retention factor, query frequency impact factor, data update frequency impact factor, and time decay factor;
[0189] According to the historical weight retention factor, determine the historical weight retention coefficient corresponding to the edge weight;
[0190] According to the query frequency influencing factor and the field query frequency, determine the field query frequency coefficient corresponding to the edge weight;
[0191] According to the data update frequency influencing factor and the field data update frequency, determine the field data update frequency coefficient corresponding to the edge weight;
[0192] Determine a time decay parameter corresponding to the edge weight according to the edge weight usage information, and determine a time decay coefficient corresponding to the edge weight according to the time decay factor and the time decay parameter;
[0193] The edge weight is updated according to the historical weight retention coefficient, the field query frequency coefficient, the field data update frequency coefficient and the time decay coefficient.
[0194] Optionally, after obtaining the data table combination set, the coefficient determination unit 302 is further used to:
[0195] If the first data table combination does not exist in the data table combination set, a query modification instruction is issued, wherein the query modification instruction is used to instruct to modify the text query information.
[0196] Optionally, when the combination confirmation unit 303 is used to obtain the third data table combination that meets the user's needs according to the reply information corresponding to the confirmation instruction, it is specifically used to:
[0197] If the reply information corresponding to the confirmation instruction is combination confirmation information, the second data table combination is used as the third data table combination that meets the user's needs;
[0198] If the reply information corresponding to the confirmation instruction is combination modification information, the fourth data table combination subset is displayed, and the selection information input for the fourth data table combination subset is received, and the fourth data table combination corresponding to the selection information is used as the third data table combination, wherein the fourth data table combination is the first data table combination in the data table combination set except the second data table combination.
[0199] Optionally, after generating the first structured query language query statement corresponding to the text query information, the statement generating unit 304 is further configured to:
[0200] Querying the data table set according to the first structured query language query statement to obtain a target data table;
[0201] Performing logical analysis on text query information to obtain logical analysis results;
[0202] A second structured query language query statement is generated according to the logic analysis result, the target data table and the query field name corresponding to the target data table, wherein the query field name is determined by a keyword.
[0203] It should be noted that the above explanation of the query statement generating method embodiment is also applicable to the query statement generating device of this embodiment, and will not be repeated here.
[0204] In summary, the device provided by the embodiment of the present disclosure, first, generates a data table combination set corresponding to the keyword set corresponding to the text query information by performing similarity matching, screens out data table combinations with correlation relationships, calculates and selects the data table combination with the largest correlation coefficient, which can reduce the situation where the keywords corresponding to multiple data tables are the same, and the direct reliance on table descriptions or field matching tables will be inaccurate, and can improve the accuracy of data table matching. Next, by increasing the interaction with the user, initiating inquiries to the user, and allowing the user to confirm the data table combination, it can ensure that the matched data table combination meets the user's needs, and can lower the threshold for user and database interaction. Finally, by generating a first structured query language query statement based on the graph database, the accuracy of SQL query statement generation can be improved.
[0205] In order to implement the above embodiments, the present disclosure also proposes an electronic device, including: a processor, and a memory communicatively connected to the processor; the memory stores computer-executable instructions; the processor executes the computer-executable instructions stored in the memory to implement the method provided by the above embodiments.
[0206] In order to implement the above embodiments, the present disclosure further proposes a computer-readable storage medium, in which computer-executable instructions are stored. When the computer-executable instructions are executed by a processor, they are used to implement the methods provided by the above embodiments.
[0207] In order to implement the above embodiments, the present disclosure also proposes a computer program product, including a computer program, which implements the methods provided by the above embodiments when executed by a processor.
[0208] The collection, storage, use, processing, transmission, provision and disclosure of user personal information involved in this disclosure shall comply with the relevant laws and regulations and shall not violate public order and good morals.
[0209] It should be noted that personal information from users should be collected for legitimate and reasonable purposes and should not be shared or sold outside of these legitimate uses. In addition, such collection / sharing should be carried out after receiving the user's informed consent, including but not limited to notifying the user to read the user agreement / user notice and sign the agreement / authorization including authorization of relevant user information before the user uses the function. In addition, any necessary steps should be taken to protect and safeguard access to such personal information data and ensure that others who have access to personal information data comply with its privacy policy and procedures.
[0210] The present disclosure anticipates providing implementation schemes for users to selectively block the use or access of personal information data. That is, the present disclosure anticipates providing hardware and / or software to prevent or block access to such personal information data. Once the personal information data is no longer needed, risks can be minimized by limiting data collection and deleting the data. In addition, when applicable, such personal information is de-identified to protect the privacy of the user.
[0211] The acquisition, transmission, storage, use, and processing of data in the technical solution disclosed in this disclosure are in compliance with the relevant provisions of national laws and regulations.
[0212] It should be noted that in the embodiments of the present disclosure, certain software, components, models and other existing solutions in the industry may be mentioned, which should be regarded as exemplary. Their purpose is only to illustrate the feasibility of implementing the technical solution of the present application, but it does not mean that the applicant has or will necessarily use the solution.
[0213] In the description of the aforementioned embodiments, the description with reference to the terms "one embodiment", "some embodiments", "example", "specific example", or "some examples" etc. means that the specific features, structures, materials or characteristics described in conjunction with the embodiment or example are included in at least one embodiment or example of the present disclosure. In this specification, the schematic representations of the above terms do not necessarily refer to the same embodiment or example. Moreover, the specific features, structures, materials or characteristics described may be combined in any one or more embodiments or examples in a suitable manner. In addition, those skilled in the art may combine and combine the different embodiments or examples described in this specification and the features of the different embodiments or examples, unless they are contradictory.
[0214] In addition, the terms "first" and "second" are used for descriptive purposes only and should not be understood as indicating or implying relative importance or implicitly indicating the number of the indicated technical features. Thus, a feature defined as "first" or "second" may explicitly or implicitly include at least one of the features. In the description of the present disclosure, "plurality" means at least two, such as two, three, etc., unless otherwise clearly and specifically defined.
[0215] Any process or method description in a flowchart or otherwise described herein may be understood to represent a module, segment or portion of code that includes one or more executable instructions for implementing the steps of a custom logical function or process, and the scope of the preferred embodiments of the present disclosure includes additional implementations in which functions may not be performed in the order shown or discussed, including performing functions in a substantially simultaneous manner or in reverse order depending on the functions involved, which should be understood by technicians in the technical field to which the embodiments of the present disclosure belong.
[0216] The logic and / or steps represented in the flowchart or otherwise described herein, for example, can be considered as an ordered list of executable instructions for implementing logical functions, and can be embodied in any computer-readable medium for use by an instruction execution system, device or apparatus (such as a computer-based system, a system including a processor, or other system that can fetch instructions from an instruction execution system, device or apparatus and execute the instructions), or in combination with these instruction execution systems, devices or apparatuses. For the purpose of this specification, "computer-readable medium" can be any device that can contain, store, communicate, propagate or transmit a program for use by an instruction execution system, device or apparatus, or in combination with these instruction execution systems, devices or apparatuses. More specific examples of computer-readable media (a non-exhaustive list) include the following: an electrical connection with one or more wires (electronic device), a portable computer disk box (magnetic device), a random access memory (RAM), a read-only memory (ROM), an erasable and programmable read-only memory (EPROM or flash memory), a fiber optic device, and a portable compact disk read-only memory (CDROM). In addition, the computer-readable medium may even be paper or other suitable medium on which the program is printed, since the program may be obtained electronically, for example, by optically scanning the paper or other medium and then editing, interpreting or otherwise processing in a suitable manner if necessary, and then stored in a computer memory.
[0217] It should be understood that the various parts of the present disclosure can be implemented in hardware, software, firmware or a combination thereof. In the above-mentioned embodiments, multiple steps or methods can be implemented in software or firmware stored in a memory and executed by a suitable instruction execution system. For example, if implemented in hardware, as in another embodiment, any one of the following technologies known in the art or a combination thereof can be used to implement: a discrete logic circuit having a logic gate circuit for implementing a logic function for a data signal, a dedicated integrated circuit having a suitable combination of logic gate circuits, a programmable gate array (PGA), a field programmable gate array (FPGA), etc.
[0218] A person skilled in the art may understand that all or part of the steps in the above-mentioned embodiment method may be completed by instructing related hardware through a program, and the program may be stored in a computer-readable storage medium, which, when executed, includes one or a combination of the steps of the method embodiment.
[0219] In addition, each functional unit in each embodiment of the present disclosure may be integrated into a processing module, or each unit may exist physically separately, or two or more units may be integrated into one module. The above-mentioned integrated module may be implemented in the form of hardware or in the form of a software functional module. If the integrated module is implemented in the form of a software functional module and sold or used as an independent product, it may also be stored in a computer-readable storage medium.
[0220] The storage medium mentioned above may be a read-only memory, a disk or an optical disk, etc. Although the embodiments of the present disclosure have been shown and described above, it can be understood that the above embodiments are exemplary and cannot be understood as limitations of the present disclosure. A person of ordinary skill in the art may change, modify, replace and modify the above embodiments within the scope of the present disclosure.
Claims
1. A query statement generation method, characterized in that: include: Acquire text query information, perform similarity matching between the text query information and a data table set to obtain a first data table subset that meets similarity requirements, and combine data tables in the first data table subset according to a keyword set corresponding to the text query information to obtain a data table combination set; If there is a first data table combination in the data table combination set, determining the association coefficient corresponding to the first data table combination according to the graph database corresponding to the data table set, wherein the first data table combination is a data table combination having an association relationship in the graph database; Selecting the first data table combination with the largest correlation coefficient as the second data table combination, initiating a confirmation instruction for the second data table combination, and obtaining a third data table combination that meets the user's needs according to reply information corresponding to the confirmation instruction; A first structured query language query statement corresponding to the text query information is generated according to the association relationship of the third data table combination in the graph database.
2. The method according to claim 1, characterized in that The combining of the data tables in the first data table subset according to the keyword set corresponding to the text query information to obtain a data table combination set includes: Extracting keywords from the text query information to obtain a keyword set; Determine a keyword corresponding to each data table in the first data table subset, and obtain a second data table subset corresponding to any keyword in the keyword set; Any data table is selected from each of the second data table subsets for combination to obtain a data table combination set.
3. The method according to claim 1, characterized in that The similarity matching of the text query information with the data table set to obtain a first data table subset that meets the similarity requirement includes: Obtain data table information of any data table in the data table set, wherein the data table information includes table name, field name, and field meaning explanation; Generate table function content description information corresponding to any data table according to the data table information; The text query information is matched with the table function content description information corresponding to each data table in the data table set to obtain a first data table subset that meets the similarity requirement.
4. The method according to claim 1, characterized in that: Before determining the association coefficient corresponding to the first data table combination according to the graph database corresponding to the data table set, the method further includes: Obtain the field name of each data table in the data table set and the operation information corresponding to the field name; If there are the same field names between any two data tables in the data table set, it is determined that there is an association relationship between the any two data tables, and an initial graph database corresponding to the data table set is generated according to the association relationship, wherein the nodes in the initial graph database are the field names; The edge weight is determined according to the operation information, and the edge weight is added to the edge corresponding to the field name in the initial graph database to obtain the graph database corresponding to the data table set.
5. The method according to claim 4, characterized in that The determining the correlation coefficient corresponding to the first data table combination according to the graph database corresponding to the data table set includes: Determine an edge set corresponding to the first data table combination in the graph database; Determine the association coefficient corresponding to the first data table combination according to the edge weight corresponding to each edge in the edge set.
6. The method according to claim 4, characterized in that After obtaining the graph database corresponding to the data table set, the method further includes: At every preset time period, the edge weight is updated according to the operation information and edge weight usage information within the preset time period, wherein the operation information includes field query frequency and field data update frequency.
7. The method according to claim 6, characterized in that The updating of the edge weight according to the operation information and edge weight usage information within the preset time period includes: Obtain historical weight retention factor, query frequency impact factor, data update frequency impact factor, and time decay factor; Determine the historical weight retention coefficient corresponding to the edge weight according to the historical weight retention factor; Determining a field query frequency coefficient corresponding to the edge weight according to the query frequency influencing factor and the field query frequency; Determine the field data update frequency coefficient corresponding to the edge weight according to the data update frequency influencing factor and the field data update frequency; Determine a time decay parameter corresponding to the edge weight according to the edge weight usage information, and determine a time decay coefficient corresponding to the edge weight according to the time decay factor and the time decay parameter; The edge weight is updated according to the historical weight retention coefficient, the field query frequency coefficient, the field data update frequency coefficient and the time decay coefficient.
8. The method according to claim 1, characterized in that After obtaining the data table combination set, the method further includes: If the first data table combination does not exist in the data table combination set, a query modification instruction is issued, wherein the query modification instruction is used to instruct to modify the text query information.
9. The method according to claim 1, characterized in that: The third data table combination that meets the user's needs is obtained according to the reply information corresponding to the confirmation instruction, including: If the reply information corresponding to the confirmation instruction is combination confirmation information, the second data table combination is used as a third data table combination that meets the user's needs; If the reply information corresponding to the confirmation instruction is combination modification information, the fourth data table combination subset is displayed, and selection information input for the fourth data table combination subset is received, and the fourth data table combination corresponding to the selection information is used as the third data table combination, wherein the fourth data table combination is the first data table combination in the data table combination set except the second data table combination.
10. The method according to claim 1, characterized in that After generating the first structured query language query statement corresponding to the text query information, the method further includes: Query the data table set according to the first structured query language query statement to obtain a target data table; Performing logic analysis on the text query information to obtain a logic analysis result; A second structured query language query statement is generated according to the logic analysis result, the target data table and the query field name corresponding to the target data table, wherein the query field name is determined by the keyword.
11. A query statement generating device, characterized in that: include: an information matching unit, configured to obtain text query information, perform similarity matching between the text query information and a data table set to obtain a first data table subset that meets similarity requirements, and combine data tables in the first data table subset according to a keyword set corresponding to the text query information to obtain a data table combination set; a coefficient determination unit, configured to determine, if there is a first data table combination in the data table combination set, a correlation coefficient corresponding to the first data table combination according to a graph database corresponding to the data table set, wherein the first data table combination is a data table combination having an association relationship in the graph database; A combination confirmation unit, configured to select a first data table combination with a maximum correlation coefficient as a second data table combination, initiate a confirmation instruction for the second data table combination, and obtain a third data table combination that meets the user's needs according to reply information corresponding to the confirmation instruction; A statement generating unit is used to generate a first structured query language query statement corresponding to the text query information according to the association relationship of the third data table combination in the graph database.
12. An electronic device, characterized in that: include: A processor, and a memory communicatively connected to the processor; The memory stores computer-executable instructions; The processor executes the computer-executable instructions stored in the memory to implement the method according to any one of claims 1 to 10.
13. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer-executable instructions, which are used to implement the method according to any one of claims 1 to 10 when executed by a processor.
14. A computer program product, characterized in that The invention comprises a computer program, which implements the method according to any one of claims 1 to 10 when being executed by a processor.
Citation Information
Patent Citations
Data analysis method, device and equipment and computer readable medium
CN117609233A
Data query method and device, computer equipment and storage medium
CN117931858A
Method and device for generating SQL (Structured Query Language) statement from natural language statement
CN118484465A
Semantic search based on a graph database
US20230076923A1
Cited By
Method and device for converting natural language to SQL (Structured Query Language) statement and electronic equipment
CN121387942A
