Database query method, device, terminal device and storage medium

By automatically identifying and converting query text into database query statements through multiple models, it solves the problems of database query complexity and maintenance difficulty in the existing technology, and realizes an efficient and automated database query process.

CN117591547BActive Publication Date: 2024-09-27ZHONGHAO XINYING (HANGZHOU) TECHNOLOGY CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202410075405.5
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-01-18
Publication Date
2024-09-27
Estimated Expiration
2044-01-18

AI Technical Summary

Technical Problem

In the existing technology, users need to understand SQL and database structure when querying the database. The rule-based method relies on manually writing grammar rules and query templates, which increases the workload and is difficult to cover complex query situations, making maintenance cumbersome.

Method used

Through multiple models (target naming recognition model, target semantic analysis model, target relationship extraction model and target sentence generation model), the conversion from query text to query statement is automated, entities, semantics and relationships are identified, and query statements are automatically generated.

Benefits of technology

It improves database query efficiency, reduces user difficulty, adapts to complex queries, improves automation and processing efficiency, and reduces maintenance costs.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN117591547B
    Figure CN117591547B
Patent Text Reader

Abstract

The embodiment of the present application provides a database query method, device, terminal device and storage medium, which belongs to the field of database technology. The method includes: obtaining a target query text, and performing entity recognition on the target query text according to a target naming recognition model to obtain a target entity; performing semantic recognition on the target query text according to a target semantic analysis model to obtain target semantics; performing relationship extraction on the target query text according to a target relationship extraction model to obtain a target relationship; determining a target query statement corresponding to the target query text using a target sentence generation model according to the target entity, target semantics and target relationship; performing data query in the database according to the target query statement to obtain a target query result corresponding to the target query text. The method realizes the automatic conversion from query text to query statement through multiple models, improves the efficiency of database query, and reduces the difficulty of using the database.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of database technology, and in particular to a database query method, apparatus, terminal device and storage medium. Background Art

[0002] With the rapid growth of data volume, storing data in database has become the only choice because database has efficient data processing capability and can quickly store, analyze and mine massive data.

[0003] When users perform database queries, they need to understand the structured query language (SQL) corresponding to the database to be queried, as well as the structure and mode of the database. This may be a major obstacle for non-professional users. Therefore, related technologies propose rule-based methods to map user query languages ​​into database query languages. However, rule-based methods rely on manually writing complex grammar rules and query templates, which increases workload and seriously affects work efficiency. Moreover, this method is difficult to cover all possible query situations, especially when it comes to complex query structures and domain-specific contexts, and the design and maintenance of rules become cumbersome. Summary of the invention

[0004] The main purpose of the embodiments of the present application is to provide a database query method, apparatus, terminal device and storage medium, aiming to realize automatic conversion from query text to query statement through multiple models, improve database query efficiency and reduce the difficulty of using the database.

[0005] In a first aspect, an embodiment of the present application provides a method for querying a database, comprising:

[0006] Obtain a target query text, and perform entity recognition on the target query text according to a target naming recognition model to obtain a target entity;

[0007] Performing semantic recognition on the target query text according to the target semantic analysis model to obtain target semantics;

[0008] Performing relation extraction on the target query text according to the target relation extraction model to obtain the target relation;

[0009] Determine a target query sentence corresponding to the target query text by using a target sentence generation model according to the target entity, the target semantics, and the target relationship;

[0010] A data query is performed in the database according to the target query statement to obtain a target query result corresponding to the target query text.

[0011] In a second aspect, an embodiment of the present application provides a database query device, including:

[0012] An entity acquisition module is used to obtain a target query text and perform entity recognition on the target query text according to a target naming recognition model to obtain a target entity;

[0013] A semantic acquisition module, used for performing semantic recognition on the target query text according to a target semantic analysis model to obtain target semantics;

[0014] A relationship acquisition module, used to extract the relationship of the target query text according to the target relationship extraction model to obtain the target relationship;

[0015] A sentence acquisition module, used to determine a target query sentence corresponding to the target query text by using a target sentence generation model according to the target entity, the target semantics and the target relationship;

[0016] The result acquisition module is used to perform data query in the database according to the target query statement to obtain the target query result corresponding to the target query text.

[0017] In a third aspect, an embodiment of the present application further provides a terminal device, comprising a processor, a memory, a computer program stored in the memory and executable by the processor, and a data bus for realizing a connection and communication between the processor and the memory, wherein when the computer program is executed by the processor, the steps of any database query method provided in the specification of the present application are implemented.

[0018] In a fourth aspect, an embodiment of the present application further provides a storage medium for computer-readable storage, characterized in that the storage medium stores one or more programs, and the one or more programs can be executed by one or more processors to implement the steps of any database query method provided in the specification of the present application.

[0019] The embodiment of the present application provides a query method, device, terminal device and storage medium for a database, wherein the method includes obtaining a target query text, and performing entity recognition on the target query text according to a target naming recognition model to obtain a target entity; performing semantic recognition on the target query text according to a target semantic analysis model to obtain target semantics; performing relationship extraction on the target query text according to a target relationship extraction model to obtain a target relationship; and then determining a target query statement corresponding to the target query text using a target statement generation model according to the target entity, target semantics and target relationship; and finally performing a data query in a database according to the target query statement to obtain a target query result corresponding to the target query text. The embodiment of the present application automatically identifies the target entity to be queried through a target naming recognition model, automatically identifies the target semantics of the query text through a target semantic analysis model, and extracts the target relationship of the query text through a target relationship extraction model, thereby automatically converting the target query text into a target query statement in a database, so as to obtain the corresponding target query result according to the target query statement, thereby realizing the automatic generation of the target query statement and improving the query efficiency of the database.

[0020] Compared with the related art, the present application, through the joint application of multiple models, can identify the information that needs to be converted (such as target entity, target semantics, target relationship) from the target query text with more complex structure and more complex syntax, so as to automatically convert the target query text into the target query statement of the database, which greatly improves the adaptability of the embodiment of the present application, enables the embodiment of the present application to cope with complex queries of the database, further improves the automation of database queries, improves the processing efficiency of complex queries, and reduces the difficulty of using the database. The embodiment of the present application solves the problem that users in the related art need to understand the relevant information of the data when using the database, reduces the time cost of users using the database, improves the query efficiency, and solves the problem that the maintenance work is cumbersome and the maintenance cost is high when performing database queries based on the rule method in the related art, improves the efficiency of database queries, especially improves the processing efficiency of complex queries, and reduces the difficulty of using the database. BRIEF DESCRIPTION OF THE DRAWINGS

[0021] In order to more clearly illustrate the technical solutions of the embodiments of the present application, the drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.

[0022] Figure 1 A flowchart of a database query method provided in an embodiment of the present application;

[0023] Figure 2A schematic diagram of the principle of a database query method provided in an embodiment of the present application;

[0024] Figure 3 A schematic diagram of the module structure of a database query device provided in an embodiment of the present application;

[0025] Figure 4 A schematic block diagram of the structure of a terminal device provided in an embodiment of the present application. DETAILED DESCRIPTION

[0026] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.

[0027] The flowcharts shown in the accompanying drawings are only examples and do not necessarily include all the contents and operations / steps, nor must they be executed in the order described. For example, some operations / steps may also be decomposed, combined or partially merged, so the actual execution order may change according to actual conditions.

