Method for generating a query statement set of a database, method for training a ranking model

By generating a set of query statements for the database and training a sorting model, the problem of interaction between non-technical users and the database is solved, and efficient conversion and accurate querying of complex query requests are achieved.

CN116756167BActive Publication Date: 2026-05-08FUDAN UNIVERSITY
View PDF 1 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
FUDAN UNIVERSITY
Filing Date
2023-05-15
Publication Date
2026-05-08

AI Technical Summary

Technical Problem

Existing technologies make it difficult to enable natural language interaction between non-technical users without professional training and databases, especially for querying data with special structures and specific semantics.

Method used

By extracting keywords from multiple sample SQL statements in the database and performing semantic annotation, the query units are reorganized, converted into template language statements, and a set of query statements is generated. The candidate SQL statements are then sorted using a trained ranking model to determine the target SQL statement, thus achieving the conversion from natural language to SQL.

Benefits of technology

It improves the accuracy of converting natural language to SQL statements, especially in handling complex query requests, simplifies the interaction between non-technical users and the database, and improves the accuracy of data query results.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN116756167B_ABST
    Figure CN116756167B_ABST
Patent Text Reader

Abstract

The application relates to the information technology field and discloses a method for generating a query statement set of a database, a method for training a ranking model, and a method for generating a query statement set of a database, which comprises the following steps: a labeling step, in which a plurality of keywords are extracted from a plurality of sample structured query language (SQL) statements of a database, and semantic labeling of each keyword is obtained; a recombination step, in which each sample SQL statement is split into a plurality of query units, and the plurality of query units are recombined multiple times based on a preset recombination rule to obtain a plurality of candidate SQL statements; and a conversion step, in which each candidate SQL statement is converted into a template language statement based on the plurality of semantic labels to obtain a plurality of template language statements, wherein the plurality of candidate SQL statements and the plurality of template language statements form a query statement set. The application can improve the accuracy of data query results.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of information technology, and more specifically, to methods for generating a set of query statements for a database, methods for training a sorting model, data query methods, apparatus, media, electronic devices, and computer program products. Background Technology

[0002] Currently, data across industries is experiencing explosive growth, with a significant portion of this data stored in structured and semi-structured knowledge bases (such as databases). Traditionally, the analysis and retrieval of this data involves interacting with the database using Structured Query Language (SQL). However, using SQL requires specialized training and a thorough understanding of the database schema. This significantly limits access for non-technical users without such training and presents a high barrier to entry for data analysis and use. Therefore, how to enable natural language interaction with databases for non-technical users without specialized training is a problem that has attracted widespread attention in both industry and academia, and remains a challenging issue.

[0003] Faced with massive databases, the data people want to obtain is no longer limited to simple data in a single table, but rather data with special structures and specific semantics. For example, if a user wants to find different codes for templates used in an article, then "templates used in an article" can be considered data with special semantics, meaning it needs to be analyzed and retrieved through the relationships between primary and foreign keys in various tables of the database. A core problem with existing models is that data with special structures and specific semantics in the database is not adequately represented, failing to help non-technical users complete interactive operations with the database. Therefore, some data with special structures and specific semantics renders existing models unsuitable. Summary of the Invention

[0004] This application provides methods for generating a set of query statements for a database, methods for training a sorting model, data query methods, apparatus, media, electronic devices, and computer program products.

[0005] In a first aspect, embodiments of this application provide a method for generating a set of query statements for a database, for use in an electronic device, the method comprising:

[0006] The annotation step involves extracting multiple keywords from multiple sample Structured Query Language (SQL) statements in the database and obtaining semantic annotations for each keyword.

[0007] The reorganization step involves splitting each sample SQL statement into multiple query units, and reorganizing the multiple query units multiple times based on preset reorganization rules to obtain multiple candidate SQL statements.

[0008] The conversion step involves converting each candidate SQL statement into a template language statement based on multiple semantic annotations, resulting in multiple template language statements.

[0009] The plurality of candidate SQL statements and the plurality of template language statements form the query statement set.

[0010] In one possible implementation of the first aspect above, the template language statement is a natural language-like statement.

[0011] In one possible implementation of the first aspect described above, each SQL statement consists of multiple query units, and the keyword is associated with each query unit.

[0012] The query unit has semantics and is the minimum structural component of an SQL statement.

[0013] In one possible implementation of the first aspect above, in the reorganization step, based on the SQL syntax rules, each sample SQL statement is split into multiple query units, and the frequency of occurrence of each query unit is counted.

[0014] The preset reorganization rules include the syntax rules of the SQL, the frequency rules of query units, the word count rules of statements, and any combination thereof.

[0015] In one possible implementation of the first aspect above, the frequency rule for query units includes: the number of reorganizations of query units with high frequency of occurrence is greater than the number of reorganizations of query units with low frequency of occurrence.

[0016] In one possible implementation of the first aspect above, the conversion step further includes:

