Intelligent database syntax parsing method based on LSTM and TRM

The intelligent database grammar parsing method integrates LSTM and TRM to address the limitations of traditional and deep learning-based parsing methods, improving SQL statement understanding and accuracy.

CN117992068BActive Publication Date: 2024-12-03TIANJIN NANKAI UNIV GENERAL DATA TECH
View PDF 11 Cites 0 Cited by

Patent Information

Application Number
CN202410390606.4
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-04-02
Publication Date
2024-12-03
Estimated Expiration
2044-04-02

AI Technical Summary

Technical Problem

Traditional parsing methods for database query statements, such as those based on rules and pattern matching, struggle with complex SQL statements, while deep learning models like LSTM and TRM have limitations in understanding semantics and structure, leading to low accuracy and performance issues.

Method used

An intelligent database grammar parsing method combining LSTM and TRM, involving preprocessing, feature extraction, sequence modeling, and output generation, to leverage the strengths of both models for improved parsing accuracy.

Benefits of technology

The combined method effectively captures timing information and syntax structure in SQL statements, enhancing parsing accuracy and supporting intelligent database development.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN117992068B_ABST
    Figure CN117992068B_ABST
Patent Text Reader

Abstract

The present invention provides an intelligent database syntax parsing method combining LSTM and TRM, the method is implemented by an intelligent database syntax parsing system, the intelligent database syntax parsing system includes an input module, a preprocessing module, a feature extraction module, a sequence modeling module and an output module, the input module is sequentially connected to the output module through the preprocessing module, the feature extraction module and the sequence modeling module. Beneficial effects of the present invention: This method combines the advantages of LSTM and TRM, can better capture the timing information and grammatical structure in SQL statements, and improves the parsing accuracy. Through the pre-trained LSTM model and self-attention mechanism, the method can quickly and accurately parse SQL statements, providing strong support for the development of intelligent databases.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention belongs to the field of artificial intelligence and natural language processing, and in particular relates to an intelligent database grammar parsing method combining LSTM and TRM. Background Art

[0002] With the advent of the big data era, the parsing of database query statements is particularly important. Traditional parsing methods are mainly based on rules and pattern matching, which cannot process complex SQL statements and have low accuracy. However, methods based on deep learning can automatically learn grammatical rules and improve parsing accuracy. Among them, LSTM and TRM (Transformer) are two common deep learning models, but using them alone cannot completely solve the problem of SQL statement parsing. Specifically, the TRM model alone cannot understand the semantics and structure of SQL well, and the LSTM model has disadvantages in parallel capabilities. Preliminary analysis and understanding of a large number of SQLs will lead to performance disadvantages. Summary of the invention

[0003] In view of this, the present invention aims to propose an intelligent database grammar parsing method combining LSTM and TRM to solve the problems existing in the above-mentioned prior art, and combine the two models of LSTM and TRM to complement each other and improve the parsing effect.

[0004] To achieve the above object, the technical solution of the present invention is achieved as follows:

[0005] An intelligent database grammar parsing method combining LSTM and TRM, the method is implemented by an intelligent database grammar parsing system, the intelligent database grammar parsing system includes an input module, a preprocessing module, a feature extraction module, a sequence modeling module and an output module, the input module is sequentially connected to the output module through the preprocessing module, the feature extraction module, and the sequence modeling module;

[0006] The method comprises the following steps:

[0007] S1, preprocessing the input data based on the preprocessing module;

[0008] S2, using the TRM model based on the feature extraction module to perform preliminary analysis on the data pre-processed in step S1;

[0009] S3, using the LSTM model based on the sequence modeling module to further analyze the data after the preliminary analysis in step S2;

[0010] S4, generating a query plan for the data further analyzed in step S3;

[0011] In step S1, the input data is preprocessed, including the following steps:

[0012] S11, cleaning the input data;

[0013] S12, performing text conversion on the cleaned data;

[0014] S13, extracting features from the data after text conversion;

[0015] S14, dividing the data after feature extraction.

[0016] Furthermore, in step S11, data cleaning is performed on the input data, including the following steps:

[0017] S111, removing duplicate data from input data;

[0018] S112, processing missing values ​​of the data in step S111;