[0028] It should be understood that the terms used in this application specification are only for the purpose of describing specific embodiments and are not intended to limit the application. As used in this application specification and the appended claims, unless the context clearly indicates otherwise, the singular forms "a", "an" and "the" are intended to include plural forms.

[0029] The embodiments of the present application provide a method, apparatus, terminal device, and storage medium for querying a database. The method for querying a database can be applied to a terminal device, which can be an electronic device such as a tablet computer, a laptop computer, a desktop computer, a personal digital assistant, and a wearable device. The terminal device can be a server or a server cluster.

[0030] With the rapid growth of data volume, since databases have efficient data processing capabilities and can quickly store, analyze and mine massive amounts of data, storing data in databases has become the only choice. In order to ensure that non-professionals can also perform database queries normally, the relevant technology can use rule-based methods to convert user query texts into database query statements, but this method requires a large number of manually written grammar rules and query templates, which is difficult to deal with complex queries. Therefore, a database query method is urgently needed.

[0031] Some embodiments of the present application are described in detail below in conjunction with the accompanying drawings. In the absence of conflict, the following embodiments and features in the embodiments can be combined with each other.

[0032] Please refer to Figure 1 , Figure 1 A flowchart of a database query method provided in an embodiment of the present application.

[0033] like Figure 1 As shown, the database query method includes steps S101 to S105.

[0034] Step S101: obtain a target query text, and perform entity recognition on the target query text according to a target naming recognition model to obtain a target entity.

[0035] For example, when a user needs to query a database, a target query text is set, and then the target naming recognition model is used to perform entity recognition on the target query text to obtain the target entity corresponding to the target query text. Among them, the entity types included in the target naming recognition model are database name, table name, column name, keyword, etc.

[0036] For example, if the target query text is "get the total number of data with scores greater than 130 points under the shuxue column in the test table of the ceshi library", the target naming recognition model needs to be used to recognize that ceshi is the database name, test is the table name, shuxue is the column name, and other keywords may include greater than, 130 points, total, etc.

[0037] For example, assuming that the model structure of the target naming recognition model is composed of BI-LSTM and CRF, considering that the amount of labeled data in this field is small, the performance of the target naming recognition model may be reduced due to lack of sufficient data. When obtaining the target naming recognition model, the general naming recognition results can be combined with the specific data in this field through pre-training models and transfer learning, thereby improving the performance of the target naming recognition model in the case of data scarcity.

[0038] In addition, while obtaining the target naming recognition model, the present application can first use a rule-based method or a statistical method in the initial stage of model use to assist the target naming recognition model in performing entity recognition on the target query text to obtain the target entity, thereby ensuring the accuracy of the target naming recognition model in performing entity recognition on the target query text.

[0039] Step S102: performing semantic recognition on the target query text according to the target semantic analysis model to obtain target semantics.

[0040] Exemplarily, the target semantic analysis model is used to analyze the user intent of the target query text to obtain the target semantics corresponding to the target query text. Then, the query intent of the target query text is classified according to the target semantic analysis model, and the query intent corresponding to the target query text is more accurately identified. Then, the target query text is decomposed into multiple subtasks according to the key information in the query intent, thereby improving the ability of the target query text to generate accurate database query names.

[0041] For example, if the target query text is "obtain the total number of data with scores greater than 130 points under the shuxue column in the test table of the ceshi library", then the target semantic analysis model is used to classify the user intent of the target query text. It can be seen that the target semantics corresponding to the target query text is the calculation of the total number of data. Therefore, the target query text can be decomposed into two subtasks. Task 1 is to obtain the data with scores greater than 130 points under the shuxue column in the test table of the ceshi library, and Task 2 is to obtain the total number of results corresponding to Task 1.

[0042] Optionally, the model structure of the target semantic analysis model can be a neural network model or a machine learning model. This application does not impose any specific restrictions, and users can set it according to actual needs.

[0043] Step S103: extracting the target relationship from the target query text according to the target relationship extraction model to obtain the target relationship.

[0044] Exemplarily, the target relationship extraction model is used to extract the target query text, thereby obtaining the target relationship between the target entities in the target query text, thereby making the association relationship between the target entities in the target query text clearer.

[0045] For example, the target query text is "get the total number of data with scores greater than 130 points under the shuxue column in the test table of the ceshi library", the target entity is ceshi as the database name, test as the table name, shuxue as the column name, and other keywords may include greater than, 130 points, data volume, total number, etc. Then, the association relationship between the target entity ceshi and the target entity test is a dependency relationship, the association relationship between the target entity test and the target entity shuxue is a dependency relationship, the association relationship between the target entity data volume and the total number of the target entity is a restriction relationship, and so on.

[0046] Optionally, the model structure of the target relationship extraction model can be a neural network model or a machine learning model. This application does not impose any specific restrictions, and users can set it according to actual needs.

[0047] Step S104: determining a target query sentence corresponding to the target query text by using a target sentence generation model according to the target entity, the target semantics and the target relationship.

[0048] Exemplarily, after obtaining the target entity, target semantics and target relationship corresponding to the target query text, the target entity, target semantics and target relationship are input into the target sentence generation model to obtain the target query sentence corresponding to the target query text.

[0049] For example, the target sentence generation model can adopt a generative model structure to convert the target entity, target semantics, and target relationship into a target query sentence of the corresponding database.

[0050] In some embodiments, before obtaining the target query text, it also includes: obtaining target training data, and adjusting an initial naming recognition model according to the target training data to obtain a target naming recognition model, adjusting an initial semantic analysis model according to the target training data to obtain a target semantic analysis model, and adjusting an initial relationship extraction model according to the target training data to obtain a target relationship extraction model; performing entity recognition on the target training data according to the target naming recognition model to obtain an entity recognition result, performing semantic recognition on the target training data according to the target semantic analysis model to obtain a semantic recognition result, and performing relationship recognition on the target training data according to the target relationship extraction model to obtain a relationship recognition result; adjusting an initial sentence generation model according to the entity recognition result, the semantic recognition result, and the relationship recognition result to obtain a target sentence generation model.

[0051] In this way, fine-tuning the model using local model parameters can greatly reduce the amount of trainable parameters for downstream tasks and further improve the training effect.

[0052] Exemplarily, before obtaining the target query text, it is necessary to first obtain a target naming recognition model, a target semantic analysis model, a target relationship extraction model, and a target sentence generation model.

[0053] Exemplarily, target training data is obtained, which includes user query text and a database query statement corresponding to the user query text, entity names and entity types in the user query text and position information of the entity names in the user query text, associations between entity names, semantic types corresponding to the user query text, etc.

[0054] Exemplarily, an initial naming recognition model is obtained, and the model parameters corresponding to the initial naming recognition model are obtained by model training under existing open source data. The target training data is then used to adjust the model parameters corresponding to the initial naming recognition model, thereby obtaining a target naming recognition model suitable for the database query field, thereby improving the recognition accuracy of the target naming recognition model.

[0055] For example, the initial naming recognition model can be a named entity recognition model based on natural language processing, and then the keywords in the target training data (such as table names, column names, database names, etc.) are marked as specific identifiers, so as to use the target training data to adjust the model parameters of the initial naming recognition model, thereby improving the accuracy of entity recognition of the target naming recognition model in the database query field.

[0056] In practical applications, the initial named entity recognition model includes but is not limited to a rule-based named entity recognition model, a statistics-based named entity recognition model, and a deep learning-based named entity recognition model.