[0017] The splitting step involves dividing each candidate SQL statement into multiple query units;

[0018] The translation step translates each query unit of each candidate SQL statement into semantic annotations of the associated keywords;

[0019] The combination step combines the multiple semantic annotations obtained from the translation to obtain a template language statement for each candidate SQL statement.

[0020] In one possible implementation of the first aspect above, the keywords include table names, column names, and table join relationships in the database.

[0021] Secondly, embodiments of this application provide a method for training a ranking model for use in an electronic device, the method comprising:

[0022] The extraction step involves extracting a portion of the template language statements as training data from the plurality of template language statements obtained according to the method described in the first aspect.

[0023] The training step involves using the training data and standard natural language statements to train the ranking model, resulting in a trained ranking model.

[0024] In one possible implementation of the second aspect above, the extraction step further includes:

[0025] The splitting step involves dividing the candidate SQL statement corresponding to each template language statement into multiple query units;

[0026] The first calculation step is to compare each query unit with the standard query unit and calculate the similarity of each query unit.

[0027] The second calculation step involves calculating a score for each template language statement based on multiple similarities.

[0028] The sorting step involves sorting multiple template language statements based on their respective scores, and then extracting a portion of the sorted template language statements as the training data.

[0029] Thirdly, embodiments of this application provide a data query method for an electronic device, the method comprising:

[0030] The first step is to obtain the query request described in natural language.

[0031] In the generation step, when the current database to be queried is a new database, the method described in the first aspect is used to generate the query statement set of the current database, the query statement set including multiple current candidate SQL statements and multiple current template language statements;

[0032] The sorting step involves inputting the query request and the plurality of current template language statements into the trained sorting model obtained according to the method described in the second aspect, thereby sorting the plurality of current template language statements.

[0033] The determination steps are as follows: obtain the target template language statement from the sorted plurality of current template language statements, and determine the current candidate SQL statement corresponding to the target template language statement as the target SQL statement;

[0034] The query step involves performing a query based on the target SQL statement to retrieve the query results corresponding to the query request.

[0035] In one possible implementation of the third aspect above, the target template language statement is the current template language statement that is ranked first among the sorted plurality of current template language statements.

[0036] Fourthly, embodiments of this application provide an apparatus for generating a set of query statements for a database, the apparatus comprising:

[0037] The annotation unit extracts multiple keywords from multiple sample Structured Query Language (SQL) statements in the database and obtains semantic annotations for each keyword;

[0038] The reorganization unit splits each sample SQL statement into multiple query units, and reorganizes the multiple query units multiple times based on a preset reorganization rule to obtain multiple candidate SQL statements;

[0039] The conversion unit, based on the multiple semantic annotations, converts each candidate SQL statement into a template language statement, resulting in multiple template language statements.

[0040] The plurality of candidate SQL statements and the plurality of template language statements form the query statement set.

[0041] Fifthly, embodiments of this application provide an apparatus for training a ranking model, the apparatus comprising:

[0042] The extraction unit extracts a portion of the template language statements as training data from the plurality of template language statements obtained by the apparatus according to the fourth aspect.

[0043] The training unit uses the training data and standard natural language to train the ranking model, resulting in a trained ranking unit.

[0044] Sixthly, embodiments of this application provide a data query device, the device comprising:

[0045] The first acquisition unit acquires query requests described in natural language.

[0046] The generation unit, when the current database to be queried is a new database, uses the apparatus according to the fourth aspect to generate the set of query statements for the current database, the set of query statements including multiple current candidate SQL statements and multiple current template language statements;

[0047] The sorting unit inputs the query request and the plurality of current template language statements into the trained sorting model obtained according to the apparatus described in the fifth aspect, thereby sorting the plurality of current template language statements;

[0048] The determining unit obtains the target template language statement from the sorted plurality of current template language statements, and determines the current candidate SQL statement corresponding to the target template language statement as the target SQL statement;

[0049] The query unit performs a query based on the target SQL statement to retrieve the query results corresponding to the query request.

[0050] In a seventh aspect, embodiments of this application provide a computer-readable storage medium storing instructions that, when executed on a computer, cause the computer to perform the methods described in the first, second, or third aspects above.

[0051] Eighthly, embodiments of this application provide an electronic device, including: one or more processors; one or more memories; the one or more memories storing one or more programs, which, when executed by the one or more processors, cause the electronic device to perform the methods described in the first, second, or third aspects above.

[0052] Ninthly, embodiments of this application provide a computer program product including computer-executable instructions that are executed by a processor to implement the methods described in the first, second, or third aspects.

[0053] This invention proposes a method to generate a set of query statements that cover the user's query intent based on semantic annotation, and then use this set of query statements to train a ranking model. Since the semantic annotation contains both semantic and structural information from the database, and the query statement set contains SQL statements with all semantic information, the trained ranking model can improve the accuracy of ranking multiple candidate SQL statements.

