A method for generating query statements based on relationship graph

By introducing a query statement generation method based on relationship graphs into Text-to-SQL technology, combined with global and local features and subtask constraints, the problem of insufficient consideration of SQL subtask constraint relationships in the existing technology is solved, and more accurate results are achieved. and generate SQL query statements that conform to SQL syntax.

CN119046313BActive Publication Date: 2025-01-21GUANGZHOU SMART SOFTWARE CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202411505112.2
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-10-28
Publication Date
2025-01-21
Estimated Expiration
2044-10-28

AI Technical Summary

Technical Problem

When existing Text-to-SQL technology handles complex user queries, the generated SQL query statements often have inaccurate problems, especially when dealing with complex constraint relationships between SQL subtasks.

Method used

This paper proposes a query statement generation method based on relationship graphs, which combines the global features and local features of the relationship graph and considers the constraint relationships between subtasks within the query statement. By constructing a graph containing statement nodes and query field nodes, the encoding layer, graph attention network layer and task decoder are used to generate accurate SQL query statements.

Benefits of technology

The accuracy of the query statements generated by the model is improved, so that the generated SQL statements are both accurate and consistent with SQL syntax, and can be executed correctly and return the expected results.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119046313B_ABST
    Figure CN119046313B_ABST
Patent Text Reader

Abstract

The present application relates to a query statement generation method based on a relationship graph, which obtains natural query statements and target data table information input by the user, constructs a relationship graph containing statement nodes and query field nodes; and extracts multi-dimensional feature representations of the nodes in the graph through the encoding layer. The feature representation of the nodes is further processed using a pre-trained relationship graph attention network layer to capture deeper semantic information. Finally, a task decoder based on constraint relationships generates an SQL query statement containing multiple query sub-statements based on the processed node feature representation and global feature representation. The method of the present application not only improves the model's ability to understand complex relationships, but also ensures the accuracy and completeness of the generated SQL query statements. In particular, it can accurately process query statements involving multiple sub-tasks, providing a more efficient and reliable solution for Text‑to‑SQL tasks.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the technical field of data query, and in particular to a query statement generation method based on a relationship graph. Background Art

[0002] In the field of natural language processing (NLP), the Text-to-SQL task aims to automatically convert natural query statements proposed by users based on natural language expressions into executable SQL query statements, thereby achieving effective query of the database. Existing Text-to-SQL technologies mainly rely on graph-based attention models, which construct a graph structure containing question nodes and database schema nodes (such as table names and column names), and use deep learning models to extract features and generate SQL statements.

[0003] However, existing technologies mainly focus on building complex relationship graphs and graph attention models and using large amounts of labeled data for training. Although this method has made some progress in this field, when processing complex user queries, such as those involving multiple SQL subtasks, the generated SQL query statements still often have inaccurate problems. Summary of the invention

[0004] Based on this, the purpose of this application is to propose a query statement generation method based on a relationship graph, combining the global and local features of the relationship graph and considering the constraint relationship between subtasks within the query statement, so as to improve the accuracy of the query statement generated by the model.

[0005] The query statement generation method based on the relationship graph described in the embodiment of the present application includes the following steps:

[0006] Acquire a natural query statement input by a user and target data table information queried by the user; the target data table information includes a number of query fields;

[0007] A relationship graph is constructed according to the natural query statement and the target data table information; the nodes of the relationship graph include statement nodes and query field nodes; the statement nodes are obtained according to the word segmentation of the natural query statement; the query field nodes are obtained according to the query fields matched by the natural query statement;

[0008] Inputting the relationship graph into the encoding layer to obtain the relationship representation between each node, the first feature representation of each node, and the global feature representation of each node in the relationship graph;

[0009] Inputting the relationship representation between the nodes and the first feature representation of each node into the pre-trained relationship graph attention network layer to obtain the second feature representation of each node;

[0010] The second feature representation of each node and the global feature representation are input into a pre-trained task decoder to obtain a query statement output by the task decoder; wherein the task decoder is constructed based on the constraint relationship between each query sub-statement of the query statement.

[0011] The inventor of the present application has analyzed the prior art and found that the prior art often ignores the complex constraint relationship between the subtasks (such as SELECT, FROM, WHERE, GROUP BY, HAVING, etc.) within the SQL query statement and how these subtasks work together to form an effective SQL query. For example, the conditional columns in the HAVING clause must be a subset of the columns selected by the SELECT clause. This constraint is often not fully considered and reflected in the prior art, resulting in the generated SQL statement may not be executed correctly or return unexpected results.

[0012] In this regard, this application pays special attention to the logical relationships and constraints between different subtasks within the SQL query statement when solving the Text-to-SQL task. Specifically, in SQL queries, there is a strict dependency between the result subtask (such as the SELECT clause) and the conditional subtask (such as the conditional column in the HAVING clause). For example, in the scenario of data aggregation (such as using CUBE), the conditional column in the HAVING clause must be a subset of the database columns explicitly selected by the SELECT clause. Based on this insight, this application not only considers the logical relationship between natural query statements and database table schemas when constructing the relationship graph, but also uses a specially designed task decoder when building a deep learning model. The decoder can understand and utilize the constraints between these subtasks. To achieve this, this application introduces a relational graph neural network for feature extraction and representation learning. The relational graph neural network can capture the complex relationships between nodes in the graph structure and generate feature representations of the nodes through multiple layers of nonlinear transformations. Correspondingly, the task decoder takes into account the structure and rules of SQL syntax and the logical order between subtasks during design. Through pre-training, it learns the feature representation of each node based on the output of the relationship graph neural network combined with the global feature representation of the preprocessed encoding layer output, and gradually generates query statements that meet the constraints between subtasks and the query statement logic. Ultimately, when the technical solution of this application is applied to the natural query statement input by the user, it is possible to generate a query statement that is both accurate and conforms to SQL syntax.

[0013] In summary, the technical solution of the present application realizes efficient and accurate conversion from natural language queries to SQL query statements by comprehensively considering various aspects of SQL query statements, including the logical relationship between subtasks, constraints, grammatical rules of query statements and constraints of database table schemas, etc., providing a strong support for complex query tasks in the field of natural language processing.

[0014] For better understanding and implementation, the present application is described in detail below with reference to the accompanying drawings. BRIEF DESCRIPTION OF THE DRAWINGS

[0015] Figure 1 A schematic diagram of a flow chart of a query statement generation method based on a relationship graph according to an embodiment of the present application;

[0016] Figure 2 A schematic diagram of the steps of pre-training the relationship graph attention neural network layer and the task decoder in an embodiment of the present application;

[0017] Figure 3 A schematic diagram of the steps of constructing a relationship graph according to a natural query statement and target data table information in an embodiment of the present application;

[0018] Figure 4 A schematic diagram of the steps of encoding the coding layer to obtain the node relationship representation, node feature representation and global feature representation in the embodiment of the present application;

[0019] Figure 5 A schematic diagram of the steps of encoding a node coding layer to obtain a node feature representation and a global feature representation in an embodiment of the present application. DETAILED DESCRIPTION

[0020] In order to make the purpose, technical solution and advantages of the present application clearer, the embodiments of the present application will be further described in detail below in conjunction with the accompanying drawings. Wherein, when the following description refers to the accompanying drawings, unless otherwise indicated, the same numbers in different drawings represent the same or similar elements.

[0021] It should be clear that the implementation methods described in the embodiments described below do not represent all implementation methods consistent with the present application. Instead, they are merely examples of devices and methods consistent with some aspects of the present application as detailed in the attached claims. Based on the embodiments of the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present application.

[0022] The terms used in this application are only for the purpose of describing specific embodiments and are not intended to limit this application. The singular forms of "a", "said" and "the" used in this application are also intended to include plural forms, unless the context clearly indicates other meanings. In addition, in the description of this application, unless otherwise specified, "multiple" refers to two or more. It should also be understood that the term "and / or" used in this article refers to and includes any or all possible combinations of one or more associated listed items, for example, A and / or B can represent: A exists alone, A and B exist at the same time, and B exists alone; the character " / " generally indicates that the objects associated before and after are in an "or" relationship.