[0057] As an optional example, assume that the initial named entity recognition model is a rule-based named entity recognition model. Specifically, the initial named entity recognition model can be used to find keywords or features of named entities in text. Assume that the model is used to identify and mark specific entities such as table names, column names, and database names. The following is an implementation of the initial named entity recognition model:

[0058] First, build a dictionary containing keywords such as table names, column names, and database names. These keywords will be used as features of named entities. Use the Chinese word segmentation module to segment the text to be recognized in the target training data and divide the text into individual words or characters. For example, the Chinese word segmentation module can be Jieba word segmentation.

[0059] Then, for the text after word segmentation, the initial naming recognition model is used to match each keyword in the keyword dictionary in turn. If a keyword in the dictionary is found during the matching process, it can be marked as a corresponding named entity type, such as table name, column name, database name, etc. Finally, the marked named entity is output for subsequent processing or analysis. The named entity can be represented by a specific identifier, such as , <column name>, <database name>, etc.

[0060] Among them, the initial named entity recognition model performs the steps of keyword matching, such as: The first step is to initialize each keyword, that is: for each keyword, obtain its length and mark it as keyword_len; create an auxiliary array next to store the maximum length of the same prefix and suffix for each character in the keyword; for each position i (1 <= i < keyword_len) in the keyword, calculate the value of next[i], that is, the maximum length of the same prefix and suffix of the keyword. Optionally, this step can be implemented by recursion or loop. The second step is to perform matching on the segmented text, that is: for each word or character in the text, match it with each keyword in the keyword dictionary; for each keyword, use a preset algorithm for matching. During the matching process of the preset algorithm, initialize the matching position of the keyword to 0; starting from the current position in the text, compare the characters of the text and the keyword in sequence; if the match is successful, continue to compare the next character and update the matching position of the keyword at the same time; if the match fails, update the matching position of the keyword according to the value of the next array to minimize the number of comparisons. Further optionally, the position of the unmatched string can also be adjusted by using the partially matched keywords. It should be noted that when the matching position of the keyword reaches the length of the keyword, it means that a matching keyword has been found in the text. Through the above steps, the preset algorithm can be used to quickly find the matching position of the keyword in the text and mark the corresponding named entity.

[0061] In the above steps, the basic principle of the preset algorithm can be to skip characters based on the matching information of the prefix and suffix of the pattern string to improve the matching efficiency. The key of the algorithm is to construct a preprocessing array (also called the partial match table) to store the length of the longest same prefix and suffix before each position in the pattern string.

[0062] In some other examples, other algorithms can also be used to implement the keyword matching process in the above steps. For example, the preset algorithm can also be to achieve jumping matching in the pattern string and the text string through preprocessing information. Different from the preset algorithm introduced above, this preset algorithm mainly depends on the occurrence position of the last character in the pattern string, the bad character rule, and the suffix rule. In practical applications, the preset algorithm can also be the Rabin-Karp algorithm, the Aho-Corasick algorithm, etc., which will not be elaborated here for the time being.

[0063] Here, the advantage of the initial named entity recognition model is that it can effectively find keywords in the text to be recognized, effectively avoid unnecessary comparisons caused by algorithm redundancy in the recognition process of related technologies, and greatly improve the matching efficiency.

[0064] Exemplarily, an initial semantic analysis model is obtained, and the model parameters corresponding to the initial semantic analysis model are obtained by model training under existing open source data. The target training data is then used to adjust the model parameters corresponding to the initial semantic analysis model, so as to obtain a target semantic analysis model suitable for the database query field, thereby improving the recognition accuracy of the target semantic analysis model.

[0065] For example, the initial semantic analysis model can be a large language model based on pre-training, and then the predicates (such as greater than, less than, etc.) used in the target training data to parse the description are used to realize the semantic division of the target training data, so as to use the target training data to adjust the model parameters of the initial semantic analysis model, thereby improving the accuracy of semantic recognition of the target semantic analysis model in the database query field.

[0066] As an optional example, first, the description text and predicates are described from the target training data, and the description text and predicates are preprocessed, including but not limited to text cleaning, word segmentation, encoding, etc. For example, the description text and predicates are segmented and encoded, and the predicates in the target training data are converted from text form to a digital form that can be processed by the model. Then, the preprocessed description text and the corresponding predicate are combined, for example, a special mark such as [SEP] can be used to separate the description text and the predicate to form an input sequence. For example, for a description of "the price of this product is greater than 100 yuan", it can be converted into an input sequence "[CLS] the price of this product [SEP] is greater than [SEP] 100 yuan [SEP]". Finally, the preprocessed description text and predicate are constructed as the input sequence of the initial semantic analysis model, and the output result is obtained through the forward propagation of the initial semantic analysis model, which can be a classification result of the predicate or other forms of semantic understanding results. According to the output result of the initial semantic analysis model, the target training data is semantically divided. According to the classification results of the predicates or other semantic understanding results, the target training data can be divided into different semantic categories, such as "greater than 100 yuan", "less than 100 yuan", etc.

[0067] Further optionally, since training the initial semantic analysis model requires a large amount of computing resources and data, the pre-trained initial semantic analysis model can be fine-tuned to save training costs and time. For example, dynamic masking fine-tuning is used to optimize the initial semantic analysis model. Specifically, during the fine-tuning process, the masking strategy in the pre-training stage is adjusted to better adapt to the target task. For example, for tasks that need to focus on the context, a longer mask length can be used; for tasks that need to focus on local semantics, a shorter mask length can be used. Dynamic adjustment of the masking strategy helps to make full use of the information of the pre-training model and improve the semantic analysis ability of the model. Alternatively, pretraining domain adaptation fine-tuning can also be used to optimize the initial semantic analysis model. When the target domain is significantly different from the pre-training domain, the pre-training domain adaptation fine-tuning method can be used. During the fine-tuning process, some specific data or labels of the target domain are used to further train the model to adapt to the characteristics and semantics of the target domain. This helps to improve the performance and generalization ability of the model in the target domain.

[0068] Exemplarily, an initial relationship extraction model is obtained, and the model parameters corresponding to the initial relationship extraction model are obtained by model training under existing open source data. The target training data is then used to adjust the model parameters corresponding to the initial relationship extraction model, thereby obtaining a target relationship extraction model suitable for the database query field, thereby improving the recognition accuracy of the target relationship extraction model.

[0069] For example, the initial relation extraction model can be a model obtained based on rule training, a statistical model, a machine learning model, etc., and then the target training data is used to identify entities (such as tables, columns, etc.) in the target query statement and the relationships between them (such as one-to-one, one-to-many, etc.) to realize the relational division of the target training data, so as to use the target training data to adjust the model parameters of the initial relation extraction model, thereby improving the accuracy of relation extraction of the target relation extraction model in the database query field.

[0070] For example, a domain interaction model can be used to build an initial relationship extraction model so that the relationship extraction task can be completed through cross-domain matching. Specifically, assume that there are database query statements in two fields, namely the medical field and the financial insurance field. Some identical or similar entities and relationships may appear in the query statements of these two fields, such as "patient", "doctor", "treatment", "cost", "bank", "balance", "compensation", etc. Therefore, the data and annotations of the two fields can be used to train the relationship extraction model at the same time to improve the accuracy of the model in identifying cross-domain entities and relationships.

