Structured query statement generation method and device, equipment and storage medium

By acquiring intent information and calculating database graph structure similarity, the target SQL statement is generated, which solves the problem of low accuracy of NL2SQL technology in complex query scenarios and improves the accuracy of generated SQL statements.

CN121277970APending Publication Date: 2026-01-06CHINALCO DIGITAL (CHENGDU) TECHNOLOGY CO LTD
View PDF 0 Cites 1 Cited by

Patent Information

Application Number
CN202511307833.7
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-09-12
Publication Date
2026-01-06

AI Technical Summary

Technical Problem

Existing NL2SQL technology has low accuracy when generating SQL statements from natural language, especially in complex query scenarios.

Method used

By obtaining the intent information in the statement to be generated, the first subgraph structure in the preset database graph structure is determined based on the preset subgraph determination rules. Multiple preset second graph structures are obtained and their structural similarity is calculated. The third graph structure is then determined, and the target SQL statement is generated based on the third graph structure.

Benefits of technology

It enables accurate generation of SQL statements from natural language statements, improving processing capabilities in complex query scenarios.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121277970A_ABST
    Figure CN121277970A_ABST
Patent Text Reader

Abstract

The invention discloses a structured query statement generation method and device, equipment and a storage medium, belongs to the field of data processing, and can accurately generate SQL statements according to natural statements. The method comprises the steps of obtaining a to-be-generated statement, and determining intention information in the to-be-generated statement; based on a preset sub-graph determination rule, determining a first sub-graph structure corresponding to the intention information in a preset database graph structure, the database graph structure being formed based on a plurality of first graph nodes and an association relationship between the first graph nodes, and the first graph nodes being determined based on structure information of a plurality of associated databases; a plurality of preset second graph structures are obtained, the second graph structures with the structural similarity with the first sub-graph structures larger than a first threshold value are determined as third graph structures, and different second graph structures are generated based on different types of preset SQL statements; and determining statement generation parameters in the first sub-graph structure based on the third graph structure, so as to generate a target SQL statement based on the statement generation parameters.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application belongs to the field of data processing, and specifically relates to a method, apparatus, device and storage medium for generating structured query statements. Background Technology

[0002] In its early stages, NL2SQL (Natural Language to SQL) technology primarily employed rule-based methods. These methods relied on manually defined rules and templates to match natural language queries with pre-defined SQL templates, but their effectiveness was limited to simple query scenarios. With the rise of deep learning, NL2SQL technology entered a new phase, incorporating advanced architectures such as sequence-to-sequence (Seq2Seq) models, attention mechanisms, and graph neural networks (GNNs). Representative models like SQLNet, SyntaxSQLNet, and IRNet have improved processing capabilities in various scenarios to some extent, but their accuracy in generating SQL statements from natural language remains relatively low.

[0003] Therefore, there is a need for a method to generate structured query statements that can accurately generate SQL statements from natural language statements. Summary of the Invention

[0004] This application provides a method for generating structured query statements, which can accurately generate SQL statements from natural language statements.

[0005] In a first aspect, embodiments of this application provide a method for generating a structured query statement. The method includes: acquiring a statement to be generated and determining intent information in the statement to be generated, wherein the statement to be generated is a natural statement of a structured query language (SQL) input by a user; determining a first subgraph structure in a preset database graph structure corresponding to the intent information based on preset subgraph determination rules, wherein the database graph structure is composed of multiple first graph nodes and the relationships between the first graph nodes, the first graph nodes are determined based on the structural information of multiple relational databases, and the first subgraph structure is a graph structure in the database graph structure related to the intent information; acquiring multiple preset second graph structures, and determining a third graph structure as the second graph structure whose structural similarity to the first subgraph structure is greater than a first threshold, wherein different second graph structures are generated based on different types of preset SQL statements; determining statement generation parameters in the first subgraph structure based on the third graph structure, and generating a target SQL statement based on the statement generation parameters, wherein the statement generation parameters are parameters required to generate the target SQL statement.

[0006] Secondly, embodiments of this application provide a structured query statement generation apparatus, comprising: a first acquisition module, configured to acquire a statement to be generated and determine intent information in the statement to be generated, wherein the statement to be generated is a natural statement of structured query language (SQL) input by a user; a first determination module, configured to determine a first subgraph structure in a preset database graph structure corresponding to the intent information based on preset subgraph determination rules, wherein the database graph structure is composed of multiple first graph nodes and the association relationships between the first graph nodes, the first graph nodes are determined based on the structural information of multiple relational databases, and the first subgraph structure is a graph structure in the database graph structure related to the intent information; a second acquisition module, configured to acquire multiple preset second graph structures and determine the second graph structures whose structural similarity to the first subgraph structure is greater than a first threshold as third graph structures, wherein different second graph structures are generated based on different types of preset SQL statements; and a second determination module, configured to determine statement generation parameters in the first subgraph structure based on the third graph structure, and generate a target SQL statement based on the statement generation parameters, wherein the statement generation parameters are parameters required to generate the target SQL statement.

[0007] Thirdly, embodiments of this application provide an electronic device including a processor, a memory, and a program or instructions stored in the memory and executable on the processor, wherein the program or instructions, when executed by the processor, implement the steps of the method described in the first aspect.

[0008] Fourthly, embodiments of this application provide a readable storage medium on which a program or instructions are stored, which, when executed by a processor, implement the steps of the method described in the first aspect.

[0009] Fifthly, embodiments of this application provide a chip, the chip including a processor and a communication interface, the communication interface being coupled to the processor, the processor being used to run programs or instructions to implement the method as described in the first aspect.

[0010] In this embodiment, the process involves: acquiring the statement to be generated and determining the intent information within it; determining a first subgraph structure corresponding to the intent information within a preset database graph structure based on preset subgraph determination rules; the database graph structure being composed of multiple first graph nodes and their associated relationships; the first graph nodes being determined based on the structural information of multiple relational databases; the first subgraph structure being a graph structure related to the intent information within the database graph structure; acquiring multiple preset second graph structures and determining the second graph structure with a structural similarity greater than a first threshold to the first subgraph structure as a third graph structure; generating different second graph structures based on different types of preset SQL statements; determining the statement generation parameters in the first subgraph structure based on the third graph structure; and generating the target SQL statement based on the statement generation parameters, thereby accurately generating SQL statements from natural statements. Attached Figure Description

[0011] Figure 1 This is a flowchart illustrating a method for generating structured query statements according to an embodiment of this application; Figure 2 This is a schematic diagram of a database graph structure provided in an embodiment of this application; Figure 3 This is a flowchart illustrating the second method for generating structured query statements provided in this application embodiment; Figure 4 This is a flowchart illustrating the third method for generating structured query statements provided in this application embodiment; Figure 5 This is a schematic diagram of a structured query statement generation device provided in an embodiment of this application; Figure 6 This is a schematic diagram of the structure of a structured query statement generation device provided in an embodiment of this application. Detailed Implementation

[0012] The technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.

[0013] The terms "first," "second," etc., used in the specification and claims of this application are used to distinguish similar objects and not to describe a specific order or sequence. It should be understood that such use of data can be interchanged where appropriate so that embodiments of this application can be implemented in orders other than those illustrated or described herein, and the objects distinguished by "first," "second," etc., are generally of the same class and the number of objects is not limited; for example, a first object can be one or more. Furthermore, in the specification and claims, "and / or" indicates at least one of the connected objects, and the character " / " generally indicates that the preceding and following objects are in an "or" relationship.

[0014] The method for generating structured query statements provided in this application will be described in detail below with reference to the accompanying drawings, through specific embodiments and application scenarios.