[0054] When a user submits a query request in natural language to the database, the trained ranking model sorts the candidate SQL statements in the database's query statement set and selects the top-ranked candidate SQL statement as the SQL statement corresponding to the query request. This facilitates interaction between the user and the database, while also providing significant convenience to non-technical users without specialized training.

[0055] This invention improves the accuracy of converting natural language statements to SQL statements by utilizing a trained ranking model. Even for complex query requests, it enhances conversion accuracy for data with special structures and specific semantics in the database. Furthermore, the improved accuracy of the SQL statements leads to a corresponding increase in the accuracy of the final data query results. Attached Figure Description

[0056] Figure 1 A flowchart is shown for a method for generating a set of query statements for a database according to an embodiment of this application;

[0057] Figure 2 It shows Figure 1 A detailed flowchart of the conversion steps in the process;

[0058] Figure 3 A flowchart illustrating a method for training a ranking model according to an embodiment of the present invention is shown;

[0059] Figure 4 yes Figure 3 A detailed flowchart of the extraction steps in the process;

[0060] Figure 5 A flowchart of a data query method according to an embodiment of the present invention is shown;

[0061] Figure 6 A structural diagram of an apparatus for generating a set of query statements for a database according to an embodiment of the present invention is shown;

[0062] Figure 7 A structural diagram of an apparatus for training a ranking model according to an embodiment of the present invention is shown;

[0063] Figure 8 A structural diagram of a data query device according to an embodiment of the present invention is shown;

[0064] Figure 9 A block diagram of an electronic device according to an embodiment of this application is shown. Detailed Implementation

[0065] The technical solutions of the embodiments of this application will now be described with reference to the accompanying drawings. Obviously, the described embodiments are only a part of the embodiments of this application, and not all of them. All other embodiments obtained by those skilled in the art based on the embodiments of this application without creative effort are within the scope of protection of this application.

[0066] Figure 1A flowchart illustrating a method for generating a set of query statements for a database according to an embodiment of the present invention is shown. This method is applicable to electronic devices, such as computers, servers, mobile terminals, etc.

[0067] like Figure 1 As shown, in the annotation step S11, multiple keywords are extracted from multiple sample structured query language (SQL) statements in the database, and the semantic annotation of each keyword is obtained.

[0068] Since each database has its own unique semantic information and special structural information, in order to capture the semantics expressed in SQL statements and bridge the semantic gap between natural language statements and SQL statements, this invention first extracts keywords and performs semantic annotation on each keyword.

[0069] Specifically, multiple sample SQL statements targeting the database can be obtained in advance, and the parts containing semantic and structural information about the database can be extracted as keywords. These keywords include table names, column names, table join relationships, and so on.

[0070] For example, keywords include table1, col1, col2, etc.

[0071] Next, semantic annotations for each keyword can be obtained from the user. Specifically, after extracting these keywords, the user can be prompted to provide semantic annotations for each keyword. Based on their understanding of the database, their own knowledge, and the aforementioned sample SQL statements, the user can semantically annotate the extracted keywords and establish a connection between the keywords and natural language.

[0072] For example, the semantic tag for the keyword table1 is "report card", the semantic tag for the keyword col1 is "name", and the semantic tag for the keyword col2 is "grades".

[0073] Semantic annotation of table names can provide more meaningful names for database tables. Since the primary key of a table is crucial information for translation, this invention can add primary key information to the semantic annotation as part of the annotation. Semantic annotation of column names can provide more meaningful names for columns. Furthermore, if a query involves join operations between tables, the semantics expressed in the SQL may become more ambiguous; therefore, semantic annotation of table join relationships can represent the semantics of the SQL join operations.

[0074] In the reorganization step S12, each sample SQL statement is split into multiple query units, and based on the preset reorganization rules, the multiple query units are reorganized multiple times to obtain multiple candidate SQL statements.

[0075] Each SQL statement consists of multiple query units, which have semantic meaning and are the smallest structural unit of an SQL statement.

[0076] Furthermore, as mentioned above, the keywords are extracted from the sample SQL statements, so each keyword is associated with a corresponding query unit. For example, the keyword `table1` is associated with query unit A, the keyword `col1` with query unit B, and the keyword `col2` with query unit C.

[0077] In this step, each sample SQL statement is first broken down into multiple query units based on the SQL syntax rules. SQL has its own syntax rules, which are known, so they will not be detailed here.

[0078] Understandably, splitting the data yields a large number of query units, allowing us to statistically analyze the frequency of each unit. For example, we might find that query unit A has a frequency of 100, query unit B has a frequency of 1000, and query unit C has a frequency of 500.

[0079] Then, based on the preset reorganization rules, these split query units are reorganized multiple times to obtain multiple candidate SQL statements.

[0080] The preset reorganization rules include SQL syntax rules, query cell frequency rules, statement word count rules, and any combination thereof.

[0081] The frequency of query units is determined by the following rule: query units with higher frequency of occurrence are recombined more often than query units with lower frequency of occurrence. For example, query unit B is recombined more often than query units A and C, and query unit C is recombined more often than query unit A, and so on.