[0071] First, the data of the two domains need to be preprocessed and feature extracted separately, for example, using text embedding technology to map each query statement into a fixed-length vector expression. Next, the feature vectors of each domain can be fed into different feature extraction models, for example, two different types of feature extraction models are used to learn the relationship extraction tasks of the above two domains. Then, the feature data of the two domain models are interacted to promote the learning of cross-domain features. For example, for each entity pair, an entity pair interaction network (EPIN) can be used to calculate the interaction between the feature vectors in the two domains. The feature vectors of the two entities are used as the input of the EPIN network, and the interaction information is used at multiple levels to generate interaction features between entity pairs. These interaction features include both local interactions between entities and global interactions between them. Then, the entity pair interaction features can be classified to achieve the relationship extraction task. Through this domain interaction model, knowledge and data from different domains can be integrated to train a more comprehensive and robust relationship extraction model, thereby improving the performance of the model in cross-domain tasks. It should be noted that the implementation of the domain interaction model requires consideration of the characteristics and mutual influence of different domains in order to design and adjust the model.

[0072] Exemplarily, before obtaining the target sentence generation model, the input for training the target sentence generation model depends on the entity recognition results, semantic recognition results, and relationship recognition results corresponding to the target naming recognition model, the target semantic analysis model, and the target relationship extraction model, respectively. Then, the target naming recognition model is used to perform entity recognition on the target training data to obtain entity recognition results, the target semantic analysis model is used to perform semantic recognition on the target training data to obtain semantic recognition results, and the target relationship extraction model is used to perform relationship recognition on the target training data to obtain relationship recognition results.

[0073] Exemplarily, an initial sentence generation model is obtained, and the model parameters corresponding to the initial sentence generation model are obtained by model training under existing open source data. The model parameters corresponding to the initial sentence generation model are adjusted using the entity recognition results, semantic recognition results, and relationship recognition results corresponding to the target training data, so as to obtain a target sentence generation model suitable for the database query field, thereby improving the accuracy of sentence generation of the target sentence generation model.

[0074] For example, the initial statement generation model can be constructed based on at least one of a database query statement generation rule algorithm, a row and column value matching algorithm, etc., and then the model parameters of the initial statement generation model are adjusted using the entity recognition results, semantic recognition results, and relationship recognition results corresponding to the target training data, so as to obtain a target statement generation model suitable for the database query field, thereby improving the accuracy of statement generation of the target statement generation model.

[0075] As an optional example, assume that the initial statement generation model can be constructed based on the database query statement generation rule algorithm and the row and column value matching algorithm. Assume that there is a movie information database, which includes the following information: movie name, release time, director, and actor. If the user describes the query requirement as "query movies directed by Zhang and released after 2018", the row and column value matching algorithm can be used to generate the corresponding initial query statement. Based on the above assumptions, first, the user's query requirements need to be mapped to relevant database columns. In this example, the information that the user needs to query includes "movie name", "release time" and "director". Then, an initial query statement template can be constructed based on these query information, such as "query *movies with a release time greater than 2018, and directed by Zhang". Next, the keyword matching method is used to determine the value represented by each query information. This can be obtained by matching row and column values ​​based on the existing movie information table. For example, in the above query statement, the query information may represent the name of the movie and the actor information, because these query information already exist in the columns of the movie information table. Therefore, the row and column value matching algorithm can be used to find the movie name and actor information that match the user's query requirements, and then fill them into the query statement template. Finally, the model parameters of the initial statement generation model can be adjusted using the entity recognition results, semantic recognition results, and relationship recognition results corresponding to the target training data, thereby obtaining a target statement generation model suitable for the database query field and further optimizing the accuracy of the generated query statements. In summary, through this initial statement generation model constructed based on the database query statement generation rule algorithm and the row and column value matching algorithm, users can more conveniently generate query statements that meet query requirements and improve the efficiency and accuracy of database queries.

[0076] Specifically, by obtaining the target naming recognition model, target semantic analysis model, target relationship extraction model and target sentence generation model, the semantic understanding and semantic relationship modeling of the target query sentence input by the user can be deeply performed. The above models can more accurately capture the intention and structure of the user's query, thereby generating more accurate database query sentences. As a result, users of database products can obtain more accurate query results that meet their needs, improving the practicality of the database.

[0077] In some implementations, obtaining the target training data includes: obtaining first training data, and performing data preprocessing on the first training data to obtain second training data; and performing data enhancement on the second training data to obtain target training data.

[0078] For example, in implementing the task of database query statements, data collection is a key step, which involves collecting data required for training and evaluating models related to database query tasks, such as data query pairs corresponding to user query languages ​​and corresponding database query statements. Such data usually needs to include natural language questions, corresponding database architecture and table data, and database query statements corresponding to the questions, etc.

[0079] Exemplarily, a database in a specific field, such as restaurants, academic papers, medical records, etc., is obtained, and natural language questions to be collected are set. The natural language questions should reflect the queries that users may ask, while covering various aspects of the target database, and the natural language questions are converted into database query language, and then the natural language questions and the database query statements corresponding to the natural language questions are used as the first training data.

[0080] Exemplarily, the first training data includes a natural language question and a database query statement corresponding to the natural language question. However, when obtaining the target naming recognition model, the target semantic analysis model and the target semantic analysis model, it is necessary to obtain the corresponding entity names, the relationships between entities and the semantic information in the natural language question. Therefore, the first training data needs to be preprocessed to obtain the corresponding second training data.

[0081] For example, the regular matching method is used to identify the entity names, relationships between entities, and semantic information of the natural language questions in the first training data, so as to obtain the entity names, relationships between entities, and semantic information corresponding to the natural language questions, and then the natural language questions, the entity names, relationships between entities, and semantic information corresponding to the natural language questions, and the database query statements corresponding to the natural language questions are used as the second training data.

[0082] For example, after obtaining the second training data, the data volume corresponding to the second training data may not meet the actual training needs. In this case, a generative model can be used to generate new sentences, or existing sentences can be recombined to generate new sentences to achieve the purpose of enhancing the second training data, thereby obtaining the target training data.

[0083] In some embodiments, the first training data includes an initial query text, and the first training data is obtained, and data preprocessing is performed on the first training data to obtain the second training data, including: performing keyword recognition on the initial query text to obtain keywords corresponding to the initial query text, and converting the keywords into corresponding database instructions; performing database information recognition on the initial query text to obtain database entity information corresponding to the initial query text; performing semantic analysis on the initial query text to obtain the query purpose corresponding to the initial query text; determining a database query command corresponding to the initial query text according to the database instruction, the database entity information and the query purpose; and determining the second training data according to the initial query text and the database query command.

[0084] Exemplarily, the first training data includes an initial query text, which is a natural language question, in other words, a query text corresponding to when a user performs a database query.

[0085] Exemplarily, the initial query text is identified by regular matching to obtain keywords corresponding to the initial query text, and then the keywords are converted to correspond to database instructions in the database.

[0086] For example, regular matching is used to identify keywords in the initial query text, such as "select", "from", "where", "group by", etc. These keywords can be used to understand the structure and intent of the initial query text. Then, instruction construction is performed to convert the identified keywords into corresponding database instructions. For example, the "select" keyword can be converted into a "SELECT" instruction, and the "from" keyword can be converted into a "FROM" instruction.