[0023] It should be understood that, although the terms first, second, third, etc. may be used in the present application to describe various information, such information should not be limited to these terms, and these terms are only used to distinguish similar objects, and do not have to be used to describe a specific order or sequence, nor can they be understood as indicating or implying relative importance. For those of ordinary skill in the art, the specific meanings of the above terms in the present application can be understood according to the specific circumstances. Depending on the context, the words "if" / "if" used in the present application can be interpreted as "at the time of" or "when" or "in response to determination".

[0024] In the field of natural language processing (NLP), the Text-to-SQL task aims to automatically convert natural query statements proposed by users based on natural language expressions into executable SQL query statements, thereby achieving effective query of the database. Existing Text-to-SQL technologies mainly rely on graph-based attention models, which construct a graph structure containing question nodes and database schema nodes (such as table names and column names), and use deep learning models to extract features and generate SQL statements.

[0025] However, existing technologies mainly focus on building complex relationship graphs and graph attention models and using large amounts of labeled data for training. Although this method has made some progress in this field, when processing complex user queries, such as those involving multiple SQL subtasks, the generated SQL query statements still often have inaccurate problems.

[0026] In this regard, the inventors of this application have analyzed the prior art and found that the prior art often ignores the complex constraint relationship between the subtasks (such as SELECT, FROM, WHERE, GROUP BY, HAVING, etc.) within the SQL query statement and how these subtasks work together to form an effective SQL query. For example, the conditional columns in the HAVING clause must be a subset of the columns selected by the SELECT clause. This constraint is often not fully considered and reflected in the prior art, resulting in the generated SQL statement may not be executed correctly or return unexpected results.

[0027] Based on this, the purpose of this application is to propose a query statement generation method based on a relationship graph, combining the global and local features of the relationship graph and considering the constraint relationship between subtasks within the query statement, so as to improve the accuracy of the query statement generated by the model.

[0028] Please refer to Figure 1 The embodiment of the present application provides a query statement generation method based on a relationship graph, comprising the following steps:

[0029] S101: Acquire a natural query statement input by a user and target data table information queried by the user; the target data table information includes a number of query fields;

[0030] S102: construct a relationship graph according to the natural query statement and the target data table information; the nodes of the relationship graph include statement nodes and query field nodes; the statement nodes are obtained according to the word segmentation of the natural query statement; the query field nodes are obtained according to the query fields matched by the natural query statement;

[0031] S103: Input the relationship graph into the encoding layer to obtain the relationship representation between each node, the first feature representation of each node, and the global feature representation of each node in the relationship graph;

[0032] S104: inputting the relationship representation between the nodes and the first feature representation of each node into a pre-trained relationship graph attention network layer to obtain a second feature representation of each node;

[0033] S105: Input the second feature representation of each node and the global feature representation into a pre-trained task decoder to obtain a query statement output by the task decoder; wherein the task decoder is constructed based on the constraint relationship between each query sub-statement of the query statement.

[0034] When solving the Text-to-SQL task, this application pays special attention to the logical relationships and constraints between different subtasks within the SQL query statement. Specifically, in SQL queries, there is a strict dependency between the result subtask (such as the SELECT clause) and the conditional subtask (such as the conditional column in the HAVING clause). For example, in the scenario of data aggregation (such as using CUBE), the conditional column in the HAVING clause must be a subset of the database columns explicitly selected by the SELECT clause. Based on this insight, this application not only considers the logical relationship between natural query statements and database table schemas when constructing the relationship graph, but also uses a specially designed task decoder when building a deep learning model. The decoder can understand and utilize the constraints between these subtasks. To achieve this, this application introduces a relational graph neural network for feature extraction and representation learning. The relational graph neural network can capture the complex relationships between nodes in the graph structure and generate feature representations of the nodes through multiple layers of nonlinear transformations. Correspondingly, the task decoder takes into account the structure and rules of SQL syntax and the logical order between subtasks during design. Through pre-training, it learns the feature representation of each node based on the output of the relationship graph neural network combined with the global feature representation of the preprocessed encoding layer output, and gradually generates query statements that meet the constraints between subtasks and the query statement logic. Ultimately, when the technical solution of this application is applied to the natural query statement input by the user, it is possible to generate a query statement that is both accurate and conforms to SQL syntax.

[0035] In summary, the technical solution of the present application realizes efficient and accurate conversion from natural language queries to SQL query statements by comprehensively considering various aspects of SQL query statements, including the logical relationship between subtasks, constraints, grammatical rules of query statements and constraints of database table schemas, etc., providing a strong support for complex query tasks in the field of natural language processing.

[0036] The query statement generation method based on the relationship graph described in the embodiment of the present application is executed by a computer. In the following, the structure and key parameters related to the model are first described, and then each step is described in detail.

[0037] The encoding layer is the first key component in the model, responsible for converting input data (such as node features in the relationship graph) into vector representations in a high-dimensional space for subsequent processing and analysis. In one embodiment, the encoding layer may include an embedding layer and an initialization layer (such as a Dropout Layer or a Normalization Layer) to convert discrete data (such as node information, labels, etc.) into continuous, dense vectors with a fixed length. These vectors serve as inputs for subsequent processing (such as the relationship graph attention network layer) and contain the core information of the input data.

[0038] Relational representation, in the context of a relational graph, refers to the mathematical representation of the connection (or edge) between nodes in a graph. It is used to characterize the association, dependency, or interaction between different nodes. In a relational graph, a relationship can be explicit (such as directly connected by directed or undirected edges) or implicit (such as indirectly inferred by attribute similarity, distance, or other metrics between nodes). Relational representations usually contain information such as type, weight, direction, etc. between two or more nodes, which is crucial for understanding the structure of data in the graph, performing tasks such as node classification and link prediction. In one embodiment, the relational representation can exist in multiple forms, such as elements in an adjacency matrix, edge feature vectors, or representations dynamically generated by a message passing mechanism in a graph neural network. These representations not only reflect the direct connection between nodes, but may also capture higher-order, complex interaction patterns, thereby providing more comprehensive and rich context information for the task decoder.

[0039] The first feature representation refers to the feature vector obtained after preliminary encoding or conversion of the input data (such as nodes in the relationship graph) in the initial stage of data processing or model training. These feature vectors serve as inputs to the subsequent processing flow and contain the original information of the input data or the information that has been preliminarily processed. In one embodiment, the first feature representation corresponds to the initial feature representation of each node in the relationship graph. These features may include the ID, type, attributes (such as text description, numerical attributes, etc.) of the node, and the position or structural information (such as degree, centrality, etc.) of the node in the graph. After these initial features are processed by the encoding layer (such as the embedding layer), they are converted into a fixed-length, dense vector form, namely the first feature representation. These vectors are further processed and converted in the subsequent relationship graph attention network layer to generate a higher-level, more expressive feature representation, which is ultimately used for the output generation of the task decoder. It should be noted that the first feature representation may vary depending on the specific application scenario and model design. In practical applications, it is necessary to select appropriate feature representation methods and encoding techniques based on the characteristics of the data and the requirements of the task.

[0040] Global feature representation refers to a feature vector extracted from the entire relationship graph or query context that can reflect the overall properties or statistical information. In this embodiment, the global feature representation can be obtained by aggregating the features of all nodes or edges in the relationship graph (such as summation, average, maximum value, etc.), or by using more complex graph neural network (GNN) technology to capture the complex interactions and dependencies between nodes in the graph. The global feature representation plays an important auxiliary role in the subsequent task decoding process, helping the model to better understand the overall structure and intent of the query.

[0041] The second feature representation is a feature vector obtained after a certain transformation or enhancement, which contains more contextual information, richer semantic content or a higher level of abstract concepts compared to the first feature representation. Typically, in the context of a relationship graph or a graph neural network (GNN), the second feature representation can be a node feature processed by a graph convolutional network (GCN), a graph attention network (GAT), a graph message passing mechanism or other graph neural network layers. In an embodiment of the present application, the second feature representation is generated in the relationship graph attention network layer based on the relationship representation between each node and the first feature representation of each node. In the relationship graph attention network layer, the node relationship and node feature information of each node are weighted and aggregated by the attention mechanism to obtain the second feature representation corresponding to each node. Generally speaking, the second feature representation not only contains the original information of the first feature representation of the node, but also incorporates the information of its neighboring nodes and the structural information of the entire relationship graph.