[0015] Figure 1 This illustration shows a method for generating structured query statements according to an embodiment of the present invention. This method can be executed by an electronic device, which may include a server and / or a terminal device, wherein the terminal device may be, for example, an in-vehicle terminal or a mobile phone terminal. In other words, the method can be executed by software or hardware installed on a structured query statement generation device, and the method includes the following steps: Step 102: Obtain the statement to be generated and determine the intent information in the statement to be generated.

[0016] The statement to be generated is a natural statement in Structured Query Language (SQL) input by the user.

[0017] The execution entity of the structured query statement generation method described in this application can be a structured query statement generation system, structured query statement generation software, or other execution entities. This application embodiment will be described using a structured query statement generation system (hereinafter referred to as the statement generation system) as an example.

[0018] The statement generation system first obtains the natural language statement to be converted into an SQL statement (the statement to be generated). Then, it determines the intent information within this natural language statement. This intent information represents the relevant information the user wants to convert into an SQL statement. The statement generation system inputs the statement to be generated into a pre-trained intent recognition model (such as a large language model). The intent recognition model analyzes the text features of the statement to be generated, such as keywords and grammatical structure, to determine the entities, relationships, and constraints related to the SQL statement contained within the statement. This intent information, representing the user's intent, can be keywords, key terms, or a sentence containing the intent. For example, in a financial system database query scenario, the statement to be generated input by the user (financial accountant) could be "Please list the names of products whose revenue this quarter is lower than the same period last month and the difference." The intent information determined by the statement to be generated could be information such as "this quarter," "last month," "products in the same period," "name," and "difference," or it could be a sentence containing the user's intent, such as "Compare the price difference of the same products this quarter and last month."

[0019] Specifically, after determining the intent information, the statement generation system can represent the intent information in JSON format. For example, when the user inputs the statement "Please list the names of products whose revenue this quarter is lower than the same period last month and the difference between them," the intent information determined by the statement generation system can be: json { "intent": "nested comparison", "entities": ["amount"], "constraints": [ {"field": "transaction date", "op": "BETWEEN", "value": "2023Q4"}, {"field": "amount", "op": "<", "value": "value for the same period last month"} ] } Step 104: Based on the preset subgraph determination rules, determine the first subgraph structure in the preset database graph structure that corresponds to the intent information.

[0020] The database graph structure is composed of multiple first graph nodes and the relationships between them. The first graph nodes are determined based on the structural information of multiple related databases. The first subgraph structure is a graph structure in the database graph structure that is related to the intent information.

[0021] After determining the intent information, the statement generation system obtains the preset subgraph determination rules and the preset database graph structure. Then, according to the subgraph determination rules, it determines the first subgraph structure in the database graph structure that corresponds to the intent information. The subgraph determination rules are used to determine the subgraph structure corresponding to different intents. The first subgraph structure is the subgraph structure corresponding to the intent information of the statement to be generated. The database graph structure is composed of the structural information of multiple relational databases as graph nodes and the relationship between the structural information as node relationships. The structural information of the relational database can be table name information, table name related information (related information of table name), field name information and field related information (related information of field name), etc. The node relationships can be containment relationships, reference relationships (such as the primary key being the referenced end and the foreign key being the referrer end), etc. For example, table name information obtained from a relational database could include: master txn table (master transaction table), product service (product service table), chart of accounts (chart of accounts table), customers (customer table), vendors (supplier table), employees (employee table), payment method (payment method table), etc. Field name information could include fields such as transaction id (transaction ID), transaction date (transaction time), transaction type (transaction action type), amount (transaction amount), customer name (transaction user), and product service (product or service) in the master txn table (master transaction table), and fields such as productservice and product service type in the product service table (product service table).

[0022] In other words, the statement generation system pre-acquires the structural information of multiple relational databases, and then uses each structural information as a first graph node. For example, the table name information "master txn table" (the main transaction table) is used as the first graph node, and the field name information "transaction id" is used as the first graph node. Then, based on the table name information and field information, the relationships between the first graph nodes are determined. These relationships include table-field relationships between tables and fields, and field-field relationships between fields. For example, the field name information "transaction id" belongs to "master txn table" (the main transaction table), the field "amount" belongs to "master txn table", etc. The foreign key "master txn table.product service" references the primary key "product service.product service", and the foreign key "master txn table.account" references the primary key "chart of accounts.account name", etc.

[0023] After determining the database graph structure, the statement generation system identifies the subgraph structure corresponding to the intent information within the database graph structure according to subgraph determination rules, and designates it as the first subgraph structure. Specifically, the database graph structure is composed of structural information from multiple relational databases and the relationships between these structural information. Therefore, the database graph structure contains relevant information about the intent information (or the SQL statement to be generated). For example, in a financial database query scenario, the database graph structure contains various transaction-related structural information. Thus, it can determine multiple structural information corresponding to the intent information of the statement to be generated based on the database graph structure. This structural information is stored in the database graph structure as relationships between nodes. Furthermore, it can determine multiple graph nodes related to the intent information and, based on these determined graph nodes and their relationships, determine the first subgraph structure. Furthermore, the subgraph determination rule is used to determine the subgraph structure that matches the intent information. It can be to determine multiple graph nodes that match the intent information and then determine the subgraph structure by identifying the multiple matching graph nodes and the relationships between the graph nodes. Alternatively, it can be to determine the graph node that best matches the intent information and determine the subgraph structure by identifying that graph node, its adjacent graph nodes, and the relationships between the graph nodes.