[0087] For example, database information recognition for the initial query text requires identifying the table name, column name, and database name involved in the initial query text, and the database entity information corresponding to the initial query text can be obtained through part-of-speech tagging, named entity recognition, and other technologies. In addition, in order to ensure the uniformity of database entity information, the identified entities can also be mapped to the corresponding database tables and columns.

[0088] Exemplarily, a regular matching method is used to obtain a verb or predicate corresponding to the initial query text, and then the verb or predicate is mapped to obtain a query purpose corresponding to the initial query text.

[0089] For example, identify the predicates (such as greater than, less than, etc.) in the initial query text and convert them into corresponding query purposes, such as comparing sizes; identify the aggregation operations (such as sum, count, etc.) in the initial query text and convert them into corresponding query purposes, such as data aggregation; identify the grouping and sorting requirements in the initial query text and convert them into corresponding query purposes, such as data sorting. For example, "group by age" can be converted to "GROUP BY age", and "sort by age in ascending order" can be converted to "ORDER BY age ASC".

[0090] In addition, if it is identified that the data type involved in the initial query text does not match the data type in the database and the corresponding data type conversion is required, the corresponding query purpose can also be set as data type conversion. For example, the string in the initial query text is converted to the VARCHAR type in the database. Then, by performing semantic information on the initial query text, the purpose of the initial query text can be better obtained.

[0091] Exemplarily, after obtaining the database instruction, database entity information and query purpose, the database instruction, database entity information and query purpose are converted into corresponding database query commands according to the set rules; and then the database query command corresponding to the initial query text is obtained. Finally, the second training data is obtained according to the database entity information corresponding to the initial query text, the query purpose and the database query command corresponding to the initial query text.

[0092] In some embodiments, performing data enhancement on the second training data to obtain target training data includes: obtaining synonyms corresponding to keywords in the second training data; replacing the keywords in the second training data with corresponding synonyms to obtain third training data; determining target vocabulary, and deleting or inserting the target vocabulary in the third training data to obtain fourth training data; performing context relationship analysis on the fourth training data to obtain missing information corresponding to the fourth training data, and then supplementing the fourth training data according to the missing information to obtain the target training data.

[0093] For example, in order to ensure the generalization and robustness of the target naming recognition model, the target semantic analysis model, the target relationship extraction model, and the target sentence generation model, so as to achieve better conversion between the target query text and the target query sentence, due to the limited amount of the second training data, if the second training data is directly used for training, the effect is often not good. In addition, the second training data can be enhanced to obtain a large amount of rich target training data by increasing the diversity of the data to improve the generalization and robustness of the above models.

[0094] Exemplarily, synonyms corresponding to keywords in the second training data are obtained with the help of an existing synonym dictionary or word vector, and then new query statements are generated by synonym replacement to obtain third training data. The third training data includes the second training data and the data after synonym replacement of the second training data, thereby increasing the diversity of query statements in the second training data and providing support for subsequent improvement of the generalization ability of each model.

[0095] Exemplarily, target vocabulary is determined, including articles, prepositions and other vocabulary that do not affect semantics, and then the corresponding target vocabulary is randomly inserted or deleted in the query statement in the third training data, so as to obtain the fourth training data, thereby increasing the randomness of the fourth training data, providing support for subsequently improving the robustness of each model.

[0096] Exemplarily, by performing contextual relationship analysis on the fourth training data, the missing information corresponding to the fourth training data is obtained, and the missing information is added to the missing position corresponding to the fourth training data, such as the preceding text, the succeeding text, etc., so as to achieve the purpose of enriching the information of the fourth training data, thereby obtaining the target training data. The diversity of the target training data is then increased, providing support for subsequently improving the generalization ability of each model.

[0097] Step S105: perform data query in the database according to the target query statement to obtain a target query result corresponding to the target query text.

[0098] Exemplarily, the target query statement is run in the database to implement data query, thereby obtaining the target query result corresponding to the target query text.

[0099] Optionally, the method for performing data query in the database by the target query statement can be executed with the help of java commands or python commands, etc., or it can be executed directly in the database. This application does not make specific restrictions, and users can set it according to actual needs.

[0100] In some implementations, the target query statement is used to perform a data query in the database to obtain a target query result corresponding to the target query text, and the target query result is obtained by referring to Figure 2 , step S105 includes: sub-step S1051 to sub-step S1053.

[0101] Sub-step S1051: perform sentence detection on the target query sentence according to the rule to obtain a detection result.

[0102] Exemplarily, the target query statement is detected according to the query rules of the database. When the target query statement meets the rules, the detection result is that the statement is normal; when the target query statement does not meet the rules, the detection result is that the statement is abnormal.

[0103] Exemplarily, when detecting whether the target query statement satisfies the rules, a regular matching method can be used to query, thereby obtaining the detection result corresponding to the target query statement. The purpose of performing statement detection on the target query statement according to the rules is to ensure that the generated target query statement is valid and complies with the syntax and semantic rules of the database.

[0104] Sub-step S1052: When the detection result is that the statement is abnormal, the target query statement is corrected and the target query statement is updated.

[0105] Exemplarily, when the detection result is that the statement is abnormal, it indicates that the target query statement does not meet the query rules of the database. Then, the part of the target query statement that does not meet the query rules is obtained according to the query rules, and then the part is adjusted according to the query rules, so as to correct the target query statement, obtain the corrected result, and then update the corrected result to the target query statement.

[0106] Exemplarily, a database generation template and a grammar generation template are established to detect and repair errors in the generated target query statements, thereby improving the accuracy of the target query statements.

[0107] Sub-step S1053: performing data query in the database according to the updated target query statement to obtain a target query result corresponding to the target query text.

[0108] Exemplarily, the updated target query statement is run in the database to implement data query, thereby obtaining the target query result corresponding to the target query text.

[0109] Optionally, the method for performing data query in the database by the updated target query statement can be executed with the help of java commands or python commands, etc., or it can be executed directly in the database. This application does not make specific restrictions, and users can set it according to actual needs.

[0110] In some embodiments, when the detection result is a sentence anomaly, it also includes: storing the target query text and the updated target query statement in a target database, and accumulating and calculating the storage quantity corresponding to the target query text and the updated target query statement; when the storage quantity is greater than or equal to a preset quantity, updating the model parameters corresponding to the target naming recognition model, the target semantic analysis model, the target relationship extraction model, and the target sentence generation model.

[0111] Exemplarily, the target query text and the updated target query statement are stored in the target database, and then when the storage quantity corresponding to the stored data in the target database is greater than or equal to the preset quantity, the model parameters corresponding to the target naming recognition model, the target semantic analysis model, the target relationship extraction model, and the target sentence generation model are updated according to the updated target query statement stored in the target database, thereby improving the recognition accuracy of each model. Then, the purpose of adjusting and optimizing the database query method according to user feedback is achieved. Then, the accuracy of the output target query statement is further improved.

[0112] In addition, the adjusted target naming recognition model, target semantic analysis model, target relationship extraction model, and target sentence generation model are saved as corresponding model files that can be used for reasoning. Model files usually include but are not limited to: model architecture, weight parameters, necessary auxiliary functions, and select an appropriate deployment environment, which can be a local server, a virtual machine instance of a cloud service provider (such as AWS, Azure, Google Cloud, etc.), or a containerized image (such as Docker); set the required dependencies in the deployment environment, including model libraries, frameworks, Python environments, and other necessary libraries; load the saved target naming recognition model, target semantic analysis model, target relationship extraction model, and target sentence generation model corresponding model files in the deployment environment for reasoning. Since each model usually involves using a deep learning framework (such as TensorFlow, PyTorch) to load the model weights; use the loaded model for reasoning, pass the target query text to the model to obtain the corresponding target query sentence. Among them, in the process of converting the target query text into the target query sentence, according to the design of the model, it can be a form of batch processing of the target query text or processing of a single target query text.