[0019] S113, correcting the data error value in step S112 to obtain cleaned data.

[0020] Furthermore, in step S12, the text conversion of the cleaned data includes the following steps:

[0021] S121, initializing the cleaned data: setting the dictionary and the maximum word length;

[0022] S122, scanning the data of step S122: scanning the text to be segmented from left to right;

[0023] S123, matching the data in step S123: try to match with the words in the dictionary starting from the current position, first try the word with the longest word length, if the match is successful, split out a word, and continue to match from the next position of the word; if the match fails, try the next shorter word, until a matching word is found or the word length is reduced to 1;

[0024] S124, continue scanning: repeat step S123 until the entire text is scanned to obtain text-converted data.

[0025] Furthermore, in step S13, feature extraction is performed on the data after text conversion, including the following steps:

[0026] S131, statistical features of the converted text data: calculating the length, number of words, and number of sentences of the text;

[0027] S132, obtaining semantic features from the data after text conversion;

[0028] S133, obtaining structural features of the data after text conversion;

[0029] S134, obtaining context features from the text-converted data.

[0030] Furthermore, in step S2, the preprocessed data is preliminarily analyzed using the TRM model, including:

[0031] S21, TRM model performs data embedding on the preprocessed data;

[0032] S22, the TRM model uses the self-attention mechanism to process the data in step S21;

[0033] S23, the TRM model uses the encoder layer to process the data of step S22;

[0034] S24, the TRM model uses the decoder layer to process the data of step S23:

[0035] S25. The TRM model outputs the data of step S24.

[0036] Furthermore, in step S22, the calculation method of the self-attention mechanism includes the following steps:

[0037] S221, first use the query Query and the key Key to calculate the weight coefficient, and then use the SoftMax operation to normalize the weight;

[0038] S222. Perform weighted summation on the Value using the weight-normalized data in step S221 to calculate the output of the attention.

[0039] Furthermore, in step S3, the LSTM model is used to further analyze the data after the preliminary analysis, including the following steps:

[0040] S31, preprocessing of data after preliminary analysis based on LSTM model;

[0041] S32, using the TRM model to perform entity recognition on the data of step S31 based on the LSTM model;

[0042] S33. Construct a parse tree for the data in step S32 based on the LSTM model to obtain data after further analysis.

[0043] Compared with the prior art, the intelligent database grammar parsing method combining LSTM and TRM described in the present invention has the following advantages:

[0044] The LSTM and TRM combined intelligent database syntax parsing method of the present invention combines the advantages of LSTM and TRM, can better capture the timing information and syntax structure in SQL statements, and improve the parsing accuracy. Through the pre-trained LSTM model and self-attention mechanism, the method can quickly and accurately parse SQL statements, providing strong support for the development of intelligent databases. BRIEF DESCRIPTION OF THE DRAWINGS

[0045] The accompanying drawings constituting a part of the present invention are used to provide a further understanding of the present invention. The exemplary embodiments of the present invention and their descriptions are used to explain the present invention and do not constitute an improper limitation of the present invention. In the accompanying drawings:

[0046] Figure 1 This is a schematic diagram of the principle of the intelligent database grammar parsing system according to an embodiment of the present invention;

[0047] Figure 2 This is a schematic diagram of the preprocessing process according to an embodiment of the present invention;

[0048] Figure 3 This is a schematic diagram of the attention mechanism principle described in an embodiment of the present invention;

[0049] Figure 4 The figure is a schematic diagram of the structure of a codec according to an embodiment of the present invention. DETAILED DESCRIPTION

[0050] It should be noted that, in the absence of conflict, the embodiments of the present invention and the features in the embodiments may be combined with each other.

[0051] In the description of the present invention, it should be understood that the terms "center", "longitudinal", "lateral", "up", "down", "front", "back", "left", "right", "vertical", "horizontal", "top", "bottom", "inside", "outside" and the like indicate positions or positional relationships based on the positions or positional relationships shown in the accompanying drawings, and are only for the convenience of describing the present invention and simplifying the description, rather than indicating or implying that the device or element referred to must have a specific orientation, be constructed and operated in a specific orientation, and therefore cannot be understood as limiting the present invention. In addition, the terms "first", "second", and the like are only used for descriptive purposes, and cannot be understood as indicating or implying relative importance or implicitly indicating the number of technical features indicated. Thus, features defined as "first", "second", and the like may explicitly or implicitly include one or more of the features. In the description of the present invention, unless otherwise specified, "multiple" means two or more.