[0024] Similarly, the determined first subgraph structure can also be output in JSON format. For example, when the user inputs the statement "Please list the names of products whose revenue this quarter is lower than the same period last month and the difference therebetween," the statement generation system can determine the first subgraph structure as follows: json { "tables": ["master txn table", "product service"], "fields": ["product service", " amount ", "transaction date"], "relationships": ["HAS PRODUCT"] Step 106: Obtain multiple preset second graph structures, and determine the second graph structure whose structural similarity with the first subgraph structure is greater than a first threshold as the third graph structure.

[0025] Here, different second graph structures are generated based on different types of preset SQL statements, and the first threshold is a pre-set threshold. Preferably, when there are multiple first subgraph structures with a structure similarity greater than the first threshold, the statement generation system can determine the second graph structure with the highest structural similarity as the third graph structure.

[0026] The statement generation system acquires multiple pre-defined second graph structures, each generated based on different types of SQL statements. In other words, the system pre-acquires various types of SQL statements and then determines the corresponding second graph structure for each statement based on the entities and relationships within them. Because the entities in the SQL statements represent partial information of the relational database structure, and the entity relationships represent partial information of the associations between relational database structures, the different second graph structures generated based on different types of SQL statements can represent a portion of the database graph structure. For example, when the SQL statement queries the price of product A last month, its corresponding second graph structure is product A-time-price, and the database graph structure also contains the association between product, time, and price.

[0027] After acquiring multiple preset second graph structures, the statement generation system compares the first subgraph structure with these second graph structures, determines the structural similarity between each second graph structure and the first subgraph structure, and then identifies the second graph structure with a structural similarity greater than a first threshold as the third graph structure. Specifically, different second graph structures are generated based on different types of SQL statements, therefore, the structures of different second graph structures are not identical. When the similarity between the first subgraph structure and the second graph structure is greater than the first threshold, it indicates a high degree of matching between the user intent corresponding to the first subgraph structure and the identified second graph structure (i.e., the third graph structure). In other words, the operation required by the user intent is the operation of the SQL statement corresponding to the third graph structure.

[0028] Specifically, when calculating structural similarity, the sentence generation system first represents the first subgraph structure and each graph structure as an abstract syntax tree, and then calculates the structural similarity (Abstract Syntax Tree, AST) between them. The structural similarity is defined as follows:

[0029]

[0030] Here, G1 and G2 are two ASTs, △(G1, G2) is the minimum tree edit cost required to transform G1 into G2, MaxNodes(G1, G2) is the maximum number of nodes in the two ASTs, OPi represents the i-th edit operation, and W(OPi) is the cost weight of the operation, which is usually set to 1.

[0031] The sentence generation system can determine the third graph structure not only based on structural similarity alone, but also based on both structural and vector similarity. Specifically, it determines the structural and vector similarity between the first subgraph structure and each second graph structure, then performs a weighted sum of these similarities, and finally determines the third graph structure based on the weighted result. Second graph structures with a weighted result greater than a preset threshold are identified as the third graph structure. Furthermore, the system calculates the feature vectors of the first subgraph structure and each second graph structure separately, and then calculates their similarity. The similarity calculation formula can be:

[0032] Where A is the feature vector of the first subgraph structure and B is the feature vector of the second graph structure.

[0033] For example, the database graph structure includes the following table information: table: master txn table (fields: transaction id, transaction date, product service, amount, ...) table: productservice (fields: product service, product service type); foreign key: master txn table.product service = product service.product service, with the following rules and constraints: current quarter date range: 2023-10-01 to 2023-12-31; same period of the previous month: 2023-09-01 to 2023-09-30. The information for the third graph structure whose similarity value is greater than the threshold can be determined as follows: SELECT A.product service, (A.monthly sales - B.monthly sales) AS diff FROM (SELECT product service, SUM(credit) AS monthly sales ...) A JOIN (SELECT product service, SUM(credit) AS monthly sales ...) B ON A.product service = B.product service WHERE A. monthly sales <B.monthly sales Step 108: Determine the statement generation parameters in the first subgraph structure based on the third graph structure, and generate the target SQL statement based on the statement generation parameters.

[0034] The statement generation parameters are the parameters required to generate the target SQL statement.

[0035] After determining the third graph structure, the statement generation system uses this structure to determine the statement generation parameters in the first subgraph structure. These parameters are those required to generate the SQL statement to be generated, such as time, product, and price. Because the SQL statement operations corresponding to the third graph structure correspond to the user's intent, the system can determine the parameter types required to execute the SQL statement corresponding to the user's intent based on the entities and entity relationships included in the third graph structure. Then, it retrieves the specific parameter values ​​from the first subgraph structure and generates the target SQL statement based on the determined parameter types and values.

[0036] Specifically, the target SQL phrase generated based on the statement generation parameters can be: SQL SELECT curr.product service, (curr.monthly sales - prev.monthly sales) AS sales diff FROM (SELECT product service, SUM(amount) AS monthly sales FROM master txn table WHERE transaction date BETWEEN '2023-10-01' AND '2023-12-31' GROUP BY product service curr JOIN ( SELECT product service, SUM(amount) AS monthly sales FROM master txn table WHERE transaction date BETWEEN '2023-09-01' AND '2023-09-30' GROUP BY product service ) prev ON curr.product service = prev.product service WHERE curr.monthly sales <prev.monthly sales; ``` The method for generating structured query statements provided in this invention involves: acquiring a statement to be generated and determining intent information within it; determining a first subgraph structure corresponding to the intent information within a preset database graph structure based on preset subgraph determination rules; the database graph structure being composed of multiple first graph nodes and their relationships, with each first graph node determined based on the structural information of multiple relational databases; acquiring multiple preset second graph structures and determining the second graph structure with a structural similarity greater than a first threshold to the first subgraph structure as a third graph structure; generating different second graph structures based on different types of preset SQL statements; determining statement generation parameters in the first subgraph structure based on the third graph structure; and generating a target SQL statement based on these parameters, thus accurately generating SQL statements from natural language statements.

[0037] In one implementation, before determining the first subgraph structure corresponding to the intent information in the preset database graph structure based on the preset subgraph determination rules (step 104), steps A1-A4 may also be performed: Step A1: Obtain the structural information of the multiple related databases.

[0038] The structure information includes table name information and multiple field information for each of the associated databases. The field information includes one or more of the following: field name information, field data information, field type information, and field constraint information.

[0039] Before determining the first sub-graph structure corresponding to the intent information in the preset database graph structure, the database graph structure needs to be generated and determined in advance. When generating the database graph structure, the statement generation system first obtains the structure information of multiple relational databases. The obtained structure information can be table name information and field information, and the field information can be one or more of the following: field name information, field data information, field type information, and field constraint information.

[0040] Step A2: Determine the first graph node based on the table name information and the field name information, and determine the first attribute information of each first graph node based on the field data information, the field type information and the field constraint information.

[0041] After obtaining the structural information of the relational database, the statement generation system determines the table names and field names included in the relational database based on the table name and field name information, and then uses both table names and field names as first graph nodes. The statement generation system also obtains the field type information, field data information, and field constraint information corresponding to each field, and uses the obtained information as the attribute information of the first graph node corresponding to that field.

[0042] In other words, the statement generation system maps each table to a graph node, with the node name being the table name. It also maps each field to a graph node, with the node name being the field name or field type (e.g., user id INT). For example, when the table is a main transaction table, the graph nodes could be transaction ID nodes, transaction date nodes, transaction type nodes, transaction amount nodes, transaction name nodes, etc.

[0043] Specifically, the statement generation system uses database system table queries to obtain full table structure information, including table names, field names, data types, and constraints. Simultaneously, the table names and field names are extracted as independent entities for subsequent processing.

[0044] Step A3: Determine the first association relationship between the nodes of the first graph based on the structural information of the multiple relational databases.

[0045] After identifying the first graph nodes, the statement generation system determines the first associations between these nodes based on the structural information of the relational database. These first associations include inter-table relationships, inter-field relationships, and table-field relationships. Inter-table relationships are between different tables; inter-field relationships are between different fields; and table-field relationships are between tables and fields. For example, first associations include containment relationships between tables and fields, and reference relationships between fields. When determining the first associations, the statement generation system can identify unique entity identifiers by analyzing PRIMARY KEY constraints or auto-incrementing fields, and infer inter-table relationships through explicit foreign key declarations or field naming patterns (e.g., user id → user.id). Simultaneously, it identifies the dependency relationships between fields and tables, determining which table a field belongs to.

[0046] Specifically, when determining the initial relationships between nodes in the first graph, the statement generation system can determine these relationships not only through a pre-trained large language model but also through user input. When determining relationships based on the large language model, the system inputs the attribute information of each first graph node and the structural information of the relational database into the large language model, enabling it to determine relationships based on the structural information. When determining relationships based on user input, the system retrieves SQL logs from historical user operations, analyzes high-frequency join operations, and determines the relationships between fields based on the logs and operation information, thereby establishing the relationships between nodes in the first graph.

[0047] Step A4: Generate the database graph structure based on the first graph node, the first association relationship, and the first attribute information corresponding to the first graph node.

[0048] After determining the first graph nodes, the first associations, and the first attribute relationships corresponding to each first graph node, the statement generation system generates a database graph structure based on these relationships. In the generated database graph structure, the first associations are represented as directed edges between the first graph nodes, and the first attribute information is represented as the label information for each first graph node.

[0049] In other words, the statement generation system will form a directed edge based on the relationship between two first-graph nodes. For example, it will convert foreign key relationships into directed edges, with type naming reflecting business semantics and edge attributes recording associated fields and constraints. Simultaneously, it will establish directed edges between tables and fields, with the edge type named "contains" to indicate that the field belongs to a certain table. For instance, when the two first-graph nodes are "master txn table" and "amount", a directed edge can be determined from "master txn table" to "amount"; when the two first-graph nodes are "product service STR" and "product service STR", a directed edge can be determined from "product service STR" to "product service STR", which can be represented as: json { "type": "HAS PRODUCT", / / Indicates the product associated with the transaction record "source": "master txn table", "target": "product service", "properties": {"foreign key": "product service"} } Figure 2 This is a schematic diagram of a database graph structure provided in one embodiment of this specification, such as... Figure 2As shown, the nodes in the graph are: Table: master txn table (main transaction table), producer service (product service table), fields: transaction id (transaction ID), transaction date (transaction time), product service (transaction service, foreign key), amount (transaction amount), product service (transaction service, primary key), product service type (category). Among them, the master txn table (main transaction table) contains transaction id (transaction ID), transaction date (transaction time), and product service (transaction service, foreign key). The product service (product service table) contains product service (transaction service, primary key) and product service type (category). The product service (transaction service, foreign key) points to the product service (transaction service, primary key). The first subgraph structure determined based on the user's intent information can be represented by the master transaction table, amount (transaction amount), transaction date (transaction time), product service (transaction service, foreign key), product service (product service table), and product service (transaction service, primary key). The statement generation system can then retrieve the necessary parameters from the first subgraph structure based on the matched third graph structure to generate the target SQL statement. Therefore, the statement generation system determines the graph nodes according to the information of each field in the tables, ensuring that the generated database graph structure contains graph nodes corresponding to multiple tables and the relationships between graph nodes corresponding to multiple fields.

[0050] In one implementation, determining the first subgraph structure corresponding to the intent information in the preset database graph structure based on preset subgraph determination rules (step 104) can be performed via steps B1-B3: Step B1: Determine the semantic similarity between the first attribute information and the intent information of each first graph node, and determine the first graph node with the semantic similarity greater than the second threshold as the initial node.

[0051] When determining the first subgraph structure corresponding to the intent information, the statement generation system first determines the semantic similarity between each first graph node and the intent information based on the attribute information of each first graph node, and determines the first graph node corresponding to the first attribute information with a similarity greater than a second threshold as the initial node. In other words, after determining the intent information, the statement generation system maps the structured objects in the database graph structure according to the entity, relation, and constraint information in the intent information.

[0052] Specifically, when determining the initial node, the statement generation system uses its first attribute information to determine the semantic similarity between each first graph node and the intent information. If the semantic similarity is greater than a second threshold, it indicates a high similarity between the first graph node and the intent information. Therefore, this first graph node is used as the initial node to determine the parameters required to generate the target SQL statement. The second threshold is a pre-set threshold. When there are multiple first graph nodes with semantic similarity greater than the second threshold, the statement generation system can determine the first graph node with the highest semantic similarity as the initial node.

[0053] Step B2: Determine the first graph nodes that are associated with the initial node among the multiple first graph nodes as the first related graph nodes.

[0054] After determining the initial node, the statement generation system identifies the first graph node in the database graph structure that has a relationship with the initial node, and designates this first graph node as the first related graph node. This relationship can be a direct connection or an indirect connection. In other words, determining the initial node does not provide all the parameters needed to generate the SQL statement; only some key parameters are available. Therefore, it is necessary to determine the first graph node that has a relationship with the initial node. This related first graph node also possesses some data related to the intent information. The statement generation system can supplement the parameters needed to generate the SQL short statement based on the attribute information of the determined first related graph node, thus determining the parameters required for generating the complete SQL statement.

[0055] Specifically, the statement generation system can traverse the related nodes of the initial node through a process of iteration. For example, it can use a bidirectional search path discovery algorithm: Step 1. Forward expansion: Based on the entities and relationships output in the query parsing, set them as seed nodes (starting points) and gradually expand the search range to find possible paths; Step 2. Backward tracing: Based on the entities and relationships output in the query parsing, start from the target constraint node (end point) and trace the path backward to ensure the connectivity of the path; Step 3. Loop detection: To avoid repeatedly visiting nodes during the search process and to prevent getting stuck in a loop, node access markers are used to avoid repeated traversal, thereby optimizing the search time complexity.

[0056] Step B3: Determine the structure of the first subgraph based on the initial node and the first related graph node.

[0057] After determining the initial node and the first related graph node, the statement generation system determines the first subgraph structure based on the initial node, the first related graph node, and the relationship between them. That is, the first subgraph structure is part of the database graph structure.

[0058] Specifically, the database graph structure contains multiple structural information from various relational databases. Some of the data information contained in these structural information is related to user intent information, while some is not. Therefore, the statement generation system first determines the initial node in the database graph structure that is most relevant to user intent. Then, based on the initial node, it determines the related nodes that are related to user intent. Finally, it cuts out all the structural parts related to intent information from the complete database graph nodes to determine the first subgraph structure. This ensures that the determined subgraph structure contains only data information related to user intent.

[0059] Therefore, when constructing the database graph structure, the statement generation system first creates a node for each table: for each table in the relational database, a corresponding node is created in the graph database. The node's label is the table name, and its type is "Table". The node's attributes include the fields in the table, but only those fields that are crucial to the business logic are retained. Secondly, a field node is created for each field: for each field in the table, a separate node is also created in the graph database. This field node is of type "Field", and its attributes include the field name (fieldName) and the field type (fieldType). For example, the field name is "username", and the type is VARCHAR (a variable-length string data type in SQL). Finally, attribute indexes are created: for frequently queried fields, attribute indexes are created for these fields in the graph database to speed up queries and improve efficiency. To establish relationships between tables, the statement generation system identifies foreign key relationships through specific logic. Specifically, when the primary key (as a unique identifier) ​​of one table matches the foreign key of another table, a directed edge is created in the graph database. The type of this edge reflects the business semantic relationship between them, thus establishing the connection between the tables. Furthermore, to further clarify the dependency relationship between fields and tables, associations are established between field nodes and table nodes. By checking whether a field belongs to a certain table's field set, a directed edge is created for each field node pointing to its parent table node. The edge type is named "BELONGS TO," indicating that the field belongs to that table. This approach not only supports multiple foreign key scenarios but also ensures that the relationship between fields and tables is clearly represented in the graph database.

[0060] In one implementation, determining the semantic similarity between the first attribute information and the intent information of each first graph node (step B1) can be performed via steps C1-C4: Step C1: Determine the first feature vector information of each first graph node based on the field name information of each first graph node, and determine the second feature vector information corresponding to the intent information.

[0061] When determining the semantic similarity between each first graph node and the intent information based on the first attribute information, the sentence generation system first determines the first feature vector information of each first graph node based on the field name information of each first graph node, and then determines the corresponding second feature vector information based on the intent information. Furthermore, the sentence generation system can not only determine the feature vector corresponding to the field name information of the first graph node as the first feature vector of that first graph node, but also obtain the first attribute information corresponding to the first graph node and determine the feature vector corresponding to the first attribute information as the first feature vector information of that first graph node.

[0062] Step C2: Determine the feature vector similarity between each of the first feature vectors and the second feature vectors.

[0063] After determining the first feature vector of each first graph node and the second feature vector of the intent information, the statement generation system determines the feature vector similarity between each first feature vector and the second feature vector, and then determines the feature vector similarity between each first graph node and the intent information.

[0064] After determining the feature vector similarity of each first and second feature vector, the sentence generation system can directly determine the feature similarity as semantic similarity, and then determine the first graph node corresponding to the first feature vector whose feature vector similarity is greater than a preset threshold as the initial node. The sentence generation system adopts the BGE-m3 model, embeds the query as a high-dimensional vector, and performs an approximate nearest neighbor search in the graph embedding space through the HNSW index.

[0065] Step C3: Determine the text similarity between the field data information and the intent information of each of the first graph nodes.

[0066] When determining the semantic similarity between each first graph node and the intent information based on the first attribute information, the sentence generation system can also first obtain the field data information of each first graph node, then obtain the intent information, and then determine the text similarity between each field data information and the intent information. Furthermore, the sentence generation system can not only determine the text similarity between each first graph node and the intent information based on the field data information, but also obtain the first attribute information of each first graph node and determine the text similarity between each first attribute information and the intent information.

[0067] After determining the text similarity between each first-image node and the intent information, the sentence generation system can also directly determine the text similarity as semantic similarity, and then determine the first-image nodes with text similarity greater than a preset threshold as initial nodes. The short sentence generation system can map the attributes and tags in the nodes to a list of nodes containing those attributes, and quickly locate nodes containing specific keywords in keyword retrieval.

[0068] Specifically, the first attribute information corresponding to each first graph node is also used for text similarity comparison. Therefore, for numeric types (such as INT integers and FLOAT decimals) and date types (such as DATE year-month-day and DATETIME year-month-day hour-minute-second), the statement generation system directly maps the values ​​of these fields to the attributes of the graph database nodes without additional processing. However, for text types (such as VARCHAR and TEXT), not only are their values ​​mapped to the attributes of the graph database nodes, but full-text indexing is also enabled for these attributes. Full-text indexing can improve the efficiency of searching text content and support complex text queries, such as fuzzy matching and keyword search.

[0069] Step C4: Determine the semantic similarity between each of the first graph nodes and the intent information based on the feature vector similarity and the text similarity.

[0070] The sentence generation system can determine semantic similarity not only based on feature vector similarity or text similarity alone, but also by weighting feature vector similarity and text similarity, and then determining semantic similarity based on the weighted result. For example, the sentence generation system assigns different weight coefficients to the results of intent information retrieval and feature vector detection, and calculates the final ranking score through weighted calculation. The semantic similarity calculation formula can be:

[0071] Wherein, final score is the semantic similarity between the first graph node and the intent information, 'a' is an adjustable weight coefficient, keyword score is the keyword retrieval score (text similarity), and vector score is the vector retrieval score (feature vector similarity).

[0072] Therefore, it is evident that the sentence generation system can determine semantic similarity through keyword retrieval, vector retrieval, and hybrid retrieval. Keyword retrieval is based on full-text search of node attributes using the Lucene index; vector retrieval uses the BGE-m3 model to generate node embeddings and construct an HNSW (Hierarchical Navigable SmallWorld) graph vector index; and hybrid retrieval is based on a linear weighted fusion of keyword and vector scores. When determining semantic similarity through hybrid retrieval, it not only captures content related to the query semantics but also ensures that nodes containing key information are not missed. Furthermore, hybrid retrieval addresses the "lexical gap" problem through query expansion, further broadening the search scope. This method performs exceptionally well in handling complex queries, leveraging the advantages of both retrieval methods to provide high-quality search results.

[0073] In one implementation, determining the first subgraph structure based on the initial node and the first related graph node (step B3) can be performed by steps D1-D2: Step D1: Based on the first attribute information of each first related graph node, determine the edge feature vector similarity between each first related node and the intent information.

[0074] When determining the structure of the first subgraph based on the initial node and the first related graph node, the sentence generation system can also determine the edge feature vector similarity between each first related node and the intent information based on the first attribute information of each first related node. The edge feature vector similarity is used to characterize the similarity between the intent information and the edge type vector. The edge type vector is the vector of the association relationship between the first related graph node and the initial node. This similarity can be cosine similarity.

[0075] After identifying multiple primary related graph nodes, the sentence generation system determines that all of these nodes are related to the intent information. However, the number of identified primary related graph nodes may be large. Therefore, the sentence generation system can perform a simplification operation on these nodes. During this simplification process, the system obtains the primary association (i.e., edge type) between each primary related graph node and the initial node. Then, it determines the similarity between this primary association and the intent information. Specifically, the variable type vector is used to represent the similarity between the association between each primary related graph node and the initial node and the intent information.

[0076] Specifically, when calculating edge feature vector similarity, the statement generation system can directly determine the edge feature vector similarity from the determined cosine similarity, or it can weight the edge feature vectors and edge occurrence frequencies, and determine the edge feature vector similarity based on the weighted result. The edge occurrence frequency is used to characterize the frequency of occurrence of the correlation between the first relevant graph node and the initial node in the database graph nodes, i.e., the frequency of occurrence of the edge type in the database graph structure. In other words, the statement generation system assigns weights to each edge in the database graph structure, and then uses an improved Dijkstra algorithm to prioritize retaining high-weight paths and pruning low-weight branches. Through subgraph pruning, redundant join operations can be effectively reduced by 70%. The weight calculation formula is as follows:

[0077] Here, `cosine_sim(query, edge_type)` calculates the cosine similarity between the query vector and the edge type vector. Cosine similarity measures the similarity of two vectors in a direction; the closer the value is to 1, the more similar they are. `edge_frequency` is the frequency of an edge's occurrence in the graph; a higher frequency indicates a more important edge in the graph. Taking the logarithm of the edge frequency smooths out the influence of frequency.

[0078] Step D2: The first relevant node whose edge feature vector similarity is greater than the third threshold is determined as the second relevant graph node, so as to determine the first subgraph structure based on the initial node and the second relevant graph node.

[0079] After the edge feature vectors corresponding to each first related graph node, the statement generation and determination system determines the first related graph node whose edge feature vector is greater than the third threshold as the second related graph node, and then determines the first subgraph structure based on the initial node and the determined second related graph node.

[0080] Figure 3 This is a flowchart illustrating a second method for generating structured query statements according to an embodiment of this specification, as shown below. Figure 3 As shown, the schematic diagram includes: Step 302: Obtain the statement to be generated and determine the intent information in the statement to be generated.

[0081] The statement to be generated is a natural statement in Structured Query Language (SQL) input by the user.

[0082] Step 304: Obtain the structure information of the multiple related databases.

[0083] The structure information includes table name information and multiple field information for each of the associated databases. The field information includes one or more of the following: field name information, field data information, field type information, and field constraint information.

[0084] Step 306: Determine the first graph node based on the table name information and the field name information, and determine the first attribute information of each first graph node based on the field data information, the field type information and the field constraint information.

[0085] Step 308: Determine the first association relationship between the nodes of the first graph based on the structural information of the multiple relational databases.

[0086] Step 310: Generate the database graph structure based on the first graph node, the first association relationship, and the first attribute information corresponding to the first graph node.

[0087] Step 312: Determine the semantic similarity between the first attribute information and the intent information of each first graph node, and determine the first graph node with the semantic similarity greater than the second threshold as the initial node.

[0088] Step 314: Determine the first graph nodes that are associated with the initial node among the multiple first graph nodes as the first related graph nodes.

[0089] Step 316: Based on the first attribute information of each first related graph node, determine the edge feature vector similarity between each first related node and the intent information.

[0090] Step 318: The first related node whose edge feature vector similarity is greater than the third threshold is determined as the second related graph node, so as to determine the first subgraph structure based on the initial node and the second related graph node.

[0091] The first subgraph structure is a graph structure in the database graph structure that is related to the intent information.

[0092] Step 320: Obtain multiple preset second graph structures, and determine the second graph structure whose structural similarity with the first subgraph structure is greater than a first threshold as the third graph structure.

[0093] The different structures in the second diagram are generated based on different types of preset SQL statements.

[0094] Step 322: Determine the statement generation parameters in the first subgraph structure based on the third graph structure, and generate the target SQL statement based on the statement generation parameters.

[0095] The statement generation parameters are the parameters required to generate the target SQL statement.

[0096] In the embodiments described in the specification, by determining table name information and field name information as graph nodes and determining the association relationship between tables and fields as directed edges, the database graph structure is determined, and a second graph structure is generated based on the sample SQL statement. This allows the system to determine the complete parameters required to generate the SQL statement corresponding to the user's intent within the database graph structure, and to determine the second graph structure corresponding to the user's intent based on the subgraph structure corresponding to the user's intent. This provides guidance for generating the target SQL statement, thereby accurately generating the target SQL statement. By first determining the initial node that matches the intent information, and then traversing to determine the related nodes that have an association relationship with the initial node, the system can ensure that the statement generation system obtains the complete parameter information required to generate the target SQL statement.

[0097] In one implementation, obtaining multiple preset second graph structures (step 106) can be performed via steps E1-E3: Step E1: Obtain multiple preset sample SQL statements of different types, and determine the condition information, action information, and multiple sample field name information included in each sample SQL statement.

[0098] Before obtaining multiple preset second graph structures, the statement generation system first needs to generate multiple different second graph structures based on different sample SQL statements. When generating the second graph structure, the statement generation system first obtains multiple preset sample SQL statements of different types, and then determines the entities and entity relationships included in the SQL statements, that is, obtains the condition information, action information and multiple sample field name information included in the SQL statements.

[0099] Specifically, different sample SQL statements correspond to different SQL operations, and with a greater diversity of sample SQL statement types, the system can determine the corresponding target SQL statement based on more types of intent information. When acquiring sample SQL statements, the statement generation system can obtain various types of SQL phrases through multiple methods, such as historical query logs: extracting high-frequency SQL patterns from historical query logs. These patterns are SQL statements frequently appearing in actual user queries, reflecting common query needs; and manually written sample templates: combining manually written templates that cover various complex SQL operations, such as JOIN joins, aggregations, and nested queries, to ensure the comprehensiveness and diversity of the template library.

[0100] Specifically, the sample SQL statement can be: SQL SELECT A.product service, (A.rev - B.rev) AS diff FROM (SELECT ... GROUP BY product service) A JOIN (SELECT ... GROUP BY product service) B ON A.product service =B.product service WHERE A.rev <B.rev Step E2: Determine the second graph node based on the sample field name information, and determine the second association relationship between each second graph node based on the condition information and the action information.

[0101] After obtaining the sample SQL statement, the statement generation system uses syntax tree parsing technology to analyze the structured features of the sample SQL statement. By parsing clauses such as join / where, it determines the node types and variable relations, i.e., second graph nodes and second associations. The statement generation system identifies the representations and field names in the from clause and maps them to second graph nodes. It converts join conditions into edge types and standardizes WHERE conditions into (field, operator, value) triples so that the extracted graph structure can be structurally represented in JSON, preserving the complete logical hierarchy of the original SQL.

[0102] Specifically, the second association information determined by abstract syntax tree parsing of the sample SQL statement can be: Node type: product service (field node), master txn table (table node); Edge relationship: inner join (JOIN condition is A.product service = B.product service); Constraint feature: WHERE A.rev <B.rev。

[0103] Step E3: Determine the second graph structure corresponding to each sample SQL statement based on the second graph nodes and the second association relationship.

[0104] After determining the nodes of the second graph and the second association, the statement generation system determines the relationships between the nodes of the second graph based on the second association and forms directed edges between the nodes of the second graph to form the second graph structure corresponding to each sample SQL statement.

[0105] In one implementation, after generating the target SQL statement based on the statement generation parameters (step 108), steps F1-F2 can also be executed: Step F1: Perform a statement error identification operation on the target SQL statement to determine whether there is any error information in the target SQL statement.

[0106] After determining the target SQL statement, the statement generation system can directly process the target SQL statement and also perform error identification to determine whether there are any errors in the target SQL statement. If there are no errors, the system can then input the statement. If there are errors in the target SQL statement, the system needs to correct the target SQL statement and output the corrected target SQL statement if there are no errors. The error information refers to the relevant information about the errors that exist in the target SQL statement.

[0107] Specifically, errors in the target SQL statement can be lexical-syntax related issues or semantic related issues. Therefore, the error identification operation performed by the statement generation system on the target SQL statement can be lexical-syntax analysis and semantic verification. Lexical-syntax analysis involves detecting basic syntax errors based on a finite state automaton (FSM); using regular expressions to intercept high-risk operations (such as DROP TABLE, DELETE FROM, etc.) and triggering an immediate termination mechanism. Semantic verification involves constructing a symbol table using database metadata to verify the existence of table names / field names; and using the Hindley-Milner type inference algorithm to verify the type consistency of WHERE conditions (e.g., preventing errors like age>'abc'). Step F2: If yes, then the error type is determined based on the error information, and the target SQL statement is corrected based on a preset response strategy corresponding to the error type.

[0108] If an error is detected in the target SQL statement, the statement generation system identifies the error and determines its type. Then, it corrects the target SQL statement according to the pre-defined response strategies corresponding to each error type. For example, the correspondence between error types and pre-defined response strategies can be:

[0109] Figure 4 This is a flowchart illustrating the third method for generating structured query statements provided in an embodiment of the specification, as shown below. Figure 4 As shown, the schematic diagram includes: Step 402: Obtain the statement to be generated and determine the intent information in the statement to be generated.

[0110] The statement to be generated is a natural statement in Structured Query Language (SQL) input by the user.

[0111] Step 404: Based on the preset subgraph determination rules, determine the first subgraph structure in the preset database graph structure that corresponds to the intent information.

[0112] The database graph structure is composed of multiple first graph nodes and the relationships between them. The first graph nodes are determined based on the structural information of multiple relational databases. The first subgraph structure is a graph structure in the database graph structure that is related to the intent information.

[0113] Step 406: Obtain multiple preset sample SQL statements of different types, and determine the condition information, action information, and multiple sample field name information included in each sample SQL statement.

[0114] Step 408: Determine the second graph node based on the sample field name information, and determine the second association relationship between each second graph node based on the condition information and the action information.

[0115] Step 410: Determine the second graph structure corresponding to each sample SQL statement based on the second graph nodes and the second association relationship.

[0116] Step 412: The second graph structure whose structural similarity to the first subgraph structure is greater than the first threshold is determined as the third graph structure.

[0117] The different structures in the second diagram are generated based on different types of preset SQL statements.

[0118] Step 414: Determine the statement generation parameters in the first subgraph structure based on the third graph structure, and generate the target SQL statement based on the statement generation parameters.

[0119] The statement generation parameters are the parameters required to generate the target SQL statement.

[0120] Step 416: Perform a statement error identification operation on the target SQL statement to determine whether there is any error information in the target SQL statement.

[0121] Step 418: If yes, then determine the error type based on the error information, and perform a correction operation on the target SQL statement based on the preset response strategy corresponding to the error type.

[0122] In the embodiments described in the specification, by generating a second graph structure based on multiple different types of sample SQL statements, it is possible not only to provide guidance when generating the target SQL statement according to the intent information, but also to broaden the scope of SQL statements that can be generated through multiple different types of second graph structures; by checking and correcting the generated target SQL statement after it has been generated, the correctness of the generated SQL statement is ensured.

[0123] It should be noted that the structured query statement generation method provided in this application embodiment can be executed by a structured query statement generation device or a control module within that device for executing the structured query statement generation method. This application embodiment uses the execution of the structured query statement generation method by a structured query statement generation device as an example to illustrate the structured query statement generation device provided in this application embodiment.

[0124] Figure 5 This is a schematic diagram of the structure of a structured query statement generation device according to an embodiment of the present invention. Figure 5As shown, the structured query statement generation device includes: a first acquisition module 502, a first determination module 504, a second acquisition module 506, and a second determination module 508.

[0125] The first acquisition module 502 is used to acquire the statement to be generated and determine the intent information in the statement to be generated, wherein the statement to be generated is a natural statement of structured query language (SQL) input by the user. The first determining module 504 is used to determine, based on a preset subgraph determining rule, a first subgraph structure in a preset database graph structure that corresponds to the intent information. The database graph structure is composed of multiple first graph nodes and the association relationships between the first graph nodes. The first graph nodes are determined based on the structural information of multiple related databases. The first subgraph structure is a graph structure in the database graph structure that is related to the intent information. The second acquisition module 506 is used to acquire multiple preset second graph structures, and determine the second graph structure whose structural similarity with the first subgraph structure is greater than a first threshold as the third graph structure. Different second graph structures are generated based on different types of preset SQL statements. The second determining module 508 is used to determine the statement generation parameters in the first subgraph structure based on the third graph structure, so as to generate a target SQL statement based on the statement generation parameters, wherein the statement generation parameters are the parameters required to generate the target SQL statement.

[0126] The structured query statement generation device in this application embodiment can be a device, or a component, integrated circuit, or chip in a terminal. The device can be a mobile electronic device or a non-mobile electronic device. For example, mobile electronic devices can be mobile phones, tablets, laptops, PDAs, in-vehicle electronic devices, wearable devices, ultra-mobile personal computers (UMPCs), netbooks, or personal digital assistants (PDAs), etc., while non-mobile electronic devices can be servers, network-attached storage (NAS), personal computers (PCs), televisions (TVs), ATMs, or self-service machines, etc. This application embodiment does not impose specific limitations.

[0127] The structured query statement generation device in this application embodiment can be a device with an operating system. This operating system can be Android, iOS, or other possible operating systems; this application embodiment does not specifically limit the specific operating system used.

[0128] The structured query statement generation apparatus provided in this application embodiment can achieve Figures 1 to 4 The various processes implemented in the method embodiments are not described in detail here to avoid repetition.

[0129] Based on the same technical concept, embodiments of this application also provide an electronic device for executing the above-described method for generating structured query statements. Figure 6 This is a schematic diagram of the structure of an electronic device to implement various embodiments of this application. The electronic device can vary significantly due to differences in configuration or performance, and may include a processor 602, a communications interface 604, a memory 606, and a communication bus 608. The processor 602, communications interface 604, and memory 606 communicate with each other via the communication bus 608. The processor 602 can call a computer program stored in the memory 606 and executable on the processor 602 to perform the following steps: Obtain the statement to be generated and determine the intent information in the statement to be generated, wherein the statement to be generated is a natural statement of structured query language (SQL) input by the user. Based on preset subgraph determination rules, a first subgraph structure corresponding to the intent information is determined in a preset database graph structure. The database graph structure is composed of multiple first graph nodes and the association relationships between the first graph nodes. The first graph nodes are determined based on the structural information of multiple related databases. The first subgraph structure is a graph structure related to the intent information in the database graph structure. Multiple preset second graph structures are obtained, and the second graph structures whose structural similarity to the first subgraph structure is greater than a first threshold are determined as third graph structures. Different second graph structures are generated based on different types of preset SQL statements. Based on the third graph structure, the statement generation parameters in the first subgraph structure are determined, and the target SQL statement is generated based on the statement generation parameters, wherein the statement generation parameters are the parameters required to generate the target SQL statement.

[0130] In one implementation, before determining the first subgraph structure corresponding to the intent information in the preset database graph structure based on preset subgraph determination rules, the method further includes: Obtain the structure information of multiple related databases, the structure information including table name information and multiple field information of each related database, the field information including one or more of field name information, field data information, field type information and field constraint information; The first graph node is determined based on the table name information and the field name information, and the first attribute information of each first graph node is determined based on the field data information, the field type information and the field constraint information. The first association relationship between the nodes of the first graph is determined based on the structural information of the multiple associated databases; The database graph structure is generated based on the first graph node, the first association relationship, and the first attribute information corresponding to the first graph node.

[0131] In one implementation, determining the first subgraph structure corresponding to the intent information in the preset database graph structure based on preset subgraph determination rules includes: Determine the semantic similarity between the first attribute information and the intent information of each first graph node, and determine the first graph node whose semantic similarity is greater than a second threshold as the initial node; The first graph nodes that are associated with the initial node among the multiple first graph nodes are identified as the first related graph nodes; The structure of the first subgraph is determined based on the initial node and the first related graph node.

[0132] In one implementation, determining the semantic similarity between the first attribute information and the intent information of each first graph node includes: Based on the field name information of each first graph node, determine the first feature vector information of each first graph node, and determine the second feature vector information corresponding to the intent information; Determine the feature vector similarity between each of the first feature vectors and the second feature vectors; Determine the text similarity between the field data information and the intent information of each of the first graph nodes; The semantic similarity between each first graph node and the intent information is determined based on the feature vector similarity and the text similarity.

[0133] In one implementation, determining the structure of the first subgraph based on the initial node and the first related graph node includes: Based on the first attribute information of each first related graph node, determine the edge feature vector similarity between each first related node and the intent information; The first relevant node whose edge feature vector similarity is greater than a third threshold is determined as the second relevant graph node, so as to determine the first subgraph structure based on the initial node and the second relevant graph node.

[0134] In one implementation, obtaining multiple preset second graph structures includes: Obtain multiple preset sample SQL statements of different types, and determine the condition information, action information, and multiple sample field name information included in each sample SQL statement; The second graph node is determined based on the sample field name information, and the second association relationship between each second graph node is determined based on the condition information and the action information; The second graph structure corresponding to each sample SQL statement is determined based on the second graph nodes and the second association relationship.

[0135] In one implementation, after generating the target SQL statement based on the statement generation parameters, the method further includes: Perform a statement error identification operation on the target SQL statement to determine whether there are any error messages in the target SQL statement; If so, the error type is determined based on the error information, and the target SQL statement is corrected based on the preset response strategy corresponding to the error type.

[0136] The specific execution steps can be found in the various steps of the above-described method for generating structured query statements, and can achieve the same technical effect. To avoid repetition, they will not be repeated here.

[0137] It should be noted that the electronic devices in the embodiments of this application include: servers, terminals, or other devices besides terminals.

[0138] The above electronic device structure does not constitute a limitation on the electronic device. An electronic device may include more or fewer components than illustrated, or combine certain components, or arrange them differently. For example, an input unit may include a Graphics Processing Unit (GPU) and a microphone, and a display unit may use a liquid crystal display (LCD), organic light-emitting diode (OLED), or other similar display panels. User input units include at least one of a touch panel and other input devices. A touch panel is also called a touchscreen. Other input devices may include, but are not limited to, physical keyboards, function keys (such as volume control buttons, power buttons, etc.), trackballs, mice, and joysticks, which will not be elaborated further here.

[0139] Memory can be used to store software programs and various data. Memory can primarily include a first storage area for storing programs or instructions and a second storage area for storing data. The first storage area can store the operating system, application programs or instructions required for at least one function (such as sound playback, image playback, etc.). Furthermore, memory can include volatile memory or non-volatile memory, or both. Non-volatile memory can be read-only memory (ROM), programmable read-only memory (PROM), erasable programmable read-only memory (EPROM), electrically erasable programmable read-only memory (EEPROM), or flash memory. Volatile memory can be random access memory (RAM), static random access memory (SRAM), dynamic random access memory (DRAM), synchronous dynamic random access memory (SDRAM), double data rate synchronous dynamic random access memory (DDRSDRAM), enhanced synchronous dynamic random access memory (ESDRAM), synchronous linked dynamic random access memory (Synchlink DRAM, SLDRAM), and direct memory bus RAM (DRRAM).

[0140] The processor may include one or more processing units; optionally, the processor integrates an application processor and a modem processor, wherein the application processor mainly handles operations related to the operating system, user interface, and applications, while the modem processor mainly handles wireless communication signals, such as a baseband processor. It is understood that the aforementioned modem processor may also not be integrated into the processor.

[0141] This application also provides a readable storage medium storing a program or instructions. When the program or instructions are executed by a processor, they implement the various processes of the above-described method for generating structured query statements and achieve the same technical effect. To avoid repetition, these will not be described again here.

[0142] The processor is the processor in the electronic device described in the above embodiments. The readable storage medium includes computer-readable storage media, such as computer read-only memory (ROM), random access memory (RAM), magnetic disk, or optical disk.

[0143] This application embodiment also provides a chip, which includes a processor and a communication interface. The communication interface is coupled to the processor. The processor is used to run programs or instructions to implement the various processes of the above-described method embodiment for generating structured query statements, and can achieve the same technical effect. To avoid repetition, it will not be described again here.

[0144] It should be understood that the chip mentioned in the embodiments of this application may also be referred to as a system-on-a-chip, system chip, chip system, or system-on-a-chip, etc.

[0145] It should be noted that, in this document, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes that element. Furthermore, it should be noted that the scope of the methods and apparatuses in the embodiments of this application is not limited to performing functions in the order shown or discussed, but may also include performing functions substantially simultaneously or in the reverse order, depending on the functions involved. For example, the described methods may be performed in a different order than described, and various steps may be added, omitted, or combined. Additionally, features described with reference to certain examples may be combined in other examples.

[0146] Through the above description of the embodiments, those skilled in the art can clearly understand that the methods of the above embodiments can be implemented by means of software plus necessary general-purpose hardware platforms. Of course, they can also be implemented by hardware, but in many cases the former is a better implementation method. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, can be embodied in the form of a software product. This computer software product is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disk) and includes several instructions to cause a terminal (which may be a mobile phone, computer, server, air conditioner, or network device, etc.) to execute the methods described in the various embodiments of this application.

[0147] The embodiments of this application have been described above with reference to the accompanying drawings. However, this application is not limited to the specific embodiments described above. The specific embodiments described above are merely illustrative and not restrictive. Those skilled in the art can make many other forms under the guidance of this application without departing from the spirit and scope of the claims, and all of these forms are within the protection scope of this application.

Claims

1. A method of generating a structured query statement, characterized by, The method comprises: obtaining a to-be-generated sentence, and determining intent information in the to-be-generated sentence, the to-be-generated sentence being a natural language sentence input by a user and to be generated into a structured query language (SQL); determining, based on a preset subgraph determination rule, a first subgraph structure corresponding to the intent information in a preset database graph structure, the database graph structure being composed of a plurality of first graph nodes and an association relationship between the first graph nodes, the first graph nodes being determined based on structure information of a plurality of association databases, and the first subgraph structure being a graph structure related to the intent information in the database graph structure; obtaining a plurality of preset second graph structures, and determining, as a third graph structure, a second graph structure having a structure similarity greater than a first threshold with the first subgraph structure, different second graph structures being generated based on different types of preset SQL statements; determining, based on the third graph structure, a sentence generation parameter in the first subgraph structure, to generate a target SQL statement based on the sentence generation parameter, the sentence generation parameter being a parameter required for generating the target SQL statement.

2. The method of claim 1, wherein, Before the determining, based on the preset subgraph determination rule, of the first subgraph structure corresponding to the intent information in the preset database graph structure, the method further comprises: obtaining the structure information of the plurality of association databases, the structure information including table name information and a plurality of field information of each association database, the field information including one or more of field name information, field data information, field type information, and field constraint condition information; determining a first graph node based on the table name information and the field name information, and determining first attribute information of each first graph node based on the field data information, the field type information, and the field constraint condition information; determining a first association relationship between the first graph nodes based on the structure information of the plurality of association databases; generating the database graph structure based on the first graph nodes, the first association relationship, and the first attribute information corresponding to the first graph nodes.

3. The method of claim 2, wherein, The determining, based on the preset subgraph determination rule, of the first subgraph structure corresponding to the intent information in the preset database graph structure comprises: determining a semantic similarity between the first attribute information of each first graph node and the intent information, and determining, as an initial node, a first graph node having a semantic similarity greater than a second threshold; determining, as a first related graph node, a first graph node having an association relationship with the initial node among the plurality of first graph nodes; determining the first subgraph structure based on the initial node and the first related graph node.

4. The method of claim 3, wherein, The determining of the semantic similarity between the first attribute information of each first graph node and the intent information comprises: determining first feature vector information of each first graph node based on the field name information of each first graph node, and determining second feature vector information corresponding to the intent information; determining a feature vector similarity between each first feature vector and the second feature vector; determining a text similarity between the field data information of each first graph node and the intent information; determine the semantic similarity between each of the first graph nodes and the intent information based on the feature vector similarity and the text similarity.

5. The method of claim 3, wherein, The determining the first subgraph structure based on the initial node and the first related graph node comprises: determine an edge feature vector similarity between each of the first related graph nodes and the intent information based on the first attribute information of each of the first related graph nodes; determine the first related graph node as a second related graph node if the edge feature vector similarity is greater than a third threshold value, so as to determine the first subgraph structure based on the initial node and the second related graph node.

6. The method of claim 1, wherein, The obtaining a plurality of preset second graph structures comprises: obtain a plurality of preset sample SQL statements of different types, and determine condition information, action information and a plurality of sample field name information included in each of the sample SQL statements; determine second graph nodes based on the sample field name information, and determine a second association relationship between each of the second graph nodes based on the condition information and the action information; determine the second graph structure corresponding to each of the sample SQL statements based on the second graph nodes and the second association relationship.

7. The method of claim 1, wherein, After the generating the target SQL statement based on the statement generation parameter, the method further comprises: perform a statement error identification operation on the target SQL statement to determine whether there is error information in the target SQL statement; if yes, determine an error type based on the error information, and perform a correction operation on the target SQL statement based on a preset coping strategy corresponding to the error type.

8. A device for generating structured query statements, characterized in that, comprise: a first obtaining module, configured to obtain a to-be-generated statement, and determine intent information in the to-be-generated statement, the to-be-generated statement being a natural language statement of a to-be-generated structured query language (SQL) input by a user; a first determining module, configured to determine a first subgraph structure corresponding to the intent information in a preset database graph structure based on a preset subgraph determination rule, the database graph structure being composed of a plurality of first graph nodes and an association relationship between the first graph nodes, the first graph nodes being determined based on structure information of a plurality of associated databases, and the first subgraph structure being a graph structure related to the intent information in the database graph structure; a second obtaining module, configured to obtain a plurality of preset second graph structures, and determine a third graph structure from the second graph structures based on a structure similarity between the third graph structure and the first subgraph structure, different second graph structures being generated based on different types of preset SQL statements; a second determining module, configured to determine a statement generation parameter in the first subgraph structure based on the third graph structure, and generate a target SQL statement based on the statement generation parameter, the statement generation parameter being a parameter required for generating the target SQL statement.

9. A computer device, comprising: The device comprises: a processor; and a memory arranged to store computer-executable instructions configured to be executed by the processor, the computer-executable instructions comprising instructions for performing steps in the method of any one of claims 1 to 7.

10. A storage medium, characterized by The storage medium is configured to store computer-executable instructions that cause a computer to perform the method of any one of claims 1 to 7.

Citation Information

Cited By

  • Relational database-oriented data processing method, device and system and storage medium

    CN122241773A