[0042] The relationship graph attention network layer is a neural network layer specially designed for processing relationship graph data. It is based on the attention mechanism and can dynamically adjust the weights of different nodes or edges when processing nodes in the relationship graph to focus on information that is more important to the current task. In one embodiment, the relationship graph attention network layer can be implemented by stacking multiple layers of attention modules, each of which has fine-grained control over message passing and aggregation between nodes. This layer is designed to enhance the model's ability to capture complex relationships between nodes in the relationship graph and provide richer feature representations for subsequent task decoders.

[0043] The task decoder is the last key component in the model, which is responsible for converting the feature representations obtained by the previous layers into the final output, which is the SQL query statement in this embodiment. The task decoder usually adopts a sequence-to-sequence architecture. In one embodiment, the task decoder includes multiple sublayers or modules, such as a feature fusion layer, a task fusion layer, and multiple linear layers (or fully connected layers). The feature fusion layer is responsible for merging and integrating feature representations from different sources; the task fusion layer is responsible for combining the results of each subtask (such as grouping, field selection, condition generation, etc.) into a complete query statement. The linear layer is used to implement specific calculations and conversion processes, such as the prediction of conditional connectors and the calculation of the number of fields. The design of the task decoder aims to gradually build and refine the various parts of the query statement, and finally generate a complete query statement that conforms to grammatical and logical rules.

[0044] Please refer to Figure 2 In the embodiment of the present application, the pre-trained relationship graph attention network layer and task decoder are trained in the following manner:

[0045] Step S201, obtaining a training data set; wherein the training data set includes a plurality of training samples, each training sample includes a relationship representation between nodes of a relationship graph, a first feature representation of each node, a global feature representation of the relationship graph, and corresponding query label information; the query label information includes a standard query statement corresponding to the relationship graph;

[0046] Step S202, inputting the relationship representation between each node of the relationship graph of each training sample and the feature representation of each node into the initialized relationship graph attention network layer to obtain the second feature representation of each node of each training sample as output;

[0047] Step S203, inputting the second feature representation of each node of each training sample and the corresponding global feature representation into the initialized task decoder to obtain the query statement corresponding to each training sample;

[0048] Step S204, calculate the loss value between the query statement of each training sample and the corresponding query label information; according to the loss value, adjust the parameters of the relationship graph attention network layer and the task decoder until the loss value is less than the preset loss threshold or the total number of weight adjustments reaches the preset number of adjustments, and obtain the trained relationship graph attention network layer and the task decoder.

[0049] The effective implementation of the embodiment of the present application depends on the relationship graph attention network layer and task decoder obtained by pre-training (for further structural limitations of the relationship graph attention network layer and the task decoder, please refer to the description of the subsequent embodiments). Specifically, step S201 first obtains a data set containing rich training samples, each training sample not only contains the relationship representation between the nodes in the relationship graph, but also covers the initial feature representation of each node (i.e., the first feature representation), and the global feature representation of the entire relationship graph. More importantly, each training sample is also accompanied by corresponding query label information, i.e., the standard query statement that should be generated according to the relationship graph, which is the key basis for evaluating the accuracy of the model output. In this embodiment, each training sample is obtained based on each different natural query statement. Specifically, the method in the embodiment of the present application is used to construct a relationship graph for the natural query statement and the corresponding target data table information, and the relationship graph is input into the encoding layer to encode the relationship between the nodes of the relationship graph of each natural query statement, the first feature representation of each node, and the global feature representation of each of the relationship graphs. In addition, the standard query statement corresponding to each natural query statement is used as the query label information of the corresponding training sample. For specific implementation steps, please refer to the detailed description of the subsequent embodiments.

[0050] Step S202 inputs the relationship graph data in the training sample (including the relationship representation between nodes and the feature representation of each node) into the initialized relationship graph attention network layer. This network layer uses the graph attention mechanism to deeply process the original node features by considering the interaction and importance between nodes, and extracts the second feature representation rich in contextual information. This process aims to capture the potential complex patterns and structural information in the graph data, and provide strong support for subsequent task decoding.

[0051] Step S203 inputs the second feature representation of each node obtained in step S202 and the global feature representation of the relationship graph in the training sample into the initialized task decoder. The task decoder uses these comprehensive features and gradually constructs a query statement corresponding to the input relationship graph through a series of decoding operations (such as sequence generation, attention allocation, etc.).

[0052] Step S204 compares the query statement output by the task decoder with the query label information in the training sample, and calculates the loss value between the two (such as cross entropy loss, BLEU score, etc.) to quantify the difference between the model output and the true label. According to the calculated loss value, the parameters in the relationship graph attention network layer and the task decoder are adjusted through the back propagation algorithm to continuously optimize the model performance. This process will be repeated until the loss value drops below the preset threshold, or the total number of weight adjustments reaches the preset number of adjustments. At this time, it is considered that the model has been fully trained and can be used for subsequent query generation tasks, that is, it is applied to the query statement generation method based on the relationship graph in the embodiment of the present application, and the natural query statement newly input by the user is processed by the pre-trained model.

[0053] Through the above training process, the combined model of the relationship graph attention network layer and the task decoder proposed in this application can efficiently extract key information from complex relationship graph data and accurately generate expected query statements. This model not only makes full use of the advantages of the graph attention mechanism in capturing complex relationships between nodes, but also realizes the natural conversion from graph to text through task-specific decoding strategies. Overall, this technical solution significantly improves the efficiency and accuracy of query generation tasks based on relationship graphs, and provides strong technical support for information retrieval, database query and other fields.

[0054] For step S101, a natural query sentence input by a user and target data table information queried by the user are obtained; the target data table information includes a number of query fields.

[0055] This step first obtains the natural language query statement input by the user, which is a description of the problem that the user wants to retrieve information from the database. At the same time, it is also necessary to obtain the target data table information of the user's query, which usually includes the name of the data table and several query fields contained in the table (i.e., the column names in the database). This step is the starting point of the entire query generation process and provides the necessary input data for subsequent steps.

[0056] For step S102, a relationship graph is constructed according to the natural query statement and the target data table information; the nodes of the relationship graph include statement nodes and query field nodes; the statement nodes are obtained according to the word segmentation of the natural query statement; the query field nodes are obtained according to the query fields matched by the natural query statement.

[0057] This step builds a relationship graph based on the natural query statement and the target data table information. This relationship graph is used to represent the association between the query statement and the database table model. The nodes of the relationship graph include two types: statement nodes and query field nodes. Statement nodes are obtained through word segmentation of natural query statements. Each word or phrase is a node, reflecting the semantic content of the query statement. Query field nodes are obtained by matching the query fields (i.e., database column names) mentioned in the natural query statement with the data table information. These nodes represent the data columns that the user wants to query. Through the connection between nodes (such as edges based on character matching), the relationship graph forms a graph structure that can reflect the relationship between query intent and database structure.

[0058] In the scenario of the embodiment of the present application, the user's query is for a large data table, that is, the number of query fields contained is greater than the preset field number threshold (such as greater than 100). Since the user queries a clear large data table, the target query data table of the SQL query statement (that is, the data table of the from sub-statement) can be directly determined. When constructing the relationship graph, there is no need to add the data table name to the relationship graph node, only the relevant query fields need to be added to the relationship graph node. Furthermore, in this scenario of large data table query, the number of query field nodes in the constructed relationship graph may also be large, resulting in a huge amount of calculation for encoding and decoding of the relationship graph, resulting in huge computing power consumption and affecting query efficiency. In this regard, the present application will provide a solution in an embodiment later, please refer to the subsequent description for details.

[0059] Please refer to Figure 3 In one embodiment, the target data table information includes a plurality of small data tables, each of which includes a plurality of query fields;

[0060] The step of constructing a relationship graph according to the natural query statement and the target data table information in step S102 includes:

[0061] Step S1021, performing syntactic analysis on the natural query statement, and determining a first dependency relationship between each word segment in the natural query statement according to the syntactic analysis result;