[0052] In the description of the present invention, it should be noted that, unless otherwise clearly specified and limited, the terms "installed", "connected", and "connected" should be understood in a broad sense, for example, it can be a fixed connection, a detachable connection, or an integral connection; it can be a mechanical connection or an electrical connection; it can be a direct connection, or it can be indirectly connected through an intermediate medium, or it can be the internal communication of two components. For ordinary technicians in this field, the specific meanings of the above terms in the present invention can be understood by specific circumstances.

[0053] The present invention will be described in detail below with reference to the accompanying drawings and in conjunction with embodiments.

[0054] Glossary:

[0055] LSTM, TRM: LSTM (Long Short-Term Memory) and TRM (Transformer) are two commonly used neural network architectures for processing sequence data. LSTM is a variant of recurrent neural network (RNN), which is particularly suitable for processing long sequence data and capturing long-term dependencies. TRM is a neural network based on the self-attention mechanism, which can process sequence data in parallel and is suitable for processing long-distance dependencies and capturing global information.

[0056] like Figures 1 to 4 As shown, an intelligent database grammar parsing method combining LSTM and TRM is implemented by an intelligent database grammar parsing system. The intelligent database grammar parsing system includes an input module, a preprocessing module, a feature extraction module, a sequence modeling module and an output module. The input module is connected to the output module through the preprocessing module, the feature extraction module and the sequence modeling module in turn. The overall schematic diagram of the system is shown in Figure 1.

[0057] This method combines the advantages of LSTM and TRM, can better capture the timing information and grammatical structure in SQL statements, and improve the parsing accuracy. Through the pre-trained LSTM model and self-attention mechanism, this method can quickly and accurately parse SQL statements, providing strong support for the development of intelligent databases.

[0058] The method comprises the following steps:

[0059] S1. Preprocessing:

[0060] Preprocessing is performed in the preprocessing module. This module is a key part of the data analysis and machine learning process, and its goal is to clean, transform, and standardize raw data for subsequent model training and prediction.

[0061] Specifically, preprocessing includes the following steps:

[0062] S11, data cleaning;

[0063] Data cleaning is the first step in preprocessing, which aims to remove or correct erroneous, abnormal, duplicate or inconsistent information in the data.

[0064] S111. Remove duplicate data: Use Python’s pandas library to detect and remove duplicate rows or records.

[0065] S112. Process missing values: delete records containing missing values.

[0066] S113. Error value correction: Identify and correct error values ​​in the data, and use a state machine to identify and correct errors.

[0067] S12, text conversion;

[0068] Text transformation is the process of converting raw text data into a format suitable for processing by machine learning models.

[0069] Participle:

[0070] Algorithm implementation steps:

[0071] S121. Initialization: Set the dictionary and maximum word length (usually the length of the longest word in the dictionary).

[0072] S122, scanning text: scanning the text to be segmented from left to right.

[0073] S123, Matching: Try to match with words in the dictionary starting from the current position, first try the word with the longest word length, if the match is successful, split out a word, and continue matching from the next position of the word; if the match fails, try the next shorter word until a matching word is found or the word length is reduced to 1.

[0074] S124, continue scanning: repeat step S123 until the entire text is scanned.

[0075] In a preferred embodiment of the present invention, an example of SQL statement segmentation is as follows:

[0076] Assume that there is a dictionary with a maximum word length of 4, which contains words such as "SELECT", "FROM", and "WHERE". Now, the SQL statement "SELECT * FROM table WHERE id = 1" is segmented.

[0077] 1) Initialization: dictionary = {"SELECT", "FROM", "WHERE", "*", "table", "id", "1"}, maximum word length = 4.

[0078] 2) Scan text: Start scanning "SELECT * FROM table WHERE id = 1".

[0079] 3) Matching:

[0080] 4) Try to match "SELECT": the match is successful, and "SELECT" is split out.

[0081] 5) Try to match "* FROM": The match is successful, and "*" and "FROM" are separated.