[0113] The present application obtains a target query text, and performs entity recognition on the target query text according to a target naming recognition model to obtain a target entity; performs semantic recognition on the target query text according to a target semantic analysis model to obtain a target semantic; performs relationship extraction on the target query text according to a target relationship extraction model to obtain a target relationship; and then determines a target query statement corresponding to the target query text using a target statement generation model according to the target entity, target semantics, and target relationship; and finally performs a data query in a database according to the target query statement to obtain a target query result corresponding to the target query text. In the present application, the target semantic analysis model is used to more accurately capture the intent and structure of the user's query, thereby generating a more accurate target query statement, so that the user can obtain more accurate query results that meet their needs, thereby improving the practicality of the database query method.

[0114] In addition, when obtaining each model, the methods of transfer learning and pre-training models can be used to enable the database query method to perform well in different fields. This allows the database query method to cover multiple fields, meet the query needs of different industries and users, and expand the application scope of the database. Introducing the target semantic analysis model into the database query method, detecting sentence anomalies to realize the user feedback loop and continuously updating the parameters of each model in the database query method can improve the accuracy of database queries, thereby allowing users to interact with the database more easily. Modifying and adjusting the parameters of each model can gradually improve the performance of the database query method, thereby improving user satisfaction and making users more willing to use the product.

[0115] Finally, due to the improvement of query accuracy in the database query method, users can easily perform database queries without having to deeply understand the database syntax, which lowers the threshold for using the database and reduces the user's learning cost, allowing more non-technical users to make full use of the method for database query and analysis. In addition, due to the improvement of query accuracy in the database query method, users can also obtain the required information more quickly, improve work efficiency and decision-making effectiveness, thereby enhancing the commercial value of the method.

[0116] See also Figure 3 , Figure 3 A database query device 200 is provided in an embodiment of the present application. The database query device 200 includes an entity acquisition module 201, a semantic acquisition module 202, a relationship acquisition module 203, a sentence acquisition module 204 and a result acquisition module 205, wherein the entity acquisition module 201 is used to obtain a target query text, and perform entity recognition on the target query text according to a target naming recognition model to obtain a target entity; the semantic acquisition module 202 is used to perform semantic recognition on the target query text according to a target semantic analysis model to obtain a target semantic; the relationship acquisition module 203 is used to perform relationship extraction on the target query text according to a target relationship extraction model to obtain a target relationship; the sentence acquisition module 204 is used to determine a target query sentence corresponding to the target query text according to the target entity, the target semantic and the target relationship using a target sentence generation model; the result acquisition module 205 is used to perform data query in the database according to the target query sentence to obtain a target query result corresponding to the target query text.

[0117] In some implementations, the database query device 200 further performs the following steps before obtaining the target query text:

[0118] Obtain target training data, and adjust an initial naming recognition model according to the target training data to obtain a target naming recognition model, adjust an initial semantic analysis model according to the target training data to obtain a target semantic analysis model, and adjust an initial relation extraction model according to the target training data to obtain a target relation extraction model;

[0119] Perform entity recognition on the target training data according to the target naming recognition model to obtain an entity recognition result, perform semantic recognition on the target training data according to the target semantic analysis model to obtain a semantic recognition result, and perform relationship recognition on the target training data according to the target relationship extraction model to obtain a relationship recognition result;

[0120] The initial sentence generation model is adjusted according to the entity recognition result, the semantic recognition result and the relationship recognition result to obtain the target sentence generation model.

[0121] In some implementations, the database query device 200 performs the following steps in the process of obtaining target training data:

[0122] Obtaining first training data, and performing data preprocessing on the first training data to obtain second training data;

[0123] Perform data enhancement on the second training data to obtain target training data.

[0124] In some implementations, the first training data includes an initial query text. When obtaining the first training data and performing data preprocessing on the first training data to obtain the second training data, the database query device 200 executes:

[0125] Perform keyword recognition on the initial query text to obtain keywords corresponding to the initial query text, and convert the keywords into corresponding database instructions;

[0126] Performing database information identification on the initial query text to obtain database entity information corresponding to the initial query text;

[0127] Performing semantic analysis on the initial query text to obtain a query purpose corresponding to the initial query text;

[0128] Determine a database query command corresponding to the initial query text according to the database instruction, the database entity information and the query purpose;

[0129] The second training data is determined according to the initial query text and the database query command.

[0130] In some implementations, the database query device 200 performs the following steps when performing data enhancement on the second training data to obtain target training data:

[0131] Obtaining synonyms corresponding to the keywords in the second training data;

[0132] Replacing the keywords in the second training data with the corresponding synonyms to obtain third training data;

[0133] Determine a target vocabulary, and delete or insert the target vocabulary into the third training data to obtain fourth training data;

[0134] A context analysis is performed on the fourth training data to obtain missing information corresponding to the fourth training data, and then the fourth training data is supplemented according to the missing information to obtain the target training data.

[0135] In some implementations, the result acquisition module 205 performs, in the process of performing a data query in the database according to the target query statement to obtain a target query result corresponding to the target query text, the following steps:

[0136] Perform sentence detection on the target query sentence according to the rule to obtain a detection result;

[0137] When the detection result is that the statement is abnormal, the target query statement is corrected and the target query statement is updated;

[0138] A data query is performed in the database according to the updated target query statement to obtain a target query result corresponding to the target query text.

[0139] In some implementations, when the detection result is that the statement is abnormal, the result acquisition module 205 further executes:

[0140] The target query text and the updated target query statement are stored in a target database, and the storage quantities corresponding to the target query text and the updated target query statement are cumulatively calculated;

[0141] When the storage quantity is greater than or equal to a preset quantity, model parameters corresponding to the target naming recognition model, the target semantic analysis model, the target relationship extraction model, and the target sentence generation model are updated.

[0142] In some implementations, the database query device 200 may be applied to a terminal device.

[0143] It should be noted that those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working process of the database query device 200 described above can refer to the corresponding process in the aforementioned database query method embodiment, and will not be repeated here.

[0144] See also Figure 4 , Figure 4 A schematic block diagram of the structure of a terminal device provided in an embodiment of the present application.

[0145] like Figure 4 As shown, the terminal device 300 includes a processor 301 and a memory 302 , and the processor 301 and the memory 302 are connected via a bus 303 , such as an I2C (Inter-integrated Circuit) bus.

[0146] Specifically, the processor 301 is used to provide computing and control capabilities to support the operation of the entire terminal device. The processor 301 can be a central processing unit (CPU), and the processor 301 can also be other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), field-programmable gate arrays (FPGA) or other programmable logic devices, discrete gates or transistor logic devices, discrete hardware components, etc. Among them, the general-purpose processor can be a microprocessor or the processor can also be any conventional processor, etc.

[0147] Specifically, the memory 302 may be a Flash chip, a read-only memory (ROM) disk, an optical disk, a USB flash drive, or a mobile hard disk.

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

[0149] The processor is used to run a computer program stored in the memory, and implement any one of the database query methods provided in the embodiments of the present application when executing the computer program.