[0062] Step S1022, identifying the entity participle of the natural query statement, and if the entity participle matches at least one query field in the target data table information, determining a second dependency relationship between the entity participle and the matched query field; if any two matched query fields belong to the same data tablelet, determining a third dependency relationship between the two matched query fields;

[0063] Step S1023, constructing nodes of a relationship graph according to each word segmentation and each matching query field within the natural query statement, and constructing corresponding edges between each node of the relationship graph according to a first dependency relationship between each word segmentation within the natural query statement, a second dependency relationship between the entity word segmentation and the matching query field, and a third dependency relationship between any two query fields belonging to the same data tablelet.

[0064] Among them, in step S1021, the natural query statement is parsed syntactically, which usually involves the use of natural language processing (NLP) technology, such as part-of-speech tagging, named entity recognition (NER), and syntactic dependency analysis. The result of the syntactic parsing will reveal the grammatical structure and semantic relationship between the various words (participles) in the query statement, the so-called "first dependency relationship". For example, in the query statement "find the product with the highest sales in 2023", the syntactic parsing may identify that "2023" is a time adverbial, "sales" is the core part of the subject, "highest" is an adjective modifying "sales", and "product" is the object. The syntactic relationship between these elements constitutes the first dependency relationship. In one embodiment, the Spacy algorithm can be used for syntactic tree parsing.

[0065] Step S1022 focuses on identifying entity segmentation in natural query statements and determining whether these entities match the query fields in the target data table information. Once a match is found, a "second dependency relationship" between the entity segmentation and the query field is established. In addition, if two matching query fields are found to belong to the same data subtable, such as "sales" and "product ID" both belong to the "sales record" data subtable, a "third dependency relationship" between the two query fields is further established, indicating their close connection in data logic.

[0066] In step S1023, a relationship graph is constructed based on all the above dependencies. The nodes of the relationship graph may include each word segmentation in the natural query statement, each matching query field, and even the data table itself (as needed). The edges are determined according to the first, second, and third dependencies, indicating the connection mode and meaning between the nodes. For example, an edge can point from "2023" to "sales", indicating the limiting effect of time adverbials on sales; another edge can point from "sales" to "products" and be connected to "product ID" through a dotted edge (determined according to specific design rules), indicating that these fields work together in the query, and "product ID" is logically associated with "product".

[0067] This embodiment can effectively convert natural language query statements into structured relationship graphs. This conversion process not only retains the original intent of the query statement, but also clarifies the data tables, fields and their relationships involved in the query. This structured representation method greatly simplifies the complexity of subsequent query processing, can more accurately understand user queries, optimize query plans, and improve query execution efficiency. At the same time, since the relationship graph clearly shows the association between the various elements in the query, it also provides strong support for subsequent work such as query optimization and error diagnosis.

[0068] In one embodiment, the syntactic parsing result includes the word-level syntactic relationship of the natural query statement; the first dependency relationship between each word segment within the natural query statement includes the first dependency type information between each word segment; the first dependency type information between each word segment is determined according to the word-level syntactic relationship.

[0069] This embodiment further defines that the dependency relationship between participles in a natural query sentence also includes type information. Specifically, when a syntactic analyzer is used to perform syntactic parsing on a natural query sentence input by a user, each word (participle) in the sentence is identified and the syntactic relationship between them, that is, the word-level syntactic relationship, is determined. These relationships include but are not limited to subject-predicate relationships, verb-object relationships, attributive relationships, etc., which together constitute the grammatical structure framework of the sentence. After obtaining the word-level syntactic relationship, these relationships are further analyzed to extract the first dependency relationship between each participle in the natural query sentence. Different from the conventional method, this embodiment introduces type information in the dependency relationship-specifically, according to the syntactic parsing result, a first dependency type information is assigned to each dependency relationship between participles. The determination of the dependency type information is based on the word-level syntactic relationship identified in the syntactic parsing. For example, if there is a subject-predicate relationship between two participles, the dependency type information between them may be marked as "subject-predicate"; if there is a verb-object relationship, it may be marked as "verb-object". These type information not only reflects the syntactic connection between participles, but also provides deep semantic clues about how they interact in sentences. The introduction of type information not only enriches the representation dimension of dependency relations, but also enables the model to capture the semantic features and structural information in natural query statements more finely.

[0070] In summary, this embodiment determines the first dependency type information between word segments based on the word-level syntactic relationship in the syntactic parsing results. The addition of these types of information enables the relationship graph to not only contain the connection information between nodes, but also contains rich semantic and grammatical knowledge. This enhanced relationship graph representation capability enables the subsequent relationship graph attention network layer and task decoder to better understand and utilize graph data, thereby generating more accurate, relevant and semantically rich query statements. Overall, this technical solution improves the performance and user experience of the query generation system based on the relationship graph.

[0071] In one embodiment, before the step of determining the second dependency relationship between the entity segmentation and the matching query field if the entity segmentation matches at least one query field in the target data table information in step S1022, the method includes the following steps:

[0072] Step S10221, character matching is performed between the entity segmentation and each query field in the target data table information. If the character mismatch degree between the entity segmentation and any query field is less than a preset threshold, it is determined that the entity segmentation matches the query field.

[0073] Before executing step S1022, i.e., determining the second dependency relationship between the entity segmentation and the query field in the target data table information, this embodiment specifically defines the preceding judgment step S10221. The core of this step is to determine the query field that matches the entity segmentation by character matching. Specifically, first traverse all query fields defined in the target data table information, and compare them with the entity segmentation currently being processed one by one at the character level. This comparison can select a suitable character matching algorithm according to the actual situation, and preferably select a character matching algorithm that can tolerate a certain degree of character difference to calculate the character mismatch. By calculating the character mismatch between the entity segmentation and each query field (such as edit distance, similarity score, etc.), and comparing it with a preset threshold, it can be determined which (or which) query field has a higher similarity at the character level between the entity segmentation. If the character mismatch between a query field and the entity segmentation is less than the preset threshold, it can be considered that the query field and the entity segmentation have a sufficiently strong association in semantics or representation, so it can be determined that there is a matching relationship between them, based on which, the second dependency relationship between the entity segmentation and the query field is established.

[0074] In summary, this embodiment significantly improves the accuracy and robustness of the match between the entity segmentation and the query field of the target data table by introducing the character matching mechanism in step S10221. This mechanism not only takes into account the precise match between the query field and the entity segmentation, but also allows a certain degree of character difference through a preset threshold, so that it can better handle the uncertainty and diversity in user input. This flexible matching method helps to improve the user-friendliness and practicality of the entire query generation system, so that the model can more accurately understand the user's query intent and generate corresponding and effective data query statements. At the same time, the overall performance and query efficiency of the model are further improved due to the reduction of mismatches caused by character differences.

[0075] In one embodiment, the second dependency relationship between the entity participle and the matched query field includes second dependency type information between the entity participle and the matched query field; the second dependency type information includes a complete match type and a partial match type;

[0076] The method further comprises the steps of:

[0077] Step S1024, if the character mismatch degree is 0, determine that the entity segmentation and the second dependent type information of the query field are a complete match type; if the character mismatch degree is greater than 0 and less than a preset threshold, determine that the entity segmentation and the second dependent type information of the query field are a partial match type.

[0078] In this embodiment, in order to more finely describe the relationship between the entity segmentation and the matching query field, the concept of the second dependency type information is introduced, and it is subdivided into a complete match type and a partial match type. These two types of information not only reflect the matching degree between the entity segmentation and the query field, but also provide richer semantic clues for subsequent query processing.

[0079] Specifically, in step S1024, the second dependency type information is determined based on the character mismatch degree calculated previously. If the character mismatch degree is 0, that is, the entity segmentation and the query field are completely consistent at the character level, then it can be determined that the second dependency type information between them is a complete match type. This match type indicates that the entity segmentation and the query field are highly consistent in semantics, which may prompt the model to directly use the entity segmentation to construct the query statement without additional conversion or interpretation. On the other hand, if the character mismatch degree is greater than 0 but less than the preset threshold, it means that there is a certain character difference between the entity segmentation and the query field, but the degree of difference is within an acceptable range. In this case, the second dependency type information between them is determined to be a partial match type. The partial match type indicates that the entity segmentation and the query field may be semantically similar but not exactly the same, suggesting that the model may need to go through some additional processing (such as synonym replacement, fuzzy query, etc.) to ensure the accuracy of the query.