[0082] The statement word count rules include rules that limit the total number of words in the reorganized candidate SQL statements, which can prevent the reorganized candidate SQL statements from being too long.

[0083] It is understood that the above-mentioned preset recombination rules are merely examples and may include any other rules and any combination of these rules.

[0084] Understandably, based on preset reorganization rules, these query units are reorganized arbitrarily multiple times to obtain multiple candidate SQL statements.

[0085] The number of candidate SQL statements is greater than the number of sample SQL statements. For example, the number of sample SQL statements is 10,000, while the number of candidate SQL statements is 1 million.

[0086] Understandably, the generated candidate SQL statements already contain all the semantic information of the user.

[0087] In the transformation step S13, based on multiple semantic annotations, each candidate SQL statement is converted into a template language statement, resulting in multiple template language statements.

[0088] Figure 2 A flowchart of the conversion steps is shown. For example... Figure 2 As shown, in the splitting step S131, each candidate SQL statement is split into multiple query units.

[0089] For example, the candidate SQL statement SQL 1 can be split into, for example, three query units. These query units are, for example, query unit A, query unit B, and query unit C.

[0090] Next, in translation step S132, each query unit of each candidate SQL statement is translated into semantic annotations of associated keywords.

[0091] For example, for query unit A of candidate SQL statement SQL 1, as mentioned above, query unit A is associated with the keyword table1, and the semantic label of the keyword table1 is "transcript". Therefore, query unit A is translated as "transcript".

[0092] Similarly, query unit B is associated with keyword col1, and the semantic label of keyword col1 is "name", so query unit B is translated as "name". Query unit C is associated with keyword col2, and the semantic label of keyword col2 is "grades", so query unit C is translated as "grades".

[0093] In step 133, the multiple semantic annotations obtained from the translation are combined to obtain the template language statement for each candidate SQL statement.

[0094] For example, combining these semantic tags "transcript", "name", and "grade" yields a template language statement for SQL 1.

[0095] Understandably, by following steps S131-133, each candidate SQL statement can be converted into a corresponding template language statement.

[0096] It is understandable that template language statements are similar to natural language statements.

[0097] It is understandable that each candidate SQL statement has a corresponding template language statement; that is, there is a one-to-one correspondence between candidate SQL statements and template language statements. In other words, if the number of candidate SQL statements is 1 million, then the number of template language statements is also 1 million.

[0098] Multiple candidate SQL statements and multiple template language statements form the query statement set of this database. For example, 1 million candidate SQL statements and 1 million template language statements form the query statement set of this database.

[0099] Figure 3 A flowchart illustrating a method for training a ranking model according to an embodiment of the present invention is shown. This method is used in electronic devices, such as computers, servers, mobile terminals, etc.

[0100] like Figure 3 As shown, in extraction step S31, from Figure 1 The method shown extracts a portion of the template language statements from the multiple template language statements obtained as training data.

[0101] Figure 4 A flowchart illustrating the extraction steps is shown. Figure 4 As shown, in the splitting step S311, the candidate SQL statement corresponding to each template language statement is split into multiple query units.

[0102] For example, the candidate SQL statement SQL_m1 corresponding to the template language statement M1 can be split into two query units, such as query unit U1 and query unit U2.

[0103] In the first calculation step S312, each query unit is compared with the standard query unit to obtain the similarity of each query unit.

[0104] Understandably, standard query units are existing, publicly available, and correct query units used as the basis for comparison with query units.

[0105] For example, query unit U1 is compared with a standard query unit, and the similarity S1 of query unit U1 is calculated. Similarly, query unit U2 is compared with a standard query unit, and the similarity S2 of query unit U2 is calculated.

[0106] The second calculation step S313 calculates the score for each template language statement based on multiple similarities.

[0107] Specifically, for example, the average of similarity S1 and similarity S2 can be calculated as the score of template language statement M1. Alternatively, the variance of similarity S1 and similarity S2 can be calculated as the score of template language statement M1.

[0108] Similarly, a score can be calculated for each template language statement. For example, in this embodiment, with 1 million template language statements, 1 million scores can be calculated.

[0109] In sorting step S314, the multiple template language statements are sorted based on their respective scores, and a portion of the sorted template language statements are extracted as training data.

[0110] Specifically, for example, the 1 million template language statements are sorted according to the aforementioned 1 million scores. From these 1 million sorted template language statements, the top 10,000 are extracted as training data.

[0111] return Figure 3 In training step S32, the ranking model is trained using training data and standard natural language to obtain the trained ranking model.

[0112] For example, the 10,000 template language statements and standard natural language statements obtained as described above are input into the ranking model, and the model is trained based on similarity to obtain the trained ranking model.

[0113] It is understandable that standard natural language statements are existing and publicly available. Furthermore, it is understandable that each of the 10,000 template language statements has a score.