[0150] In one embodiment, the processor is used to run a computer program stored in the memory, and implements the following steps when executing the computer program:

[0151] Obtain a target query text, and perform entity recognition on the target query text according to a target naming recognition model to obtain a target entity;

[0152] Performing semantic recognition on the target query text according to the target semantic analysis model to obtain target semantics;

[0153] Performing relation extraction on the target query text according to the target relation extraction model to obtain the target relation;

[0154] Determine a target query sentence corresponding to the target query text by using a target sentence generation model according to the target entity, the target semantics, and the target relationship;

[0155] A data query is performed in the database according to the target query statement to obtain a target query result corresponding to the target query text.

[0156] In some implementations, the processor 301, before obtaining the target query text, further executes:

[0157] Obtain target training data, and adjust an initial naming recognition model according to the target training data to obtain a target naming recognition model, adjust an initial semantic analysis model according to the target training data to obtain a target semantic analysis model, and adjust an initial relation extraction model according to the target training data to obtain a target relation extraction model;

[0158] Perform entity recognition on the target training data according to the target naming recognition model to obtain an entity recognition result, perform semantic recognition on the target training data according to the target semantic analysis model to obtain a semantic recognition result, and perform relationship recognition on the target training data according to the target relationship extraction model to obtain a relationship recognition result;

[0159] The initial sentence generation model is adjusted according to the entity recognition result, the semantic recognition result and the relationship recognition result to obtain the target sentence generation model.

[0160] In some implementations, the processor 301 executes, during the process of obtaining the target training data:

[0161] Obtaining first training data, and performing data preprocessing on the first training data to obtain second training data;

[0162] Perform data enhancement on the second training data to obtain target training data.

[0163] In some implementations, the first training data includes an initial query text. When the processor 301 obtains the first training data and performs data preprocessing on the first training data to obtain the second training data, the processor 301 executes:

[0164] Perform keyword recognition on the initial query text to obtain keywords corresponding to the initial query text, and convert the keywords into corresponding database instructions;

[0165] Performing database information identification on the initial query text to obtain database entity information corresponding to the initial query text;

[0166] Performing semantic analysis on the initial query text to obtain a query purpose corresponding to the initial query text;

[0167] Determine a database query command corresponding to the initial query text according to the database instruction, the database entity information and the query purpose;

[0168] The second training data is determined according to the initial query text and the database query command.

[0169] In some implementations, the processor 301 performs, when performing data enhancement on the second training data to obtain target training data:

[0170] Obtaining synonyms corresponding to the keywords in the second training data;

[0171] Replacing the keywords in the second training data with the corresponding synonyms to obtain third training data;

[0172] Determine a target vocabulary, and delete or insert the target vocabulary into the third training data to obtain fourth training data;

[0173] A context analysis is performed on the fourth training data to obtain missing information corresponding to the fourth training data, and then the fourth training data is supplemented according to the missing information to obtain the target training data.

[0174] In some implementations, the processor 301 performs, in the process of performing a data query in the database according to the target query statement to obtain a target query result corresponding to the target query text:

[0175] Perform sentence detection on the target query sentence according to the rule to obtain a detection result;

[0176] When the detection result is that the statement is abnormal, the target query statement is corrected and the target query statement is updated;

[0177] A data query is performed in the database according to the updated target query statement to obtain a target query result corresponding to the target query text.

[0178] In some implementations, when the detection result is that the statement is abnormal, the processor 301 further executes:

[0179] The target query text and the updated target query statement are stored in a target database, and the storage quantities corresponding to the target query text and the updated target query statement are cumulatively calculated;

[0180] When the storage quantity is greater than or equal to a preset quantity, model parameters corresponding to the target naming recognition model, the target semantic analysis model, the target relationship extraction model, and the target sentence generation model are updated.

[0181] It should be noted that those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working process of the terminal device described above can refer to the corresponding process in the aforementioned database query method embodiment, and will not be repeated here.

[0182] An embodiment of the present application also provides a storage medium for computer-readable storage, wherein the storage medium stores one or more programs, and the one or more programs can be executed by one or more processors to implement the steps of any database query method provided in the description of the embodiment of the present application.

[0183] The storage medium may be an internal storage unit of the terminal device described in the foregoing embodiment, such as a hard disk or memory of the terminal device. The storage medium may also be an external storage device of the terminal device, such as a plug-in hard disk, a smart memory card (Smart Media Card, SMC), a secure digital (SecureDigital, SD) card, a flash card (Flash Card), etc., equipped on the terminal device.

[0184] It will be appreciated by those skilled in the art that all or some of the steps, systems, and functional modules / units in the methods disclosed above may be implemented as software, firmware, hardware, and appropriate combinations thereof. In a hardware embodiment, the division between the functional modules / units mentioned in the above description does not necessarily correspond to the division of physical components; for example, a physical component may have multiple functions, or a function or step may be performed by several physical components in cooperation. Some or all physical components may be implemented as software executed by a processor, such as a central processing unit, a digital signal processor, or a microprocessor, or implemented as hardware, or implemented as an integrated circuit, such as an application-specific integrated circuit. Such software may be distributed on a computer-readable medium, which may include a computer storage medium (or non-transitory medium) and a communication medium (or transient medium). As is known to those skilled in the art, the term computer storage medium includes volatile and non-volatile, removable and non-removable media implemented in any method or technology for storing information (such as computer-readable instructions, data structures, program modules, or other data). Computer storage media include, but are not limited to, RAM, ROM, EEPROM, flash memory or other memory technology, CD-ROM, digital versatile disks (DVD) or other optical disk storage, magnetic cassettes, magnetic tapes, magnetic disk storage or other magnetic storage devices, or any other medium that can be used to store the desired information and can be accessed by a computer. In addition, it is well known to those skilled in the art that communication media typically contain computer-readable instructions, data structures, program modules, or other data in a modulated data signal such as a carrier wave or other transport mechanism, and may include any information delivery media.

[0185] It should be understood that the term "and / or" used in the specification of this application and the appended claims refers to any combination of one or more of the associated listed items and all possible combinations, including these combinations. It should be noted that, in this article, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or system including a series of elements includes not only those elements, but also includes other elements not explicitly listed, or also includes elements inherent to such process, method, article or system. In the absence of further restrictions, an element defined by the sentence "including a..." does not exclude the presence of other identical elements in the process, method, article or system including the element.

[0186] The serial numbers of the embodiments of the present application are only for description and do not represent the advantages and disadvantages of the embodiments. The above are only specific embodiments of the present application, but the protection scope of the present application is not limited thereto. Any technician familiar with the technical field can easily think of various equivalent modifications or replacements within the technical scope disclosed in the present application, and these modifications or replacements should be included in the protection scope of the present application. Therefore, the protection scope of the present application shall be based on the protection scope of the claims.

Claims