[0082] 6) Try to match "FROM table": The match is successful, and "FROM" and "table" are split.

[0083] 7) Try to match "table WHERE": The match is successful, and "table" and "WHERE" are split.

[0084] 8) Try to match "WHERE id": The match is successful, and "WHERE" and "id" are separated.

[0085] 9) Try to match "id = ": The match is successful, and "id" and "=" are separated.

[0086] 10) Try to match “= 1”: The match is successful, and “=” and “1” are separated.

[0087] 11) Result: The word segmentation result is "SELECT", "*", "FROM", "table", "WHERE", "id", "=", "1".

[0088] S13, feature extraction;

[0089] Feature extraction is the process of extracting meaningful information from raw data to use as input to a machine learning model.

[0090] S131. Statistical features: Calculate statistical information such as text length, number of words, number of sentences, etc.

[0091] S132. Semantic features: Use the pre-trained model BERT to obtain the semantic representation of the text.

[0092] S133. Structural features: For database query statements, extract specific parts of the SQL statement (such as the SELECT clause, FROM clause, etc.).

[0093] S134, context features: consider the context information of the query statement, such as user permissions, transaction status, etc.

[0094] S14, data partitioning;

[0095] The data set is divided into training set, validation set and test set to evaluate the performance of the model. In the context of intelligent database syntax parsing, the preprocessing module will pay special attention to tasks such as cleaning, word segmentation, and feature extraction of database query statements in order to provide high-quality training data for subsequent LSTM and Transformer models. The specific process of preprocessing, such as Figure 2 shown.

[0096] S2. Preliminary analysis using the TRM model based on the feature extraction module:

[0097] The Transformer model is able to capture contextual information in SQL statements through its self-attention mechanism. The self-attention mechanism allows the model to consider the information of the entire input sequence when processing each word or token, thereby establishing dependencies between words.

[0098] The TRM model used in this system for preliminary analysis belongs to the feature extraction module, which extracts features from the processed text and captures the dependencies and contextual information in the text.

[0099] S21. Data embedding: First, the model needs to perform an embedding operation on the input data to convert the input data into a vector representation that the model can process. This step is achieved through word embedding.

[0100] S22. Self-attention mechanism: The attention mechanism essentially draws on the ability of human vision to process information, which can be summarized into two stages: determining which part of the input needs special attention; and then allocating resources to the important part first. In the neural network, the attention mechanism can be understood as focusing on different features when predicting results.

[0101] Mathematically speaking, the calculation of the attention mechanism can be described as a mapping from a query to a series of key-value pairs. The principle of the attention mechanism calculation is as follows Figure 3 As shown:

[0102] The calculation method can also be summarized into two steps:

[0103] Query, Key and Value represent three different vectors, respectively.

[0104] Query represents the target to be focused on or retrieved;

[0105] Key is used to match Query;

[0106] Value represents the information that needs to be weighted and summed according to the matching degree between Query and Key;

[0107] Taking the model used in this system as an example, each word after segmentation can be regarded as a Key. When processing this SQL statement, the model will generate a Query, which represents the SQL statement to be processed, and the Value is the code corresponding to the Key.

[0108] (1) First, use the query Query and key Key to calculate the weight coefficient. The methods for calculating similarity include point multiplication, weight, cosine similarity, etc., and then use the SoftMax operation to normalize the weight.

[0109] ;

[0110] in, Represents a function used to calculate a query and Key The similarity between

[0111] Represents the query vector (Query), which is usually a vector representing the current focus;

[0112] Represents the transpose operation, which means that the vector Transpose to facilitate dot product operations;

[0113] Represents the key vector (Key), which is a vector that matches the query vector;

[0114] Indicates key vectors. In a sequence, there may be multiple key vectors;

[0115] and Represents the weight matrix, corresponding to the query (Query) and the key (Key). They are used to convert the query vector and key vector Linearly transform to the same dimensional space for subsequent operations;

[0116] Represents the concatenation operation of the vector, which converts the query vector and key vector Splice into a longer vector;

[0117] Represents a weight vector, usually called a value vector. In the attention mechanism, it is used to convert the intermediate representation (usually the result after the activation function) into a scalar score, which will be used in the subsequent normalization operation to calculate the attention weight. Represents a hyperbolic tangent activation function, which maps the input value to between -1 and 1;