[0114] Ranking models can be implemented using, for example, a dual-tower model or a pre-trained language model. Examples of dual-tower models include SENet and DSSM, while examples of pre-trained language models include BERT.

[0115] Figure 5 A flowchart of a data query method according to an embodiment of the present invention is shown. This method is used in electronic devices, such as computers, servers, mobile terminals, etc.

[0116] like Figure 5 As shown, in the first acquisition step S51, a query request described in natural language is acquired, such as query request Q1. Query request Q1 is used to query data in the current database D1.

[0117] In generation step S52, when the current database D1 to be queried is a new database, the method based on... Figure 1 The method shown generates a set of query statements for the current database, which includes multiple current candidate SQL statements and multiple current template language statements.

[0118] If the current database D1 is a new database, then there is no set of query statements for the current database D1. Therefore, it is necessary to follow... Figure 1 The method shown generates a set of query statements for the current database D1, and then proceeds to the sorting step S53 below.

[0119] This query statement set includes multiple current candidate SQL statements and multiple current template language statements. It is understood that there is a one-to-one correspondence between the current candidate SQL statements and the current template language statements.

[0120] Understandably, if the current database D1 is not a new database, then it has already passed... Figure 1 The method shown generates a set of query statements for the current database D1, and then we can directly proceed to the sorting step S53 below.

[0121] In sorting step S53, query request Q1 and multiple current template language statements are input according to the above. Figure 3 The method shown yields a trained ranking model, which is used to rank multiple current template language statements.

[0122] For example, in this embodiment, there are 100,000 current template language statements, and these current template language statements are sorted using a trained sorting model.

[0123] In step S54, the target template language statement is obtained from the sorted multiple current template language statements, and the current candidate SQL statement corresponding to the target template language statement is determined as the target SQL statement.

[0124] The target template language statement is the first-ranked current template language statement among a sorted pool of current template language statements. In other words, from 100,000 sorted current template language statements, the first-ranked statement is selected as the target template language statement. Then, the corresponding candidate SQL statement is used as the target SQL statement.

[0125] In query step S55, a query is performed based on the target SQL statement to retrieve the query result corresponding to query request Q1.

[0126] It is understandable that the target SQL statement is used to query the current database D1, thereby retrieving the query results corresponding to the query request Q1.

[0127] This invention proposes a method to generate a set of query statements that cover the user's query intent based on semantic annotation, and then use this set of query statements to train a ranking model. Since the semantic annotation contains both semantic and structural information from the database, and the query statement set contains SQL statements with all semantic information, the trained ranking model can improve the accuracy of ranking multiple candidate SQL statements.

[0128] When a user submits a query request in natural language to the database, the trained ranking model sorts the candidate SQL statements in the database's query statement set and selects the top-ranked candidate SQL statement as the SQL statement corresponding to the query request. This facilitates interaction between the user and the database, while also providing significant convenience to non-technical users without specialized training.

[0129] This invention improves the accuracy of converting natural language statements to SQL statements by utilizing a trained ranking model. Even for complex query requests, it enhances conversion accuracy for data with special structures and specific semantics in the database. Furthermore, the improved accuracy of the SQL statements leads to a corresponding increase in the accuracy of the final query results.

[0130] The present invention also provides an apparatus for generating a set of query statements for a database. For example... Figure 6 The device 60 includes:

[0131] The annotation unit 61 extracts multiple keywords from multiple sample Structured Query Language (SQL) statements in the database and obtains semantic annotations for each keyword.

[0132] Reorganization unit 62 splits each sample SQL statement into multiple query units, and reorganizes the multiple query units multiple times based on preset reorganization rules to obtain multiple candidate SQL statements;

[0133] The conversion unit 63, based on the multiple semantic annotations, converts each candidate SQL statement into a template language statement, resulting in multiple template language statements.

[0134] The plurality of candidate SQL statements and the plurality of template language statements form the query statement set.

[0135] It is understandable that annotation unit 61, recombination unit 62, and transformation unit 63 can be... Figure 9 The processor 1404 in the electronic device 1400 has the functions of these modules or units to implement them.

[0136] The present invention also provides an apparatus for training a ranking model. For example... Figure 7 As shown, the device 70 includes:

[0137] Extraction unit 71, from according to Figure 6 The device extracts a portion of the template language statements from the multiple template language statements obtained as training data.

[0138] Training unit 72 uses the training data and standard natural language to train the ranking model, resulting in a trained ranking unit.

[0139] It is understandable that extraction unit 71 and training unit 72 can be achieved through... Figure 9 The processor 1404 in the electronic device 1400 has the functions of these modules or units to implement them.

[0140] The present invention also provides a data query device. For example... Figure 8 As shown, the device 80 includes:

[0141] The first acquisition unit 81 acquires the query request described in natural language;

[0142] The generation unit 82, when the current database to be queried is a new database, uses the apparatus according to claim 12 to generate the query statement set of the current database, the query statement set including multiple current candidate SQL statements and multiple current template language statements;