[0080] In summary, this embodiment further enhances the logical information in the relationship graph by introducing the concept of the second dependency type information and subdividing it into full match type and partial match type. The representation ability of the relationship graph is also enhanced, so that the subsequent relationship graph attention network layer and task decoder can better understand and utilize the graph data, thereby generating more accurate, relevant and semantically rich query statements. Overall, this technical solution improves the performance and user experience of the query generation system based on the relationship graph.

[0081] In one embodiment, the target data table information also includes field category information corresponding to each query field;

[0082] The third dependency relationship includes third dependency type information; the third dependency type information includes the same field category type and different field category types;

[0083] The method further comprises the steps of:

[0084] Step S1025, if any two query fields belonging to the same data table correspond to the same field category information, determine that the third dependency type information between the two query fields is the same field category type; otherwise, determine that the third dependency type information between the two query fields is different field category types.

[0085] In this embodiment, in order to further improve the accuracy of the neural network when generating query statements, the target data table information is divided more carefully, and the concept of type information is introduced in the third dependency. These improvements are intended to provide the neural network with richer context information by more comprehensively capturing the semantic and structural relationships between the fields in the data table, thereby guiding it to generate more accurate and logical query statements. Specifically, in the target data table information, in addition to recording the basic information of each query field, additional field category information is added. The field category information is the result of a higher-level classification of the query field, which reflects the common attributes or categories represented by the field in the data table. For example, a data table may contain multiple fields related to "user information", such as user name, user ID, user mailbox, etc., and these fields can be classified into the category of "user information". Next, the third dependency and its type information are defined. The third dependency mainly focuses on the nature of the association between any two query fields in the same data table, and the third dependency type information is used to describe the specific type of this association. According to the field category information, the third dependency type information can be subdivided into the same field category type and different field category types. If two query fields belong to the same field category, then the third dependency type information between them is the same field category type; conversely, if they belong to different field categories, then they are different field category types.

[0086] In step S1025, the specific operation of the above logic is implemented. For any two query fields in the same data table, first check whether the field category information corresponding to them is the same. If they are the same, it is determined that the third dependency type information between the two fields is the same field category type; if they are different, it is determined that they are different field category types.

[0087] This embodiment introduces the concepts of field category information and the third dependency relationship and its type information, and implements step S1025 in the data processing process, so that the relationship graph not only contains the connection information between the query field nodes, but also contains rich type information between the query fields, thereby enhancing the representation ability of the relationship graph. The introduction of field category information enables the neural network to better understand the intrinsic connection and hierarchical structure between the fields in the data table, so that it can more accurately grasp the user's query intention and the structural characteristics of the data table when generating query statements. At the same time, the introduction of the third dependency relationship and its type information provides the neural network with richer contextual information, allowing it to more carefully analyze the correlation properties between the query fields, and generate more logical and semantic query statements based on this. Overall, this technical solution improves the performance and user experience of the query generation system based on the relationship graph.

[0088] For step S103, the relationship graph is input into the encoding layer to obtain the relationship representation between each node, the first feature representation of each node and the global feature representation of each node in the relationship graph.

[0089] After the relationship graph is constructed in the above steps, this step inputs the relationship graph into an encoding layer for processing. The role of the encoding layer is to extract features and learn representations of nodes and edges in the relationship graph. Through the encoding layer, it is possible to generate relationship representations between nodes (specifically, features such as the strength and type of connections between nodes), first feature representations of each node (specifically, the semantic and contextual features of the node itself), and global feature representations of each node in the relationship graph (i.e., features of nodes that contain the entire graph structure). These feature representations provide important input information for the attention network and decoder in subsequent steps.

[0090] Please refer to Figure 4 In one embodiment, the coding layer in step S103 includes a relationship coding layer and a node coding layer;

[0091] The step of inputting the relationship graph into the encoding layer to obtain the relationship representation between each node, the first feature representation of each node and the global feature representation of each node in the relationship graph in step S103 includes:

[0092] Step S1031, inputting the relationship graph into the relationship encoding layer to obtain an output relationship representation between each node;

[0093] Step S1032: input each node of the relationship graph into the node encoding layer to obtain a feature representation of each node and a global feature representation of each node of the relationship graph.

[0094] In this embodiment, the structure of the coding layer is further refined, and it is divided into a relationship coding layer and a node coding layer to process the relationship information between nodes in the relationship graph and the feature information of the nodes themselves respectively. This hierarchical processing method helps the neural network to more effectively capture the complex structure of the relationship graph and generate high-quality node representation and global feature representation.

[0095] In step S1031, the relationship graph is first input into the relationship encoding layer. The main task of the relationship encoding layer is to analyze and process the connection relationship and dependency information between the nodes in the relationship graph, so as to generate the relationship representation between each node. This relationship representation not only contains the direct connection information between the nodes, but also can capture the indirect association and more complex dependency relationship between the nodes through the iterative process of the graph neural network (such as the graph convolution network GCN). Through the processing of the relationship encoding layer, a more comprehensive and in-depth feature representation of the node relationship (i.e., the relationship representation) can be obtained.

[0096] In step S1032, each node of the relationship graph is input into the node coding layer. The main goal of the node coding layer is to extract the feature information of each node and convert it into a feature representation suitable for subsequent processing. This feature representation can contain various types of information such as node attribute information, category labels, text descriptions, etc., depending on the processing capabilities of the node coding layer used. At the same time, the node coding layer will also aggregate and abstract the node features of the entire relationship graph to generate a global feature representation of the relationship graph. The global feature representation is a high-level summary and description of the entire relationship graph, which helps the neural network understand the semantics and structure of the entire relationship graph in subsequent steps.

[0097] In summary, this embodiment significantly improves the efficiency and accuracy of the neural network in processing relationship graph data by introducing a hierarchical processing mechanism of the relationship coding layer and the node coding layer. The relationship coding layer effectively captures the complex relationship information between nodes and provides rich contextual support for subsequent query generation or reasoning tasks. The node coding layer focuses on the extraction and representation learning of the node's own features to ensure the integrity and accuracy of the node information. This hierarchical processing method not only enables the neural network to understand the intrinsic structure of the relationship graph more deeply, but also improves its scalability and robustness when processing large-scale relationship graph data. Ultimately, by integrating information such as relationship representation, node feature representation, and global feature representation, the neural network can generate more accurate and logical query statements or reasoning results, thereby providing users with a better data service experience.

[0098] Please refer to Figure 5 In one embodiment, the node encoding layer includes an embedding layer and an attention network layer; the embedding layer is connected to the attention network layer;

[0099] The step of inputting each node of the relationship graph into the node coding layer to obtain the output feature representation of each node and the global feature representation of each node of the relationship graph in step S1032 includes:

[0100] Step S10321, splicing the statement nodes and query field nodes of the relationship graph according to a preset format to obtain a spliced ​​text of the relationship graph nodes; inputting the spliced ​​text of the relationship graph nodes into the embedding layer to obtain a first embedding vector sequence of the spliced ​​text of the relationship graph nodes; the first embedding vector sequence includes the embedding vector corresponding to each statement node and each query field node in the spliced ​​text of the relationship graph nodes;

[0101] Step S10322, inputting the first embedding vector sequence into the attention network layer to obtain an output second embedding vector sequence; the second embedding vector sequence includes the embedding vector corresponding to each sentence node and each query field node in the relationship graph node concatenation text, and the global feature vector of the relationship graph node concatenation text;

[0102] Step S10323, according to the embedding vector corresponding to each sentence node in the relationship graph node splicing text, obtain the feature representation corresponding to each sentence node; according to the embedding vector corresponding to each query field node in the relationship graph node splicing text, obtain the feature representation corresponding to each query field node; according to the global feature vector of the relationship graph node splicing text, obtain the global feature representation of each node of the relationship graph.

[0103] In this embodiment, in order to more accurately capture the complex relationships between nodes in the relationship graph and the characteristics of the nodes themselves, a node encoding layer including an embedding layer and an attention network layer is designed. This design aims to automatically extract and fuse semantic information between and within nodes through deep learning to generate more expressive feature representations.