[0118] Indicates that the matrix belongs to a specific layer;

[0119] Indicates Key This weight determines how much the model should pay attention to the first The value associated with each key (Value);

[0120] Represents the exponential function, which is used to convert the values ​​in the brackets to positive numbers. The exponential function ensures that all calculated scores are positive, which is necessary for the subsequent normalization step;

[0121] Softmax is the symbol for the softmax function, which is used to convert a set of scores into a probability distribution. The softmax function ensures that the sum of all output scores is 1 and each output score is between 0 and 1. In this way, each key will get an attention weight between 0 and 1, representing the query The degree of attention paid to the key;

[0122] ∑ represents the summation symbol, which means summing all keys to ensure that the sum of all attention weights is 1;

[0123] Represents an iteration variable used to iterate over all keys.

[0124] (2) In the second stage, the Value is weighted and summed to calculate the output of attention.

[0125] S23, Encoder layer: After the self-attention mechanism processes the data, the data will be sent to the encoder layer. The encoder layer consists of multiple sublayers, including the self-attention layer and the feedforward neural network layer. The self-attention layer is responsible for performing self-attention calculations on the input information, while the feedforward neural network layer performs further nonlinear transformations.

[0126] S24, Decoder layer: The input information is processed by the decoder layer. The decoder layer also contains the self-attention layer, the encoder-decoder attention layer, and the feedforward neural network layer. These layers work together to enable the model to generate an output sequence related to the input information. The encoder-decoder structure diagram is shown in Figure 4 shown.

[0127] S25, output processing: Finally, after processing by the encoder layer and the decoder layer, the model will generate the final output.

[0128] In a preferred embodiment of the present invention, it is assumed that there is the following SQL statement:

[0129] SELECT name, age FROM users WHERE age > 30

[0130] After word segmentation, we get:

[0131] [CLS], SELECT, name, ,, age, FROM, users, WHERE, age, >, 30, [SEP]

[0132] The encoded sequence (assuming the BERT model is used, each word is mapped to its corresponding ID):

[0133]

[101] , 2023, 2003, 1029, 2002, 1996, 2025, 1010, 2023, 1037, 1999,1012,

[102]

[0134] These IDs are input into the encoding layer of the BERT model, and a context vector is generated for each ID. If you are concerned about the representation of the entire SQL statement, select the output vector corresponding to the [CLS] tag (ID is 101) as the representation vector of the entire sequence.

[0135] Ultimately, the model will output a fixed-size vector (such as 768 dimensions in BERT), which captures the semantic information of the input SQL statement and can be used for subsequent tasks.

[0136] S3. Further analysis using LSTM model based on sequence modeling module:

[0137] The LSTM model is a recurrent neural network that is particularly suitable for processing sequence data. It can capture long-term dependencies in a sequence. In this system, it belongs to the sequence modeling module. Combining the global features extracted by Transformer and the sequence modeling capability of LSTM, the semantic structure of the query statement can be better understood.

[0138] Suppose there is a simple SQL query statement: "SELECT name, age FROM users WHERE age >30".

[0139] S31. Preprocessing: First, preprocess the SQL statement, such as word segmentation, entity marking, etc. In this example, the SQL statement is word segmented into: ["SELECT", "name", ",", "age", "FROM", "users", "WHERE", "age", ">", "30"], and the entities are marked, such as "name" and "age" are column names, "users" is the table name, and "age >30" is the conditional expression.

[0140] S32. Entity recognition: Next, we use the TRM model to perform entity recognition. Specifically, the preprocessed SQL statement is input into the Transformer model, and the model outputs the label of each word (such as column name, table name, conditional expression, etc.). In this way, we can identify the entities in the SQL statement.

[0141] S33, build parse tree: Based on entity recognition, this module starts to build SQL syntax parse tree. According to the grammatical rules of SQL statements, some basic tree structures are defined. For example, SELECT statements usually contain one or more column names, FROM statements contain a table name, and WHERE statements contain a conditional expression. Then, these tree structures can be filled according to the results of entity recognition. In this example, the following parse tree can be built:

[0142] ;