[0143] The sorting unit 83 inputs the query request and the plurality of current template language statements into the trained sorting model obtained by the apparatus according to claim 13, thereby sorting the plurality of current template language statements;

[0144] The determining unit 84 obtains the target template language statement from the sorted plurality of current template language statements, and determines the current candidate SQL statement corresponding to the target template language statement as the target SQL statement;

[0145] The query unit 85 performs a query based on the target SQL statement to retrieve the query result corresponding to the query request.

[0146] It is understandable that the first acquisition unit 81, generation unit 82, sorting unit 83, determination unit 84, and query unit 85 can be... Figure 9 The processor 1404 in the electronic device 1400 has the functions of these modules or units to implement them.

[0147] The present invention also provides a computer-readable storage medium storing instructions that, when executed on a computer, cause the computer to perform [operations]. Figure 1 or Figure 3 or Figure 5 The method shown.

[0148] The present invention also provides a computer program product, including computer-executable instructions, which are executed by processor 1404 to carry out [the program]. Figure 1 or Figure 3 or Figure 5 The method shown.

[0149] Now for reference Figure 9 , Figure 9 An example electronic device 1400 according to an embodiment of the present invention is illustrated schematically. In one embodiment, system 1400 may include one or more processors 1404, system control logic 1408 connected to at least one of the processors 1404, system memory 1412 connected to system control logic 1408, non-volatile memory (NVM) 1416 connected to system control logic 1408, and network interface 1420 connected to system control logic 1408.

[0150] In some embodiments, processor 1404 may include one or more single-core or multi-core processors. In some embodiments, processor 1404 may include any combination of general-purpose processors and special-purpose processors (e.g., graphics processors, application processors, baseband processors, etc.). In embodiments where system 1400 employs eNB (Evolved Node B) 101 or RAN (Radio Access Network) controller 102, processor 1404 may be configured to perform various corresponding embodiments, such as... Figure 1 or Figure 3 or Figure 5 The example shown.

[0151] In some embodiments, system control logic 1408 may include any suitable interface controller to provide any suitable interface to at least one of the processors 1404 and / or any suitable device or component communicating with system control logic 1408.

[0152] In some embodiments, system control logic 1408 may include one or more memory controllers to provide an interface to system memory 1412. System memory 1412 may be used to load and store data and / or instructions. In some embodiments, memory 1412 of system 1400 may include any suitable volatile memory, such as suitable dynamic random access memory (DRAM).

[0153] NVM / memory 1416 may include one or more tangible, non-transitory computer-readable media for storing data and / or instructions. In some embodiments, NVM / memory 1416 may include any suitable non-volatile memory such as flash memory and / or any suitable non-volatile storage device, such as at least one of HDD (Hard Disk Drive), CD (Compact Disc) drive, and DVD (Digital Versatile Disc) drive.

[0154] NVM / Memory 1416 may include a portion of the storage resources on the device on which System 1400 is installed, or it may be accessible by the device, but is not necessarily part of the device. For example, NVM / Memory 1416 may be accessed over a network via Network Interface 1420.

[0155] Specifically, system memory 1412 and NVM / memory 1416 may each include a temporary copy and a permanent copy of instruction 1424. Instruction 1424 may include, when executed by at least one of processors 1404, causing electronic device 1400 to perform, as Figure 2 The instructions for the method shown. In some embodiments, instructions 1424, hardware, firmware and / or their software components may additionally / alternatively be located in system control logic 1408, network interface 1420 and / or processor 1404.

[0156] Network interface 1420 may include a transceiver for providing a radio interface to system 1400, thereby enabling communication with any other suitable device (such as a front-end module, antenna, etc.) via one or more networks. In some embodiments, network interface 1420 may be integrated into other components of system 1400. For example, network interface 1420 may be integrated into at least one of processor 1404, system memory 1412, NVM / memory 1416, and firmware device (not shown) with instructions that, when at least one of processor 1404 executes the instructions, electronic device 1400 implements as follows: Figure 1 or Figure 3 or Figure 5 The method shown.

[0157] The network interface 1420 may further include any suitable hardware and / or firmware to provide a multiple-input multiple-output radio interface. For example, the network interface 1420 may be a network adapter, a wireless network adapter, a telephone modem, and / or a wireless modem.

[0158] In one embodiment, at least one of the processors 1404 may be packaged together with the logic of one or more controllers for system control logic 1408 to form a system-in-package (SiP). In another embodiment, at least one of the processors 1404 may be integrated on the same die with the logic of one or more controllers for system control logic 1408 to form a system-on-a-chip (SoC).

[0159] The electronic device 1400 may further include an input / output (I / O) device 1432. The I / O device 1432 may include a user interface enabling a user to interact with the electronic device 1400; the peripheral component interface is designed to allow peripheral components to also interact with the electronic device 1400. In some embodiments, the electronic device 1400 may also include sensors for determining at least one type of environmental condition and location information related to the electronic device 1400.