[0104] First, step S10321 splices the statement nodes and query field nodes in the relationship graph according to a preset format. This splicing can be a simple text connection or a complex format with delimiters for subsequent processing. Subsequently, the spliced ​​relationship graph node text is input into the embedding layer. The embedding layer uses a pre-trained word embedding model (such as Word2Vec, BERT, etc.) to convert the text into a vector representation in a high-dimensional space, that is, the first embedding vector sequence. These vectors not only contain the semantic information of the words, but are also optimized through contextual relationships, so that similar words or nodes are closer in the vector space.

[0105] Next, step S10322 sends the first embedding vector sequence to the attention network layer. The core idea of ​​the attention mechanism is to enable the model to focus on important parts when processing information and ignore irrelevant or minor details. In this example, the attention network layer generates a second embedding vector sequence by calculating the importance weight of each embedding vector to the whole and adjusting the value of the vector accordingly. In this process, not only the information of the original embedding vector is retained, but also the feature representation of the key nodes is enhanced by weighted fusion. At the same time, the attention network layer also outputs a global feature vector, which integrates the overall information of the spliced ​​text of the relationship graph nodes, providing a basis for subsequent global feature representation.

[0106] Finally, step S10323 obtains feature representations of each statement node and each query field node according to the embedding vectors in the second embedding vector sequence. These feature representations not only contain the semantic information of the node itself, but also incorporate the information of other related nodes through the attention mechanism, thereby achieving effective transmission and fusion of information between nodes. In addition, according to the global feature vector, the global feature representation of each node in the relationship graph is obtained.

[0107] In summary, this embodiment achieves a deep understanding and feature extraction of each node and its mutual relationship in the relationship graph by introducing a node encoding layer consisting of an embedding layer and an attention network layer. On the one hand, the embedding layer uses a pre-trained word embedding model to convert text nodes into high-dimensional vectors, retaining rich semantic information; on the other hand, the attention network layer enhances the feature representation of key nodes and generates a global feature vector by dynamically adjusting the weights of node vectors. This design not only improves the accuracy and robustness of node feature representation, but also enables the model to better capture the complex structure and potential patterns in the relationship graph, providing strong support for subsequent data processing, query optimization and other tasks.

[0108] In one embodiment, the node encoding layer further includes a pooling layer connected to the attention network layer; the embedding layer includes a character segmentation layer and an embedding calculation layer; the character segmentation layer is used to perform character segmentation on each query field node in the concatenated text of the relationship graph nodes to obtain a number of characters corresponding to each query field node; the embedding calculation layer is used to calculate a first embedding vector of a number of characters corresponding to each query field node; the embedding vector corresponding to the query field node in the first embedding vector sequence includes a first embedding vector of each character of the query field node;

[0109] The step of obtaining the feature representation corresponding to each query field node according to the embedding vector corresponding to each query field node in the text of the relationship graph node splicing in step S10323 includes:

[0110] Step S103231, performing pooling calculation based on the first embedding vectors of each character of each query field node to obtain the second embedding vector of each query field node; determining the second embedding vector corresponding to each query field node as the feature representation corresponding to each query field node.

[0111] Among them, the character segmentation layer is used to perform character-level segmentation processing on each query field node in the concatenated text of the relationship graph nodes. This process splits each query field node into its constituent characters, providing a basis for subsequent character-based embedding calculations. The advantage of character segmentation is that it can capture more subtle semantic and structural information within the query field node, which helps to improve the accuracy of feature representation.

[0112] The embedding calculation layer is used to calculate the first embedding vector of each character corresponding to each query field node. These embedding vectors are obtained through pre-trained character embedding models (such as Char2Vec, etc.). They not only contain the semantic information of the characters themselves, but may also be optimized through contextual relationships. In this way, the embedding calculation layer generates a character-based, high-dimensional, and information-rich embedding vector sequence for the query field node.

[0113] The pooling layer receives the output from the attention network layer and performs pooling calculations on the embedding vector sequence of each query field node. Pooling operations (such as maximum pooling, average pooling, etc.) generate a second embedding vector of fixed length by aggregating key information in the embedding vector sequence. This second embedding vector not only retains the important features of the original embedding vector, but also reduces the computational complexity and noise interference through dimensionality reduction, making the feature representation more compact and robust.

[0114] It should be noted that the various layers involved in the embodiments of the present application, including the encoding layer, the character segmentation layer, the embedding calculation layer, the pooling layer, the relational attention network layer, the task decoder, etc., can all be processing modules based on neural networks, which have the ability to receive input data and output processed data, and this ability is usually obtained through training - except for special instructions, some of the layers can be directly using existing technologies, while some layers need to be trained accordingly according to the scenarios of the present application. Except for special instructions, or based on the technical implementation logic, some layers may not be processing modules based on neural networks, but processing modules based on custom rules, which do not need to be trained. For example, the character segmentation layer can also be based on custom rules for character-level segmentation. The above specific reference is made to the description of the embodiments in the context of the present application.

[0115] This embodiment involves a large data table query scenario. The number of query field nodes in the relationship graph may be very large. Directly encoding and decoding these nodes will bring a huge computational burden and affect the query efficiency. To this end, this embodiment optimizes the node encoding layer in a targeted manner. In the character segmentation layer and the embedding calculation layer, for each query field node, it is first split into a character sequence by the character segmentation layer, and then the embedding calculation layer is used to calculate the embedding vector of each character. This step ensures that even if the field name is long or contains complex characters, it can be effectively converted into a representation in a high-dimensional vector space. Subsequently, the character embedding vector sequence is sent to the attention network layer, and the weight is assigned to the embedding vector of each character through the attention mechanism to highlight important information and suppress noise. In the pooling layer after the attention network layer, the long sequence is compressed into a second embedding vector of a fixed length by performing a pooling operation on the embedding vector sequence of each query field node. This step significantly reduces the dimension and computation of the feature vector, while retaining key information, effectively reducing the complexity of encoding and decoding.

[0116] Through the above-mentioned optimization measures, this embodiment realizes effective optimization of the relationship graph construction and node encoding layer in the scenario of large data table query. On the one hand, by omitting the data table name node and focusing on the query field node, the complexity of the relationship graph is simplified; on the other hand, by introducing the combined processing of the character segmentation layer, the embedding calculation layer, the attention network layer and the pooling layer, the efficient extraction and compression encoding of the query field node feature vector is realized. These optimization measures not only reduce the amount of calculation and reduce the computing power consumption, but also improve the query efficiency, so that the system can respond to query requests for large-scale data tables more quickly.

[0117] For step S104, the relationship representation between the nodes and the first feature representation of each node are input into the pre-trained relationship graph attention network layer to obtain the second feature representation of each node.

[0118] After obtaining the preliminary feature representation of the node in step S103, step S104 inputs these feature representations and the relationship representations between nodes into a pre-trained relationship graph attention network layer for further processing. The relationship graph attention network layer can use the attention mechanism to capture the important relationships and dependencies between nodes, and update and optimize the feature representation of the nodes based on these relationships and dependencies. Through this step, a more accurate and rich second feature representation of the node can be generated, providing more powerful support for the subsequent generation of query statements.

[0119] For step S105, the second feature representation of each node and the global feature representation are input into a pre-trained task decoder to obtain a query statement output by the task decoder; wherein the task decoder is constructed based on the constraint relationship between each query sub-statement of the query statement.

[0120] In this step, the second feature representation of each node and the global feature representation are input into a pre-trained task decoder. The task decoder is constructed based on the constraint relationship between each query sub-statement within the query statement, and through prior training, it can understand these constraints and use them to guide the generation process of the query statement. During the decoding process, the task decoder gradually constructs SQL query statements that meet the user's query intent. These query statements not only contain information such as the data columns and conditions that the user wants to query, but also follow the rules of SQL grammar. Of course, in relevant scenarios, they can also follow the constraints of the database table model. Through this step, the precise conversion from natural language queries to SQL query statements is finally achieved.