[0143] This parse tree can be further converted into a SQL query statement: "SELECT name, age FROM usersWHERE age > 30".

[0144] S4. Generate query plan:

[0145] This step belongs to the output module, and generates corresponding database query operation instructions based on the results of the above steps.

[0146] Based on the syntax parse tree, the database checks whether the semantics of the query are valid, such as whether the table name and column name exist, whether the user has sufficient permissions to execute the query, etc., and outputs a parse tree with semantic information. Based on this parse tree, the optimizer tries to reorganize the parts of the query to execute the query more efficiently. For example, it may merge multiple table scan operations or advance certain calculations to the early stages of the query. Get a query plan that is logically equivalent but may be more concise or more suitable for optimization. The optimizer selects the most efficient physical execution strategy based on database statistics (such as table size, index selectivity, etc.). Get a specific execution plan.

[0147] In a preferred embodiment of the present invention, it is assumed that there is the following SQL query:

[0148] SELECT name, department_id

[0149] FROM employees

[0150] WHERE salary > 50000;

[0151] The following query plan is generated:

[0152]

[0153] S41, id: query identifier, used to distinguish different parts in the query. There is only one query here, so it is 1.

[0154] S42, select_type: query type. SIMPLE means this is a simple SELECT query that does not contain subqueries or union queries.

[0155] S43, table: the name of the table involved in the query, here is employees.

[0156] S44, partitions: If the table is partitioned, this will show the partition information involved in the query. In this example, there are no partitions, so it is NULL.

[0157] S45, type: access type. ref indicates that this is an index-based reference access, which uses the index to find matching rows.

[0158] S46, possible_keys: indexes that may be applied to this table. There is only one index, idx_salary, which is possible for this query.

[0159] S47, key: the index actually selected by the query optimizer. In this example, the optimizer selects the idx_salary index.

[0160] S48, key_len: The length of the index used. The 5 here may mean that the first 5 bytes of the index are used for the search.

[0161] S49, ref: Shows which columns or constants are used as references for index lookups. const indicates that this is a constant value, which here refers to the number 50000.

[0162] S410, rows: the estimated number of rows to be checked, which is estimated to be 100 rows here.

[0163] S411, filtered: The percentage of returned results. Here, 10.00% means that among the 100 rows checked, approximately 10 rows will meet the condition that salary > 50000.

[0164] S412, extra: Identifies the index usage of the SQL statement. Common values ​​in the extra field include: Usingindex, which means that a covering index will be used to avoid accessing the data table; Using where, which means that filtering will be performed after the storage engine retrieves the row, etc.

[0165] Through these steps, the intelligent database syntax parsing method based on the combination of LSTM and TRM can understand and execute complex database query statements, providing strong support for data processing and analysis in the big data era.

[0166] This system combines LSTM and TRM. The TRM model has efficient parallelization and global information capture capabilities, and can perform preliminary analysis and understanding of SQL statements. The LSTM model has the ability to handle long-term and short-term problems in data, and further understand the semantics and structure of SQL.

[0167] The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principle of the present invention should be included in the protection scope of the present invention.

Claims