[0160] In some embodiments, the user interface may include, but is not limited to, a display (e.g., a liquid crystal display, a touch screen display, etc.), a speaker, a microphone, one or more cameras (e.g., a still image camera and / or a video camera), a flashlight (e.g., a light-emitting diode flash), and a keyboard.

[0161] The various embodiments of the mechanisms disclosed in this application can be implemented in hardware, software, firmware, or a combination of these implementation methods. Embodiments of this application can be implemented as computer programs or program code executable on a programmable system, the programmable system including at least one processor, a storage system (including volatile and non-volatile memory and / or storage elements), at least one input device, and at least one output device.

[0162] Program code can be applied to input instructions to execute the functions described in this application and generate output information. The output information can be applied to one or more output devices in a known manner. For the purposes of this application, the processing system includes any system having a processor such as, for example, a digital signal processor (DSP), a microcontroller, an application-specific integrated circuit (ASIC), or a microprocessor.

[0163] The program code can be implemented using a high-level procedural language or an object-oriented programming language to communicate with the processing system. Assembly language or machine language can also be used when needed. In fact, the mechanisms described in this application are not limited to any particular programming language. In either case, the language can be a compiled language or an interpreted language.

[0164] In some cases, the disclosed embodiments may be implemented in hardware, firmware, software, or any combination thereof. The disclosed embodiments may also be implemented as instructions carried or stored thereon on one or more temporary or non-temporary machine-readable (e.g., computer-readable) storage media, which may be read and executed by one or more processors. For example, the instructions may be distributed via a network or through other computer-readable media. Therefore, machine-readable media may include any mechanism for storing or transmitting information in a machine-readable (e.g., computer-readable) form, including but not limited to floppy disks, optical disks, CD-ROMs, magneto-optical disks, read-only memory (ROM), random access memory (RAM), erasable programmable read-only memory (EPROM), electrically erasable programmable read-only memory (EEPROM), magnetic cards or optical cards, flash memory, or tangible machine-readable storage for transmitting information (e.g., carrier waves, infrared signals, digital signals, etc.) using the Internet in the form of electrical, optical, acoustic, or other propagation signals. Therefore, machine-readable media include any type of machine-readable medium suitable for storing or transmitting electronic instructions or information in a machine-readable (e.g., computer-readable) form.

[0165] In the accompanying drawings, some structural or methodological features may be shown in a specific arrangement and / or order. However, it should be understood that such a specific arrangement and / or order may not be necessary. Rather, in some embodiments, these features may be arranged in a manner and / or order different from that shown in the illustrative drawings. Furthermore, the inclusion of structural or methodological features in a particular figure does not imply that such features are required in all embodiments, and in some embodiments, these features may be omitted or may be combined with other features.

[0166] It should be noted that all units / modules mentioned in the device embodiments of this application are logical units / modules. Physically, a logical unit / module can be a physical unit / module, a part of a physical unit / module, or a combination of multiple physical units / modules. The physical implementation of these logical units / modules themselves is not the most important factor; the combination of functions implemented by these logical units / modules is the key to solving the technical problems proposed in this application. Furthermore, to highlight the innovative aspects of this application, the above-described device embodiments of this application have not introduced units / modules that are not closely related to solving the technical problems proposed in this application. This does not mean that the above-described device embodiments do not contain other units / modules.

[0167] It should be noted that in the examples and description of this patent, relational terms such as "first" and "second" are used merely to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitations, an element defined by the phrase "comprising one" does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes said element.

[0168] Although this application has been illustrated and described with reference to certain preferred embodiments thereof, those skilled in the art should understand that various changes in form and detail may be made thereto without departing from the spirit and scope of this application.

Claims

1. A method for generating a set of query statements for a database, used in an electronic device, characterized in that, The method includes: The annotation step involves extracting multiple keywords from multiple sample structured query language statements in the database and obtaining semantic annotations for each keyword. The keywords include table names, column names, and table join relationships in the database. The reorganization step involves splitting each sample structured query language statement into multiple query units based on the syntax rules of the structured query language. Then, based on preset reorganization rules, the multiple query units are reorganized multiple times to obtain multiple candidate structured query language statements. Each query unit has semantic meaning and is the minimum structural component of the structured query language statement. The preset reorganization rules include the syntax rules of the structured query language, the frequency rules of query unit occurrence, the word count rules of the statement, and any combination thereof. The conversion step, based on the multiple semantic annotations, converts each candidate structured query language statement into a template language statement, resulting in multiple template language statements, which are similar to natural language statements. The plurality of candidate structured query language statements and the plurality of template language statements form the query statement set, and the two correspond one-to-one.

2. The method according to claim 1, characterized in that, Each Structured Query Language statement consists of multiple query units, and the keywords are associated with the query units.

3. The method according to claim 2, characterized in that, In the reorganization step, based on the syntax rules of the structured query language, each sample structured query language statement is split into multiple query units, and the frequency of occurrence of each query unit is counted.