[0121] Furthermore, in one embodiment as mentioned above, the method of the present application queries a large data table, and the data table name can be directly determined. Therefore, the relationship diagram does not include the node of the data table name, and the query statement finally generated does not include the data table name of the queried large data table. If the query mechanism of the data query engine requires the query statement to specify the target data table name of the query, then obviously, the target data table information obtained in step S101 also includes the data table name of the large data table, and after obtaining the query statement output by the task decoder in step S105, the data table name is also obtained and a query engine query statement is further generated with the query statement, and the query can be executed based on the query engine query statement.

[0122] In one embodiment, the task decoder includes a feature fusion layer and a task decoding layer; the feature fusion layer is connected to the task decoding layer; the task decoding layer includes a task fusion layer and a first linear layer, a second linear layer, a third linear layer, a fourth linear layer, a fifth linear layer, a sixth linear layer, a seventh linear layer, an eighth linear layer, a ninth linear layer, a tenth linear layer, an eleventh linear layer, and a twelfth linear layer respectively connected to the task fusion layer;

[0123] The step of inputting the second feature representation of each node and the global feature representation into a pre-trained task decoder to obtain a query statement output by the task decoder in step S105 includes:

[0124] Step S1051, performing feature fusion on the global feature representation and the feature representation of the statement node, and inputting the fused feature representation into the first linear layer, the second linear layer, and the third linear layer in sequence, to obtain a first task result, wherein the first task result includes the number of fields of the grouped data filtering condition sub-statement, the number of fields of the field selection sub-statement, and the number of fields of the condition selection sub-statement;

[0125] Step S1052, inputting the feature representation of the statement node to the fourth linear layer, the fifth linear layer, and the sixth linear layer in sequence to obtain a second task result, wherein the second task result includes a conditional connector of a grouped data filtering conditional sub-statement, a conditional operator of a grouped data filtering conditional sub-statement, a conditional connector of a conditional selection sub-statement, and a conditional value of a conditional selection sub-statement;

[0126] Step S1053, performing feature fusion on the embedding representation output by the sixth linear layer and the feature representation of the sentence node, and inputting the fused feature representation into the seventh linear layer to obtain a third task result, wherein the third task result includes a condition value and a condition column of a conditional selection sub-statement in the query sentence;

[0127] Step S1054, performing feature fusion on the global feature representation and the feature representation of the query field node, and sequentially inputting the fused feature representation into the eighth linear layer to obtain a fourth task result, wherein the fourth task result includes the field of the field selection sub-statement;

[0128] Step S1055, performing feature fusion on the embedding representation output by the eighth linear layer and the feature representation of the query field node, and inputting the fused feature representation into the ninth linear layer and the tenth linear layer in sequence to obtain the fifth task result, wherein the fifth task result includes the fields of the sorting sub-statement and the fields of the conditional selection sub-statement;

[0129] Step S1056, inputting the embedding representation output by the eighth linear layer into the eleventh linear layer and the twelfth linear layer in sequence to obtain a sixth task result, wherein the sixth task result includes fields of a grouping sub-statement and a grouping data filtering condition sub-statement;

[0130] Step S1057: input the first task result, the second task result, the third task result, the fourth task result, the fifth task result and the sixth task result into the task fusion layer to obtain an output query statement.

[0131] In this embodiment, the task decoder is designed to include a feature fusion layer and a task decoding layer, where the task decoding layer is further subdivided into multiple linear layers to process feature representations from different nodes and ultimately generate a complete query statement. This design aims to gradually construct a query statement that conforms to the SQL syntax and logical structure through hierarchical processing and feature fusion.

[0132] First, step S1051 fuses the global feature representation with the feature representation of the statement node. This step aims to combine the overall information of the relationship graph with the specific query statement structure. Subsequently, the fused feature representation is sequentially passed through the first linear layer, the second linear layer, and the third linear layer to predict the number of fields required in the grouped data filtering condition sub-statement (Having statement), the field selection sub-statement (select statement), and the condition selection sub-statement (where statement). This prediction provides a basic framework for the subsequent detailed condition generation.

[0133] Next, step S1052 uses only the feature representation of the statement nodes to determine the conditional connectors (such as AND, OR) and conditional operators (such as =, >, <, etc.) in the grouped data filtering condition sub-statement (Having statement) and the conditional selection sub-statement (where statement) through the processing of the fourth to sixth linear layers. This step focuses on refining the conditional logic in the query statement.

[0134] In order to generate specific conditions in the conditional selection sub-statement, step S1053 fuses the embedding representation output by the sixth linear layer with the feature representation of the statement node again, and sends the fused feature representation to the seventh linear layer. The seventh linear layer is responsible for outputting the condition value and the corresponding condition column to ensure that each condition in the query statement is clear and meaningful.

[0135] Step S1054 fuses the global feature representation with the feature representation of the query field node, and generates the fields that should be included in the field selection sub-statement (select statement) through processing in the eighth linear layer. This step ensures that the query results contain the fields that the user is interested in.

[0136] Step S1055 fuses the embedding representation output by the eighth linear layer with the feature representation of the query field node, and then determines the fields in the sorting sub-statement (Order by statement) and other fields that may be involved in the conditional selection sub-statement (where statement) through processing by the ninth and tenth linear layers. This helps to generate more refined query results.

[0137] Step S1056 directly uses the embedded representation output by the eighth linear layer, and generates the fields involved in the grouping sub-statement (Group by statement) and the grouping data filtering condition sub-statement (Having statement) through the processing of the eleventh linear layer and the twelfth linear layer. This step completes the construction of the grouping function in the query statement.

[0138] Finally, step S1057 inputs the results of the above subtasks (i.e., the results of the first to sixth tasks) into the task fusion layer. The task fusion layer is responsible for integrating these task results into a complete query statement that conforms to SQL syntax. This step is the final link in the decoding process, which ensures that the generated query statement is both accurate and efficient.

[0139] This embodiment realizes the automatic generation of complex query statements by introducing a multi-layer linear structure and a feature fusion mechanism. The task decoder can not only predict the various components of the query statement (such as grouping, field selection, conditions, etc.) based on the node feature representation in the relationship graph, but also ensure that each component is accurate through refined processing. This design not only improves the accuracy and efficiency of query statement generation, but also greatly reduces the difficulty and cost of manually writing complex query statements. At the same time, through hierarchical processing and feature fusion, the model is more stable and efficient when processing large-scale data and complex queries.

[0140] The above-mentioned embodiments only express several implementation methods of the present application, and the descriptions thereof are relatively specific and detailed, but they cannot be understood as limiting the scope of the invention patent. It should be pointed out that, for ordinary technicians in this field, several modifications and improvements can be made without departing from the concept of the present application, and the present application is also intended to include such modifications and modifications.

Claims

1. A query statement generation method based on a relationship graph, characterized in that: The following steps are involved: Obtain the natural query statement input by the user and the target data table information queried by the user; The target data table information includes several query fields; Constructing a relationship graph according to the natural query statement and the target data table information; the nodes of the relationship graph include statement nodes and query field nodes; The sentence node is obtained according to the word segmentation of the natural query sentence; The query field node is obtained according to the query field matched by the natural query statement; Inputting the relationship graph into the encoding layer to obtain the relationship representation between each node, the first feature representation of each node, and the global feature representation of each node in the relationship graph; Inputting the relationship representation between the nodes and the first feature representation of each node into the pre-trained relationship graph attention network layer to obtain the second feature representation of each node; Inputting the second feature representation of each node and the global feature representation into a pre-trained task decoder to obtain a query statement output by the task decoder; wherein the task decoder is constructed based on the constraint relationship of each query sub-statement of the query statement; The encoding layer includes a node encoding layer; the node encoding layer includes an embedding layer and an attention network layer; the embedding layer is connected to the attention network layer; The step of inputting the relationship graph into the encoding layer to obtain the relationship representation between each node, the first feature representation of each node, and the global feature representation of each node in the relationship graph includes: Splicing the statement nodes and query field nodes of the relationship graph according to a preset format to obtain a spliced ​​text of the relationship graph nodes; inputting the spliced ​​text of the relationship graph nodes into the embedding layer to obtain a first embedding vector sequence of the spliced ​​text of the relationship graph nodes; the first embedding vector sequence includes the embedding vector corresponding to each statement node and each query field node in the spliced ​​text of the relationship graph nodes; Inputting the first embedding vector sequence into the attention network layer to obtain an output second embedding vector sequence; the second embedding vector sequence includes the embedding vector corresponding to each sentence node and each query field node in the relationship graph node concatenation text, and the global feature vector of the relationship graph node concatenation text; According to the embedding vector corresponding to each sentence node in the text of the relationship graph node splicing, the feature representation corresponding to each sentence node is obtained; according to the embedding vector corresponding to each query field node in the text of the relationship graph node splicing, the feature representation corresponding to each query field node is obtained; according to the global feature vector of the text of the relationship graph node splicing, the global feature representation of each node of the relationship graph is obtained.