1. Intelligent database grammar parsing method based on LSTM and TRM, Features: The method is implemented by an intelligent database grammar parsing system, which includes an input module, a preprocessing module, a feature extraction module, a sequence modeling module and an output module, wherein the input module is sequentially connected to the output module through the preprocessing module, the feature extraction module and the sequence modeling module; The method comprises the following steps: S1, preprocessing the input data based on the preprocessing module; S2, using the TRM model based on the feature extraction module to perform preliminary analysis on the data pre-processed in step S1; S3, using the LSTM model based on the sequence modeling module to further analyze the data after the preliminary analysis in step S2; S4, generating a query plan for the data further analyzed in step S3, Based on the syntax parse tree, the database checks whether the semantics of the query is valid and outputs a parse tree with semantic information; based on the parse tree with semantic information, the database tries to reorganize the various parts of the query so as to execute the query more efficiently; In step S1, the input data is preprocessed, including the following steps: S11, cleaning the input data; S12, performing text conversion on the cleaned data; S13, extracting features from the data after text conversion; S14, dividing the data after feature extraction; In step S12, the text conversion of the cleaned data includes the following steps: S121, initializing the cleaned data: setting the dictionary and the maximum word length; S122, scanning the data of step S122: scanning the text to be segmented from left to right; S123, matching the data in step S123: segmenting the SQL statement, trying to match it with the words in the dictionary from the current position, first trying the word with the longest word length, if the match succeeds, segmenting a word, and continuing to match from the next position of the word; if the match fails, trying the next shorter word, until a matching word is found or the word length is reduced to 1; S124, continue scanning: repeat step S123 until the entire text is scanned to obtain text-converted data; In step S13, feature extraction is performed on the data after text conversion, including the following steps: S131, statistical features of the converted text data: calculating the length, number of words, and number of sentences of the text; S132, obtaining semantic features from the data after text conversion; S133, obtaining structural features from the data after text conversion, and for a database query statement, extracting a specific part of the SQL statement, wherein the specific part includes a SELECT clause and a FROM clause; S134, obtaining context features from the data after text conversion; In step S2, the preprocessed data is initially analyzed using the TRM model, including: S21, TRM model performs data embedding on the preprocessed data; S22, the TRM model uses the self-attention mechanism to process the data in step S21; S23, the TRM model uses the encoder layer to process the data of step S22; S24, the TRM model uses the decoder layer to process the data of step S23: S25, the TRM model outputs the data of step S24 and captures the semantic information of the input SQL statement; The TRM model is able to capture contextual information in SQL statements through the design of its self-attention mechanism. The self-attention mechanism allows the model to consider the information of the entire input sequence when processing each word or token, thereby establishing dependencies between words. In step S22, the calculation method of the self-attention mechanism includes the following steps: S221, first use the query Query and the key Key to calculate the weight coefficient, and then use the SoftMax operation to normalize the weight; S222, performing weighted summation on Value using the weight-normalized data of step S221, and calculating the output of attention; In step S221, The expression of the SoftMax operation for weight normalization is: ; in, Represents a function used to calculate the query and Keys The similarity between Represents the query vector Query, which is the SQL statement to be processed; Represents the transpose operation, which means that the vector Transpose to facilitate dot product operations; Represents the key vector Key, which is a vector that matches the query vector; Indicates key vectors; and Represents the weight matrix, corresponding to the query Query and key Key respectively; they are used to convert the query vector and key vector Linearly transform to the same dimensional space for subsequent operations; Represents the concatenation operation of the vector, which converts the query vector and key vector Splice into a longer vector; Represents a weight vector, called the value vector; Represents a hyperbolic tangent activation function, which maps the input value to between -1 and 1; Indicates Keys The attention weight of Represents the exponential function, which is used to convert the value in the brackets into a positive number; Softmax represents the symbol of the softmax function, which is used to convert a set of scores into a probability distribution; Represents an iteration variable, used to traverse all keys; In step S3, the LSTM model is used to further analyze the data after preliminary analysis, including the following steps: S31. Preprocess the SQL statements after preliminary analysis based on the LSTM model; S32, using the TRM model to perform entity recognition on the data in step S31 based on the LSTM model, inputting the preprocessed SQL statement into the TRM model, and the TRM model outputs a label for each word, wherein the label includes a column name, a table name, and a conditional expression; S33. Based on the LSTM model, a SQL grammar parse tree is constructed for the data in step S32, a basic tree structure is defined according to the grammatical rules of the SQL statement, and the tree structure is filled according to the result of entity recognition to obtain data for further analysis.

2. According to the LSTM and TRM combined intelligent database grammar parsing method of claim 1, Features: In step S11, data cleaning is performed on the input data, including the following steps: S111, removing duplicate data from input data; S112, processing missing values ​​of the data in step S111; S113, correcting the data error value in step S112 to obtain cleaned data.

Citation Information

Patent Citations

  • Semantic analysis method and device, electronic equipment and storage medium

    CN113408298A

  • Construction method and application of SQL statement generation model of natural Chinese language

    CN114020768A

  • SQL (Structured Query Language) statement conversion method, device and equipment and computer readable storage medium

    CN114691716A

  • Method and system for converting natural language text into SQL (Structured Query Language) statement

    CN114896275A

  • Air traffic control system hazard source key feature extraction method based on semi-supervised learning

    CN116090454A