4. The method according to claim 3, characterized in that, The frequency of query units is governed by the rule that query units with high frequency of occurrence are recombined more often than query units with low frequency of occurrence.

5. The method according to claim 2, characterized in that, The conversion step further includes: The splitting step involves dividing each candidate structured query language statement into multiple query units; The translation step translates each query unit of each candidate structured query language statement into the semantic annotation of the associated keywords; The combination step combines the multiple semantic annotations obtained from the translation to obtain a template language statement for each candidate structured query language statement.

6. A method for training a ranking model for an electronic device, characterized in that, The method includes: The extraction step involves extracting a portion of the template language statements from the plurality of template language statements obtained by the method according to any one of claims 1-5 as training data; The training step involves using the training data and standard natural language statements to train the ranking model, resulting in a trained ranking model.

7. The method according to claim 6, characterized in that, The extraction step further includes: The splitting step involves breaking down the candidate structured query language statements corresponding to each template language statement into multiple query units; The first calculation step is to compare each query unit with the standard query unit and calculate the similarity of each query unit. The second calculation step involves calculating a score for each template language statement based on multiple similarities. The sorting step involves sorting multiple template language statements based on their respective scores, and then extracting a portion of the sorted template language statements as the training data.

8. A data query method for electronic devices, characterized in that, The method includes: The first step is to obtain the query request described in natural language. In the generation step, when the current database to be queried is a new database, the query statement set of the current database is generated using the method according to any one of claims 1-5, wherein the query statement set includes multiple current candidate structured query language statements and multiple current template language statements; The sorting step involves inputting the query request and the plurality of current template language statements into the trained sorting model obtained by the method according to any one of claims 6-7, thereby sorting the plurality of current template language statements; The determination steps are as follows: obtain the target template language statement from the sorted plurality of current template language statements, and determine the current candidate structured query language statement corresponding to the target template language statement as the target structured query language statement; The query step involves performing a query based on the target structured query language statement to retrieve the query results corresponding to the query request.

9. The method according to claim 8, characterized in that, The target template language statement is the current template language statement that is ranked first among the sorted multiple current template language statements.

10. An apparatus for generating a set of query statements for a database, characterized in that, The device includes: The annotation unit extracts multiple keywords from multiple sample structured query language statements in the database and obtains semantic annotations for each keyword. The keywords include table names, column names, and table join relationships in the database. The reorganization unit, based on the syntax rules of the structured query language, splits each sample structured query language statement into multiple query units, and reorganizes the multiple query units multiple times based on preset reorganization rules to obtain multiple candidate structured query language statements. The query unit has semantics and is the minimum structural component of the structured query language statement. The preset reorganization rules include the syntax rules of the structured query language, the frequency rules of the occurrence of query units, the word count rules of the statement, and any combination thereof. The conversion unit, based on the multiple semantic annotations, converts each candidate structured query language statement into a template language statement, resulting in multiple template language statements, which are similar to natural language statements. The plurality of candidate structured query language statements and the plurality of template language statements form the query statement set, and the two correspond one-to-one.

11. An apparatus for training a ranking model, characterized in that, The device includes: The extraction unit extracts a portion of the template language statements from the plurality of template language statements obtained by the device according to claim 10 as training data. The training unit uses the training data and standard natural language to train the ranking model, resulting in a trained ranking unit.

12. A data query device, characterized in that, The device includes: The first acquisition unit acquires query requests described in natural language. The generation unit, when the current database to be queried is a new database, uses the apparatus according to claim 10 to generate the query statement set of the current database, the query statement set including multiple current candidate structured query language statements and multiple current template language statements; The sorting unit inputs the query request and the plurality of current template language statements into the trained sorting model obtained by the apparatus according to claim 11, thereby sorting the plurality of current template language statements; The determining unit obtains the target template language statement from the sorted plurality of current template language statements, and determines the current candidate structured query language statement corresponding to the target template language statement as the target structured query language statement; The query unit performs a query based on the target structured query language statement to retrieve the query results corresponding to the query request.

13. A computer-readable storage medium, characterized in that, The storage medium stores instructions that, when executed on a computer, cause the computer to perform the method of any one of claims 1 to 5, or the method of any one of claims 6 to 7, or the method of any one of claims 8 to 9.

14. An electronic device, characterized in that, include: One or more processors; One or more memories; the one or more memories storing one or more programs, which, when executed by the one or more processors, cause the electronic device to perform the method of any one of claims 1 to 6, or the method of any one of claims 6 to 7, or the method of any one of claims 8 to 9.

15. A computer program product comprising computer-executable instructions, characterized in that, The instructions are executed by the processor to implement the method of any one of claims 1 to 5, or the method of any one of claims 6 to 7, or the method of any one of claims 8 to 9.

Citation Information

Patent Citations

  • Data pair generation method and device, electronic equipment and storage medium

    CN112559552A