2. The query statement generation method based on the relationship graph according to claim 1 is characterized in that: The target data table information includes a number of small data tables, each of which includes a number of query fields; The constructing a relationship graph according to the natural query statement and the target data table information includes: Performing syntactic analysis on the natural query statement, and determining a first dependency relationship between each word segment in the natural query statement according to the syntactic analysis result; Identify the entity participle of the natural query statement, and if the entity participle matches at least one query field in the target data table information, determine a second dependency relationship between the entity participle and the matched query field; if any two matched query fields belong to the same data tablelet, determine a third dependency relationship between the two matched query fields; The nodes of the relationship graph are constructed according to the individual word segments and the matched query fields within the natural query statement, and the corresponding edges between the nodes of the relationship graph are constructed according to the first dependency relationship between the individual word segments within the natural query statement, the second dependency relationship between the entity word segment and the matched query field, and the third dependency relationship between any two query fields belonging to the same data tablelet.

3. The query statement generation method based on the relationship graph according to claim 2 is characterized in that: The syntactic parsing result includes the word-level syntactic relationship of the natural query statement; the first dependency relationship between each word in the natural query statement includes the first dependency type information between each word; the first dependency type information between each word is determined according to the word-level syntactic relationship.

4. The query statement generation method based on the relationship graph according to claim 2 is characterized in that: If the entity segmentation matches at least one query field in the target data table information, before determining the second dependency relationship between the entity segmentation and the matching query field, the method includes the following steps: The entity segmentation is character matched with each query field in the target data table information. If the character mismatch degree between the entity segmentation and any query field is less than a preset threshold, it is determined that the entity segmentation matches the query field.

5. The query statement generation method based on the relationship graph according to claim 4 is characterized in that: The second dependency relationship between the entity participle and the matched query field includes second dependency type information between the entity participle and the matched query field; the second dependency type information includes a complete match type and a partial match type; The method further comprises the steps of: If the character mismatch degree is 0, it is determined that the entity segmentation and the second dependent type information of the query field are a complete match type; if the character mismatch degree is greater than 0 and less than a preset threshold, it is determined that the entity segmentation and the second dependent type information of the query field are a partial match type.

6. The query statement generation method based on the relationship graph according to claim 2 is characterized in that: The target data table information also includes field category information corresponding to each query field; The third dependency relationship includes third dependency type information; the third dependency type information includes the same field category type and different field category types; The method further comprises the steps of: If any two query fields belonging to the same data subtable correspond to the same field category information, the third dependency type information between the two query fields is determined to be the same field category type; otherwise, the third dependency type information between the two query fields is determined to be different field category types.

7. The query statement generation method based on the relationship graph according to claim 1 is characterized in that: The coding layer includes a relation coding layer; The step of inputting the relationship graph into the encoding layer to obtain the relationship representation between each node, the first feature representation of each node, and the global feature representation of each node in the relationship graph includes: The relationship graph is input into the relationship encoding layer to obtain the relationship representation between the output nodes.

8. The query statement generation method based on the relationship graph according to claim 7 is characterized in that: The node encoding layer also includes a pooling layer connected to the attention network layer; the embedding layer includes a character segmentation layer and an embedding calculation layer; the character segmentation layer is used to perform character segmentation on each query field node in the relationship graph node splicing text to obtain a number of characters corresponding to each query field node; the embedding calculation layer is used to calculate a first embedding vector of a number of characters corresponding to each query field node; The embedding vector corresponding to the query field node in the first embedding vector sequence includes a first embedding vector of each character of the query field node; The step of concatenating the embedding vector corresponding to each query field node in the text according to the relationship graph nodes to obtain the feature representation corresponding to each query field node includes: Perform pooling calculation based on the first embedding vectors of each character of each query field node to obtain a second embedding vector of each query field node; Determine a second embedding vector corresponding to each query field node as a feature representation corresponding to each query field node.

9. The query statement generation method based on the relationship graph according to claim 1, characterized in that: The task decoder includes a feature fusion layer and a task decoding layer; the feature fusion layer is connected to the task decoding layer; The task decoding layer includes a task fusion layer and a first linear layer, a second linear layer, a third linear layer, a fourth linear layer, a fifth linear layer, a sixth linear layer, a seventh linear layer, an eighth linear layer, a ninth linear layer, a tenth linear layer, an eleventh linear layer and a twelfth linear layer respectively connected to the task fusion layer; The step of inputting the second feature representation of each node and the global feature representation into a pre-trained task decoder to obtain a query statement output by the task decoder includes: Performing feature fusion on the global feature representation and the feature representation of the statement node, and inputting the fused feature representation to the first linear layer, the second linear layer, and the third linear layer in sequence, to obtain a first task result, wherein the first task result includes the number of fields of the grouped data filtering condition sub-statement, the number of fields of the field selection sub-statement, and the number of fields of the condition selection sub-statement; Inputting the feature representation of the statement node to the fourth linear layer, the fifth linear layer, and the sixth linear layer in sequence to obtain a second task result, wherein the second task result includes a conditional connector of a grouped data filtering conditional sub-statement, a conditional operator of a grouped data filtering conditional sub-statement, a conditional connector of a conditional selection sub-statement, and a conditional value of the conditional selection sub-statement; Perform feature fusion on the embedding representation output by the sixth linear layer and the feature representation of the sentence node, and input the fused feature representation into the seventh linear layer to obtain a third task result, wherein the third task result includes a condition value and a condition column of a conditional selection sub-statement in the query sentence; Performing feature fusion on the global feature representation and the feature representation of the query field node, and sequentially inputting the fused feature representation into the eighth linear layer to obtain a fourth task result, wherein the fourth task result includes a field of a field selection sub-statement; Performing feature fusion on the embedding representation output by the eighth linear layer and the feature representation of the query field node, and inputting the fused feature representation into the ninth linear layer and the tenth linear layer in sequence, to obtain a fifth task result, wherein the fifth task result includes a field of a sorting sub-statement and a field of a conditional selection sub-statement; Inputting the embedding representation output by the eighth linear layer into the eleventh linear layer and the twelfth linear layer in sequence to obtain a sixth task result, wherein the sixth task result includes fields of a grouping sub-statement and a grouping data filtering condition sub-statement; The first task result, the second task result, the third task result, the fourth task result, the fifth task result and the sixth task result are input into the task fusion layer to obtain an output query statement.

10. The query statement generation method based on the relationship graph according to claim 1, characterized in that: The pre-trained relationship graph attention network layer and task decoder are trained in the following way: Acquire a training data set; wherein the training data set includes a plurality of training samples, each training sample includes a relationship representation between nodes of a relationship graph, a first feature representation of each node, a global feature representation of the relationship graph, and corresponding query label information; the query label information includes a standard query statement corresponding to the relationship graph; Input the relationship representation between each node of the relationship graph of each training sample and the feature representation of each node into the initialized relationship graph attention network layer to obtain the second feature representation of each node of each training sample as output; Inputting the second feature representation of each node of each training sample and the corresponding global feature representation into the initialized task decoder to obtain the query statement corresponding to each training sample; Calculate the loss value between the query statement of each training sample and the corresponding query label information; according to the loss value, adjust the parameters of the relationship graph attention network layer and the task decoder until the loss value is less than the preset loss threshold or the total number of weight adjustments reaches the preset number of adjustments, and obtain the trained relationship graph attention network layer and the task decoder.

Citation Information

Patent Citations

  • Knowledge graph link prediction method based on heuristic information search

    CN117973517A

  • Data query method, device and equipment, computer storage medium and program product

    CN118747177A