1. A method for querying a database, characterized in that: The method comprises: Obtain a target query text, and perform entity recognition on the target query text according to a target naming recognition model to obtain a target entity, including: setting the target query text, and using the target naming recognition model to recognize the corresponding target entity in the target query text; the entity type of the target entity includes at least one of the following: database name, table name, column name, keyword; the preset algorithm adopted by the target naming recognition model is obtained by skipping characters based on the matching information of the prefix and suffix of the pattern string; the key to the preset algorithm is to construct a preprocessing array to store the length of the longest identical prefix and suffix before each position in the pattern string; the preset algorithm realizes the jump matching between the pattern string and the text string by preprocessing information; the preset algorithm depends on the appearance position of the last character in the pattern string, the bad character rule and the suffix rule; The target query text is semantically identified according to the target semantic analysis model to obtain the target semantics, including: using the target semantic analysis model to classify the query intent of the target query text to identify the query intent corresponding to the target query text; decomposing the target query text into multiple subtasks according to key information in the query intent; executing the multiple subtasks to obtain the target semantics; According to the target relationship extraction model, the target query text is subjected to relationship extraction to obtain the target relationship; wherein the target relationship includes the dependency relationship and / or restriction relationship between the target entities in the target query text; the target relationship extraction model is constructed using the domain interaction model; wherein, for each entity pair from two different domains, the feature vectors of the two entities are used as the input of the entity pair interaction network EPIN, and the interaction information is used at multiple levels to generate the interaction features between the entity pairs, and the interaction features between the entity pairs include the local interaction and the global interaction between the entities; the interaction features between the entity pairs are classified to achieve the relationship extraction task; The target query sentence corresponding to the target query text is determined by using a target sentence generation model according to the target entity, the target semantics and the target relationship; wherein the target sentence generation model is constructed based on a database query sentence generation rule algorithm and a row-column value matching algorithm; the target sentence generation model is obtained by adjusting model parameters using entity recognition results, semantic recognition results and relationship recognition results corresponding to target training data, so that the target sentence generation model is adjusted to be suitable for the database query field; the target training data is obtained by generating new sentences using a generation model, or by recombining and combining existing sentences to generate new sentences, and is used to achieve training data enhancement of the target training data; A data query is performed in the database according to the target query statement to obtain a target query result corresponding to the target query text.

2. The method according to claim 1, characterized in that: Before obtaining the target query text, the method further includes: Obtain target training data, and adjust an initial naming recognition model according to the target training data to obtain a target naming recognition model, adjust an initial semantic analysis model according to the target training data to obtain a target semantic analysis model, and adjust an initial relation extraction model according to the target training data to obtain a target relation extraction model; Perform entity recognition on the target training data according to the target naming recognition model to obtain an entity recognition result, perform semantic recognition on the target training data according to the target semantic analysis model to obtain a semantic recognition result, and perform relationship recognition on the target training data according to the target relationship extraction model to obtain a relationship recognition result; The initial sentence generation model is adjusted according to the entity recognition result, the semantic recognition result and the relationship recognition result to obtain the target sentence generation model.

3. The method according to claim 2, characterized in that The obtaining of target training data comprises: Obtaining first training data, and performing data preprocessing on the first training data to obtain second training data; Perform data enhancement on the second training data to obtain target training data.

4. The method according to claim 3, characterized in that The first training data includes an initial query text. The first training data is obtained, and data preprocessing is performed on the first training data to obtain second training data, including: Perform keyword recognition on the initial query text to obtain keywords corresponding to the initial query text, and convert the keywords into corresponding database instructions; Performing database information identification on the initial query text to obtain database entity information corresponding to the initial query text; Performing semantic analysis on the initial query text to obtain a query purpose corresponding to the initial query text; Determine a database query command corresponding to the initial query text according to the database instruction, the database entity information and the query purpose; The second training data is determined according to the initial query text and the database query command.

5. The method according to claim 3, characterized in that: The performing data enhancement on the second training data to obtain target training data includes: Obtaining synonyms corresponding to the keywords in the second training data; Replacing the keywords in the second training data with the corresponding synonyms to obtain third training data; Determine a target vocabulary, and delete or insert the target vocabulary into the third training data to obtain fourth training data; A context analysis is performed on the fourth training data to obtain missing information corresponding to the fourth training data, and then the fourth training data is supplemented according to the missing information to obtain the target training data.

6. The method according to claim 1, characterized in that The step of performing a data query in the database according to the target query statement to obtain a target query result corresponding to the target query text includes: Perform sentence detection on the target query sentence according to the rule to obtain a detection result; When the detection result is that the statement is abnormal, the target query statement is corrected and the target query statement is updated; A data query is performed in the database according to the updated target query statement to obtain a target query result corresponding to the target query text.

7. The method according to claim 6, characterized in that When the detection result is that the sentence is abnormal, the method further includes: The target query text and the updated target query statement are stored in a target database, and the storage quantities corresponding to the target query text and the updated target query statement are cumulatively calculated; When the storage quantity is greater than or equal to a preset quantity, model parameters corresponding to the target naming recognition model, the target semantic analysis model, the target relationship extraction model, and the target sentence generation model are updated.

8. A database query device, characterized in that: include: An entity acquisition module is used to obtain a target query text, and to perform entity recognition on the target query text according to a target naming recognition model to obtain a target entity; wherein the entity acquisition module is configured to: set the target query text, and use the target naming recognition model to recognize the corresponding target entity in the target query text; the entity type of the target entity includes at least one of the following: database name, table name, column name, keyword; the preset algorithm adopted by the target naming recognition model is obtained by skipping characters based on the matching information of the prefix and suffix of the pattern string; the key to the preset algorithm is to construct a preprocessing array to store the length of the longest identical prefix and suffix before each position in the pattern string; the preset algorithm realizes the jump matching between the pattern string and the text string by preprocessing information; the preset algorithm depends on the appearance position of the last character in the pattern string, the bad character rule and the suffix rule; A semantic acquisition module, used for performing semantic recognition on the target query text according to the target semantic analysis model to obtain target semantics; wherein the semantic acquisition module is configured to: perform query intent classification on the target query text using the target semantic analysis model to identify the query intent corresponding to the target query text; decompose the target query text into multiple subtasks according to key information in the query intent; and execute multiple subtasks to obtain the target semantics; A relationship acquisition module is used to extract the target relationship from the target query text according to the target relationship extraction model; wherein the target relationship includes the dependency relationship and / or restriction relationship between the target entities in the target query text; the target relationship extraction model is constructed using a domain interaction model; wherein, for each entity pair from two different domains, the feature vectors of the two entities are used as the input of the entity pair interaction network EPIN, and the interaction information is used at multiple levels to generate the interaction features between the entity pairs, and the interaction features between the entity pairs include the local interaction and the global interaction between the entities; the interaction features between the entity pairs are classified to achieve the relationship extraction task; A sentence acquisition module is used to determine the target query sentence corresponding to the target query text using a target sentence generation model according to the target entity, the target semantics and the target relationship; the target sentence generation model is constructed based on a database query sentence generation rule algorithm and a row and column value matching algorithm; the target sentence generation model is obtained by adjusting model parameters using entity recognition results, semantic recognition results and relationship recognition results corresponding to target training data, so that the target sentence generation model is adjusted to be suitable for the database query field; the target training data is obtained by generating new sentences using a generation model, or by recombining and combining existing sentences to generate new sentences, and is used to achieve training data enhancement of the target training data; The result acquisition module is used to perform data query in the database according to the target query statement to obtain the target query result corresponding to the target query text.

9. A terminal device, characterized in that: The terminal device includes a processor and a memory; The memory is used to store computer programs; The processor is configured to execute the computer program and implement the database query method according to any one of claims 1 to 7 when executing the computer program.

10. A computer storage medium for computer storage, characterized in that: The computer storage medium stores one or more programs, and the one or more programs can be executed by one or more processors to implement the steps of the database query method described in any one of claims 1 to 7.