Method, device and storage medium for converting natural language statements into SQL

By extracting target entities and query fields from data query text and using the semantic and structural similarity of the knowledge graph to determine the comprehensive similarity, the problem of insufficient accuracy of traditional methods under complex table structures and query requirements is solved, and higher SQL conversion accuracy is achieved.

CN120296139BActive Publication Date: 2025-10-17CHINA UNICOM (GUANGDONG) IND INTERNET CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202510787118.1
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2025-06-13
Publication Date
2025-10-17
Estimated Expiration
2045-06-13

AI Technical Summary

Technical Problem

Traditional natural language conversion methods rely on manual rule templates or template-based rule engines, which have poor versatility and insufficient accuracy when faced with complex table structures and query requirements.

Method used

By performing semantic analysis on the data query text, extracting the target entities and query fields, and using the semantic similarity and structural similarity in the knowledge graph to determine the comprehensive similarity, the data query text is converted into a structured query statement by combining the target nodes, connection relationships and business rules.

Benefits of technology

It improves the accuracy of converting natural language query text into SQL query statements, avoids inaccurate conversion caused by target node errors, and enhances applicability in complex query scenarios.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120296139B_ABST
    Figure CN120296139B_ABST
Patent Text Reader

Abstract

The application provides a method and device for converting a natural language sentence into SQL and a storage medium, relates to the technical field of data processing, and is used to improve the accuracy of converting a natural language sentence into a SQL sentence. The method comprises the following steps: performing semantic analysis on a data query text to extract a target entity and at least one query field, wherein the target entity indicates a query intention corresponding to the data query text; determining a comprehensive similarity between each query field and each first candidate node in a pre-stored knowledge graph according to the semantic similarity and the structural similarity between each query field and each first candidate node; determining a target node corresponding to each query field according to the comprehensive similarity between each query field and each first candidate node; and converting the data query text into a structured query statement according to the above information.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present application relates to the technical field of data processing, and in particular to a method and device for converting a natural language sentence into SQL and a storage medium. BACKGROUND

[0002] In a data query scenario, a user usually expresses a query intention in a natural language, and a query system needs to convert it into an executable structured query language (SQL). Traditional methods for converting a natural language into SQL rely on artificial rule templates or rule engines based on templates, and have poor versatility and insufficient accuracy when facing complex table structures and query requirements. SUMMARY

[0003] Therefore, the present application provides a method and device for converting a natural language sentence into SQL and a storage medium, which can improve the accuracy of converting a query text in a natural language into an SQL query statement. The present application is implemented by the following aspects:

[0004] In a first aspect, the present application provides a method for converting a natural language sentence into SQL, which includes: performing semantic analysis on a data query text to extract a target entity and at least one query field, wherein the target entity is used to indicate a query intention of the data query text; determining a comprehensive similarity between each query field in the at least one query field and each first candidate node in a pre-stored knowledge graph according to a semantic similarity and a structural similarity between the each query field and the each first candidate node, wherein the knowledge graph is constructed according to a plurality of data tables, and the structural similarity is used to indicate a structural association degree of the each query field and the each first candidate node in the knowledge graph; determining a target node corresponding to the each query field according to the comprehensive similarity between the each query field and the each first candidate node; and converting the data query text into a structured query statement according to at least one target node, a connection relationship between the target entity and the at least one target node, a target business rule, and the data query text.

[0005] In a possible implementation, the method further includes: traversing the knowledge graph to determine a path length from the target entity to the each first candidate node; and calculating the structural similarity between the each query field and the each first candidate node according to the path length from the target entity to the each first candidate node and a pre-set inverse function.

[0006] In a possible implementation, the determining the comprehensive similarity between each query field and each first candidate node according to the semantic similarity and the structural similarity between the each query field and the each first candidate node comprises: for each of the each first candidate node, calculating a first similarity according to a product result of the semantic similarity between the each query field and the each first candidate node and a first preset weight; calculating a second similarity according to the structural similarity between the each query field and the each first candidate node and a second preset weight; and determining the comprehensive similarity between the each query field and the each first candidate node according to a sum of the first similarity and the second similarity, to obtain the comprehensive similarity between the each query field and the each first candidate node.

[0007] In a possible implementation, before the determining the comprehensive similarity between each query field and each first candidate node according to the semantic similarity and the structural similarity between the each query field and the each first candidate node, the method further comprises: calculating the semantic similarity between the each query field and each node in the knowledge graph; and determining the each first candidate node according to the semantic similarity between the each query field and the each node and a first similarity threshold.

[0008] In a possible implementation, the determining the target node corresponding to the each query field according to the comprehensive similarity between the each query field and the each first candidate node comprises: determining at least one second candidate node according to the comprehensive similarity between the each query field and the each first candidate node and a second similarity threshold; and inputting the at least one second candidate node, the data query text and context information of the at least one second candidate node in the knowledge graph into a pre-trained large language model to obtain the target node.

[0009] In a possible implementation, before determining the comprehensive similarity between each query field and each first candidate node according to the semantic similarity and the structural similarity between each query field and each first candidate node in the at least one query field, the method further includes: extracting metadata information of each data table in the plurality of data tables, where the metadata information includes table description information and column description information; constructing a plurality of nodes and attribute information of each node in the plurality of nodes according to the table description information and the column description information, where one node is used to indicate one table entity or column entity; extracting table and column relationships and column and column relationships between the plurality of nodes according to the table description information and the column description information; and constructing relationship edges between the plurality of nodes according to the table and column relationships and the column and column relationships, to obtain the knowledge graph.

[0010] In a possible implementation, the converting the data query text into the structured query statement according to the at least one target node, the connection relationship between the target entity and the at least one target node, the target business rule, and the data query text includes: inputting the at least one target node, the connection relationship between the target entity and the at least one target node, the target business rule, and the data query text into a pre-trained statement conversion model, to obtain the structured query statement, where the pre-trained statement conversion model is trained according to a sample query statement data set.

[0011] In a second aspect, an embodiment of the present application provides a device for converting a natural language statement into SQL, including: an analysis module configured to perform semantic analysis on a data query text, and extract a target entity and at least one query field, where the target entity is used to indicate a query intention of the data query text; a determination module configured to determine a comprehensive similarity between each query field and each first candidate node in a pre-stored knowledge graph according to a semantic similarity and a structural similarity between each query field and each first candidate node in the at least one query field, where the knowledge graph is constructed according to a plurality of data tables, and the structural similarity is used to indicate a structural association degree of each query field and each first candidate node in the knowledge graph; and the determination module is further configured to determine a target node corresponding to each query field according to the comprehensive similarity between each query field and each first candidate node; and a conversion module configured to convert the data query text into a structured query statement according to the at least one target node, a connection relationship between the target entity and the at least one target node, a target business rule, and the data query text.

[0012] In a third aspect, an apparatus for converting a natural language sentence into an SQL statement is provided, and the apparatus includes a memory storing executable program codes, and a processor coupled to the memory. The processor invokes the executable program codes stored in the memory to execute the method according to the first aspect and any possible implementation.

[0013] In a fourth aspect, a computer readable storage medium is provided, and the computer readable storage medium stores a computer program. The computer program is executed by a processor to implement the method according to the first aspect and any possible implementation.

[0014] In a fifth aspect, a computer program product is provided, and the computer program product includes a computer program. The computer program is executed by a processor to implement the method according to the first aspect and any possible implementation.

[0015] By implementing the method provided in the embodiments of the present application, after the target entity and the at least one query field are determined, the nodes semantically similar to each query field in the knowledge graph can be determined based on the semantic similarity between each query field and each first candidate node in the knowledge graph, and the structural association degree between each query field and each first candidate node in the knowledge graph can be determined based on the structural similarity between each query field and each first candidate node in the knowledge graph. The structural association procedure can reflect the business association degree between each query field and each first candidate node in the knowledge graph. Therefore, the comprehensive similarity is determined by combining the semantic similarity and the structural similarity, and the target node determined based on the comprehensive similarity can effectively avoid the problem that the query field and the node are semantically similar but have no business association, and thus the problem that the SQL statement obtained by conversion is inaccurate due to the error in determining the target node can also be avoided. It can be seen that the method for converting a natural language sentence into an SQL statement provided in the embodiments of the present application can improve the accuracy of converting a natural language query text into an SQL query statement. BRIEF DESCRIPTION OF DRAWINGS

[0016] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings needed in the embodiments will be briefly introduced. Obviously, the drawings in the following description are only some embodiments of the present application, and other drawings can be obtained by those skilled in the art without creative labor.

[0017] Figure 1 An application scenario diagram of the method for converting a natural language sentence into an SQL statement provided in the embodiments of the present application;

[0018] Figure 2 A flowchart of the method for converting a natural language sentence into an SQL statement provided in the embodiments of the present application;

[0019] Figure 3 A knowledge graph provided by an embodiment of the present application Figure 1 ;

[0020] Figure 4 A knowledge graph provided by an embodiment of the present application Figure 2 ;

[0021] Figure 5 A structure of a device for converting a natural language sentence into SQL provided by an embodiment of the present application Figure 1 ;

[0022] Figure 6 A structure of a device for converting a natural language sentence into SQL provided by an embodiment of the present application Figure 2 . DETAILED DESCRIPTION

[0023] The technical solutions in the present application will be described below with reference to the drawings.

[0024] In order to clearly describe the technical solutions of the embodiments of the present application, in the embodiments of the present application, the same items or similar items with basically the same functions and effects are distinguished by using "first", "second", etc. For example, the first instruction and the second instruction are used to distinguish different user instructions, and do not limit the order. Those skilled in the art can understand that "first", "second", etc. do not limit the quantity and execution order, and "first", "second", etc. also do not necessarily mean different.

[0025] It should be noted that in the present application, the words "exemplarily" or "for example" are used to represent an example, illustration or description. Any embodiment or design scheme described as "exemplarily" or "for example" in the present application should not be interpreted as more preferred or more advantageous than other embodiments or design schemes. Rather, the words "exemplarily" or "for example" are intended to present the relevant concept in a specific manner.

[0026] In addition, "at least one" means one or more, and "more" means two or more. "And / or" describes the association relationship of associated objects, indicating that three relationships can exist. For example, A and / or B can mean: A exists alone, A and B exist at the same time, and B exists alone, where A and B can be singular or plural. The character " / " generally indicates that the previous and next associated objects are in an "or" relationship. "At least one of the following items" or similar expressions refers to any combination of these items, including any combination of single or plural items. For example, at least one of a, b and c can mean: a, or b, or c, or a and b, or a and c, or b and c, or a, b and c, where a, b, c can be single or plural.

[0027] In addition, the terms "including" and "having" and any variations thereof in the embodiments and drawings of this application are intended to cover non-exclusive inclusions. For example, a process, method, system, product, or apparatus comprising a series of steps or units is not limited to the listed steps or units, but may optionally include steps or units not listed, or may optionally include other steps or units inherent to the process, method, product, or apparatus.

[0028] In data query scenarios, users typically express their query intent in natural language, which the query system must convert into executable Structured Query Language (SQL). Traditional natural language-to-SQL conversion methods rely on manual experience, are inadequate for complex table structures and query requirements, and the resulting SQL suffers from poor accuracy.

[0029] Based on this, an embodiment of the present application provides a method for converting natural language statements into SQL, the method including: performing semantic parsing on a data query text, extracting a target entity and at least one query field, wherein the target entity is used to indicate the query intent of the data query text; determining the comprehensive similarity between each query field and each first candidate node based on the semantic similarity and structural similarity between each query field in at least one query field and each first candidate node in a pre-stored knowledge graph, the knowledge graph is constructed based on multiple data tables, and the structural similarity is used to indicate the degree of structural association between each query field and each first candidate node in the knowledge graph; determining the target node corresponding to each query field based on the comprehensive similarity between each query field and each first candidate node; converting the data query text into a structured query statement based on at least one target node, the connection relationship between the target entity and at least one target node, the target business rules and the data query text.

[0030] The comprehensive similarity is determined by combining the semantic similarity and the structural similarity between the query field and each first candidate node in the knowledge graph. Since the structural similarity can reflect the business association degree between the query field and each first candidate node, that is, the comprehensive similarity considers both the semantic association degree and the business association degree. Therefore, the target node determined based on the comprehensive similarity can effectively avoid the problem that the query field is semantically similar to the node but has no business association, and can also avoid the problem that the converted SQL statement is inaccurate due to the error of the determined target node, that is, the accuracy of converting the natural language query text into the SQL query statement is improved.

[0031] The application scenario of the method for converting a natural language statement into SQL provided by the embodiment of the application will be described below.

[0032] Please refer to Figure 1 The application scenario of the method for converting a natural language statement into SQL provided by the embodiment of the application will be described below. Figure 1 As shown in the figure, the schematic diagram includes a data query device 110 and an electronic device 120.

[0033] The data query device 110 can be a device or apparatus having a data query function. When the data query device 110 is an apparatus having a data query function, the data query device 110 can be, for example, a terminal device. When the data query device 110 is an apparatus having a data query function, the data query device 110 can be a functional module in another device. For example, the data query device 110 is a functional module in the electronic device 120. Exemplarily, the terminal device involved in the embodiments of the present application can include a general handheld electronic terminal, such as a mobile phone, a smart phone, a portable terminal, a terminal, a personal digital assistant (PDA), a portable multimedia player (PMP) device, a notebook computer, a note pad, a wireless broadband (Wibro) terminal, a personal computer (PC), a smart PC, a point of sales (POS) terminal, and a vehicle-mounted computer, etc. The terminal device can also include a wearable device. The wearable device is a portable electronic device that can be directly worn on the user's body or integrated into the user's clothes or accessories. The wearable device is not only a hardware device, but also can realize powerful intelligent functions, such as a computing function, a positioning function, and an alarm function, through software support and data interaction and cloud interaction, and can be connected to a mobile phone and various terminals. The wearable device can include, but is not limited to, a watch type (such as a watch, a wristband, etc.) supported by a wrist, a shoe type (such as a shoe, a sock, or other leg-wearing products) supported by a foot, a glass type (such as glasses, a helmet, a headband, etc.) supported by a head, and a smart clothing, a bag, a walking stick, accessories, and various non-mainstream product forms.

[0034] The electronic device 120 can be a terminal device or a server having a data processing capability. The terminal device is introduced in the foregoing content, which will not be described herein again. The electronic device 120 can also prestore a plurality of data tables, or the electronic device 120 can access a plurality of data tables by accessing an external storage device.

[0035] Exemplarily, the data query device 110 can obtain a data query text input by a user, and send the data query text to the electronic device 120. The electronic device 120 receives the data query text, and processes the data query text to convert the data query text into a SQL query statement. The specific manner in which the electronic device 120 processes the data query text to convert the data query text into a SQL query statement will be described in detail below.

[0036] Please refer toFigure 2 A flowchart of a method for converting a natural language sentence into SQL provided by an embodiment of the present application is shown. The following is an explanation of the steps shown in the method performed by an electronic device, such as the electronic device 120 shown in FIG. 1. Figure 2 Figure 1 Figure 2 The method shown in FIG. 2 can be applied to the application scenarios shown in FIG. 1. Figure 1

[0037] S201. Perform semantic analysis on the data query text to extract a target entity and at least one query field, wherein the target entity is used to indicate the query intent of the data query text.

[0038] The query intent can indicate the target data or the target data table that the data query text expects to query. The target data can be any data in a plurality of pre-stored data tables. The target data table can be any data table in the plurality of data tables.

[0039] Specifically, the electronic device can perform semantic analysis on the data query text, analyze the query intent of the data query text, and determine the target entity and at least one query field of the data query text based on the query intent. In the embodiments of the present application, the target entity is used to indicate the target data table involved in the data query text.

[0040] Alternatively, the electronic device can also extract the target entity and at least one query field from the data query text through a named entity recognition technology (NER). For example, the electronic device can perform named entity recognition on the data query text, recognize the associated entity in the data query text, and take the associated entity as the target entity. The associated entity refers to the data table involved in the data query text, such as the “order amount table”.

[0041] In this implementation, the electronic device can also input the data query text into a pre-trained named entity recognition model to obtain the target entity and at least one query field based on the pre-trained named entity recognition model. The pre-trained entity recognition model is trained based on a large number of labeled sample data query texts.

[0042] For example, the data query text is “query the total order amount of A city in 2023”, and the semantic analysis of the data query text indicates that the data in the order amount table needs to be queried. Therefore, the target entity corresponds to “order amount”, and at least one query field corresponds to “total order amount”.

[0043] It should be understood that the at least one query field extracted in step S201 is an initial query field.

[0044] ​​​At S202, according to the semantic similarity and the structural similarity between each query field and each first candidate node in the pre-stored knowledge graph, a comprehensive similarity between each query field and each first candidate node is determined; wherein, the knowledge graph is constructed according to a plurality of data tables, and the structural similarity is used to indicate the structural association degree of each query field and each first candidate node in the knowledge graph.

[0045] The semantic similarity can indicate the semantic association degree between the query field and the node. Since the knowledge graph is constructed based on a plurality of data tables, the knowledge graph includes the business association between the plurality of data tables, therefore, the structural similarity can not only reflect the structural association degree between the query field and the node, but also indirectly reflect the business association degree between the query field and the node.

[0046] Specifically, the electronic device can calculate the comprehensive similarity between each query field and each first candidate node according to the product of the semantic similarity between each query field and each first candidate node and the first preset weight, and the sum of the product of the structural similarity between each query field and each first candidate node and the second preset weight.

[0047] Specifically, for each first candidate node in the plurality of first candidate nodes, the electronic device can calculate a first similarity according to the product of the semantic similarity between each query field and each first candidate node and the first preset weight, and calculate a second similarity according to the structural similarity between each query field and each first candidate node and the second preset weight. Finally, the comprehensive similarity between each query field and each first candidate node is determined according to the sum of the first similarity and the second similarity, and the comprehensive similarity between each query field and each first candidate node is obtained. For example, a calculation formula for determining the comprehensive similarity between each query field and a first candidate node is as follows:

[0048] Comprehensive similarity = first similarity + second similarity = first preset weight * semantic similarity + second preset weight * structural similarity

[0049] The first preset weight and the second preset weight are pre-configured in the electronic device, and the specific values of the first preset weight and the second preset weight can be set according to actual needs, for example, can be obtained according to experience or experiment, and the present application embodiment does not limit this. The first preset weight and the second preset weight are adjustable weights, and the specific adjustment method can be set according to actual business needs, and the present application embodiment does not limit this.

[0050] The calculation methods of the semantic similarity and the structural similarity are described below.

[0051] 1. semantic similarity.

[0052] The electronic device can calculate the cosine similarity between each query field and each first candidate node to obtain the semantic similarity between each query field and each first candidate node. Specifically, the electronic device can convert each query field and each first candidate node into a vector form, and then calculate the cosine similarity between the vectorized each query field and each first candidate node to finally obtain the semantic similarity between each query field and each first candidate node.

[0053] Alternatively, the electronic device can also calculate the semantic similarity between each query field and each first candidate node according to other manners, for example, by outputting the semantic similarity between each query field and each first candidate node through a pre-trained model, wherein the pre-trained model can be trained according to a large amount of sample data, and the sample data includes sample query fields and sample nodes.

[0054] It should be understood that the semantic similarity between each query field and each first candidate node includes the semantic similarity between each query field and each of the first candidate nodes. For example, taking each query field as query field 1, and the first candidate nodes including node 1, node 2 and node 3, the semantic similarity between query field 1 and each first candidate node should include the semantic similarity between query field 1 and node 1, the semantic similarity between query field 1 and node 2, and the semantic similarity between query field 1 and node 3.

[0055] 2. structural similarity.

[0056] The electronic device can calculate the structural similarity between each query field and each first candidate node according to the path length between each target entity and each first candidate node. The specific manner of determining the structural similarity between each target entity and each first candidate node will be specifically described below in conjunction with a method flowchart for determining structural similarity shown in Figure 4 .

[0057] S401, traversing the knowledge graph to determine the path length from the target entity to each first candidate node in the knowledge graph.

[0058] The path length can refer to the number of hops from the entity to the node, or the number of edges (relationships) passed through from the entity to the node. For example, please refer to Figure 3 , a schematic diagram of a knowledge graph provided by an embodiment of the present application. As Figure 3 shown, the path length from the target entity 1 to node 1 is 2, the path length from the target entity 1 to node 2 is 3, and the path length from the target entity 1 to node 3 is 1.

[0059] In particular, if there is no connection between a target entity and a node, for example, Figure 3 The node 4 shown has no connection with the target entity 1. In this case, the node can be eliminated, i.e., the process of calculating the comprehensive similarity between the target entity and the node is ended. Alternatively, the path length between the node and the target entity can be set to a maximum value, such as 999, 9999, etc., wherein the maximum value can be preconfigured in the electronic device.

[0060] In a possible implementation, when determining the path length from the target entity to each first candidate node, the path length can also be calculated according to the types of edges passed through by the target entity to each first candidate node and the weights corresponding to the edge types. The edge types can include semantic relationships (such as semantic equivalence relationships), foreign key association relationships, etc. For example, it is assumed that the weight of a foreign key edge = 1 and the weight of a semantic edge = 2, and then the path length = 1 x number of foreign key edges + 2 x number of semantic edges.

[0061] It should be noted that there can be multiple paths from the target entity to each first candidate node, and in the embodiments of the present application, the path length of the shortest path from the target entity to each first candidate node is taken as the path length used to calculate the structural similarity between each query field and each first candidate node. In actual applications, a corresponding weight can also be set for the path according to the business rules, so as to select the path length of the target path as the path length used to calculate the structural similarity between each query field and each first candidate node.

[0062] S402, according to the path length from the target entity to each first candidate node in the knowledge graph and the preset inverse function, the structural similarity between each query field and each first candidate node is calculated.

[0063] The preset inverse function can refer to the inverse of the path length, or the reciprocal of the path length. For example, a calculation formula for calculating the structural similarity between each query field and a first candidate node is as follows:

[0064] Structural similarity = 1 / path length

[0065] Since the range of the cosine similarity is [-1, 1], the range of the structural similarity can be unified to [0, 1] by the preset inverse function. The reciprocal of the path length indicates the structural similarity, and in the case of shorter path length, the structural similarity is greater, which can reflect that the structural association between the target entity and the node is closer, and also indirectly reflects that the business association is closer.

[0066] It should be understood that the path length of the target entity to each first candidate node includes the path length of the target entity to each of the first candidate nodes. For example, taking the target entity as target entity 1, and the first candidate nodes including node 1, node 2 and node 3, the path length of the target entity 1 to each first candidate node includes the path length of the target entity 1 to node 1, the path length of the target entity 1 to node 2 and the path length of the target entity 1 to node 3.

[0067] In a possible implementation, in the case that the target entity is the same as a first candidate node, the path length between the target entity and the first candidate node is 0. At this time, the structural similarity between the target entity and the first candidate node cannot be calculated based on the reciprocal of the path length. Therefore, in order to avoid this case, the reciprocal function is set as the reciprocal of (path length + 1). Exemplarily, a calculation formula for calculating the structural similarity between each target entity and a first candidate node is as follows:

[0068] Structural similarity = 1 / (path length + 1)

[0069] Exemplarily, if the path length of the target entity 1 to node 2 is 3 and the path length of the target entity 1 to node 3 is 1, the structural similarity of the target entity 1 to node 2 is 0.25, and the structural similarity of the target entity to node 3 is 0.5. It can be seen that the structural similarity of the target entity 1 to node 3 is higher, and the structural association and business association between the target entity 1 and node 3 in the knowledge graph are more close.

[0070] Based on the above content, it can be known that the embodiments of the present application provide two calculation formulas of the comprehensive similarity, which are as follows:

[0071] Formula 1: Comprehensive similarity = first preset weight * semantic similarity + second preset weight * (1 / path length)

[0072] Formula 2: Comprehensive similarity = first preset weight * semantic similarity + second preset weight * [1 / (path length + 1)]

[0073] Wherein, the content of the first preset weight and the second preset weight can correspond to the content described in the foregoing, which will not be described here.

[0074] In a possible implementation, each first candidate node is a node in the knowledge graph that is semantically similar to each query field. In this case, the electronic device can first filter the first candidate nodes that are semantically similar to each query field according to the semantic similarity between each query field and each node in the knowledge graph. In this way, by excluding some nodes that are obviously different in semantics and retaining the first candidate nodes that are similar in semantics, the electronic device can reduce the computing pressure and improve the computing efficiency. Specifically, the electronic device can calculate the semantic similarity between each query field and each node in the knowledge graph. Then, according to the semantic similarity between each query field and each node and the first similarity threshold, the electronic device can determine each first candidate node. For example, the electronic device can determine a node as a first candidate node if the semantic similarity between the node and each query field is greater than or equal to the first similarity threshold.

[0075] wherein the first similarity threshold is used to filter nodes that are semantically similar to each target entity from the nodes. The first similarity threshold can be set according to actual needs, and embodiments of the present application do not limit the same. The specific manner in which the electronic device calculates the semantic similarity can correspond to the content described in the foregoing, which will not be described here.

[0076] For example, in a knowledge graph including nodes 1, 2, 3, 4, and 5, the query field is query field 1, and the first similarity threshold is 0.5. The electronic device calculates the semantic similarity between query field 1 and node 1 as 0.67, the semantic similarity between query field 1 and node 2 as 0.75, the semantic similarity between query field 1 and node 3 as 0.75, the semantic similarity between query field 1 and node 4 as 0.37, and the semantic similarity between query field 1 and node 5 as 0.25. As can be seen, the semantic similarity between query field 1 and nodes 4 and 5 is less than the first similarity threshold. Therefore, the electronic device can determine nodes 1, 2, and 3 as each first candidate node.

[0077] In a possible implementation, before calculating the comprehensive similarity, the electronic device can construct a knowledge graph for the plurality of data tables. Specifically, the electronic device can extract metadata information of each data table in the plurality of data tables, wherein the metadata information includes table description information and column description information. The table description information includes table name, table structure information, association relationship with other tables (such as foreign key constraint or business logic association), index type, primary key definition, and the like. The column description information includes column name (or field name), data type, constraint condition, field attribute, business meaning (specific description of the data stored in the column), and the like. Optionally, the table description information and the column description information can further include other information, which will not be exemplified herein.

[0078] Further, according to the table description information and the column description information, a plurality of nodes and attribute information of each node in the plurality of nodes are constructed. One node is used to indicate one table entity or one column entity. In a popular way, the electronic device can abstract each table and each column in the plurality of databases as one node, and store the table description information corresponding to each table in the attribute information of the corresponding table entity, and store the column description information corresponding to each column in the attribute information of the corresponding column entity.

[0079] Then, according to the table description information and the column description information, table and column relationships and column and column relationships between the plurality of nodes are extracted, and further, according to the table and column relationships and the column and column relationships, relationship edges between the plurality of nodes are constructed to obtain a knowledge graph. Optionally, the edge types of the relationship edges include column belonging table, foreign key association, aggregation logic, semantic equivalent relationship (such as "customer" and "user"), and the like, and the electronic device can also establish a display connection mode through a semantic label when constructing the relationship edges between the nodes. The relationships between the columns include data association across tables or columns through foreign keys, calculation logic, business rules, and the like, and the relationships between the tables include defining table structures and data rules through primary keys, data types, constraints, indexes, and the like.

[0080] Finally, a database knowledge graph (DB-KG) is obtained, which explicitly expresses the complex associations between multiple tables and provides a structured knowledge base for subsequent semantic reasoning and SQL generation.

[0081] After the knowledge graph is constructed, the knowledge graph can be persisted in a graph database (such as Neo4j) to ensure efficient relationship traversal and path query.

[0082] In one possible implementation, after the knowledge graph is constructed, the database structure changes (such as adding a table or modifying a foreign key) can be monitored in real time or at intervals of a preset time period, and the changes are synchronized to the knowledge graph in real time to ensure consistency with the actual database.

[0083] S203, according to the comprehensive similarity between each query field and each first candidate node, determining a target node corresponding to each query field.

[0084] The target node can be a standard query field corresponding to the query field. As described above, the query fields extracted in step S201 are initial query fields. Since there can be some differences between the fields extracted from the data query text and the fields in the data table in description, in order to improve the accuracy of SQL conversion, the query fields extracted from the data query text need to be corrected to obtain the standard query fields corresponding thereto.

[0085] Specifically, the electronic device can determine, as the target node, a first candidate node corresponding to the highest comprehensive similarity between each query field and each first candidate node.

[0086] Alternatively, the electronic device can also determine at least one second candidate node according to the comprehensive similarity between each query field and each first candidate node and a second similarity threshold. For example, the electronic device can determine, as the second candidate node, a first candidate node with a comprehensive similarity greater than or equal to the second similarity threshold. Then, the at least one second candidate node, the data query text, and the context information of the at least one second candidate node in the knowledge graph are input into the pre-trained large language model to obtain the target node. Specifically, the pre-trained large language model analyzes the semantics of the data query text, and in combination with the context information of the at least one second candidate node in the knowledge graph, analyzes the connection relationship between the query field and each second candidate node, and then determines the target node from the at least one second candidate node that matches the semantics of the data query text and matches the query field.

[0087] The second similarity threshold is pre-configured in the electronic device, and the second similarity threshold can be set according to actual needs, which is not limited in the embodiments of the present application. The pre-trained large language model is obtained by training a sample data set, and the sample data set includes annotated sample query fields, candidate nodes corresponding to the sample query fields, and context information of the candidate nodes in the knowledge graph. The context information of each second candidate node in the knowledge graph includes adjacent nodes of each second candidate node in the knowledge graph, and the connection relationship between the adjacent nodes, the attributes of the adjacent nodes, and the like. The connection relationship between the second candidate node and the adjacent node includes the relationship between the columns and / or the relationship between the tables and the columns. The relationship between the columns includes cross-table or cross-column data association through foreign keys, calculation logic, business rules, etc. The relationship between the tables and the columns includes defining table structure and data rules through primary keys, data types, constraints, indexes, etc.

[0088] For example, taking each first candidate node as node 1, node 2, and node 3, each query field as query field 1, and each first preset weight and second preset weight as 0.5, the electronic device calculates that the semantic similarity between query field 1 and node 1 is 0.67, the semantic similarity between query field 1 and node 2 is 0.75, and the semantic similarity between query field 1 and node 3 is 0.75; the structural similarity between query field 1 and node 1 is 0.33, the structural similarity between query field 1 and node 2 is 0.5, and the structural similarity between query field 1 and node 3 is 0.2. According to the above comprehensive similarity calculation formula, the electronic device calculates that the comprehensive similarity between query field 1 and node 1 is 0.5*(0.67+0.33)=0.5, the comprehensive similarity between query field 1 and node 2 is 0.5*(0.75+0.5)=0.625, and the comprehensive similarity between query field 1 and node 3 is 0.5*(0.75+0.2)=0.475. Based on this, the electronic device can determine node 2 as the target node.

[0089] Alternatively, if the second similarity threshold is 0.5, the electronic device can determine node 1 and node 2 as the second candidate nodes. Then, the electronic device inputs node 1, node 2, the data query text, and the context information of node 1 and node 2 in the knowledge graph into the pre-trained large language model, and outputs the target node, for example, the target node is node 2.

[0090] To better understand the comprehensive similarity provided by the embodiments of the present application, the following takes the data query text as “query the GDP growth rate of B city in 2024”, the target entity as “GDP year-on-year growth rate”, the query field as “GDP growth rate”, and the first candidate node as “GDP year-on-year growth rate” and “GDP month-on-month growth rate”, and the first preset weight as 0.6 and the second preset weight as 0.4 as examples to illustrate the comprehensive similarity provided by the embodiments of the present application. It should be understood that, generally, “GDP growth rate” is by default “GDP year-on-year growth rate”. Therefore, when the initial target entity “GDP growth rate” extracted from the data query text does not match the node in the knowledge graph in description, the electronic device can map the target entity to the specific field (node) in the knowledge graph according to the semantics of the target entity in the data query text to correct the description of the target entity.

[0091] It can be seen that the semantics between the first candidate node "GDP growth rate" and "GDP growth rate" are similar. In this example, the electronic device takes "GDP growth rate" as the center node (in this example, "GDP growth rate" as the center node is a table node), and calculates the path length of the center node and the first candidate node "GDP growth rate" (column node) and "GDP growth rate", respectively. The electronic device can determine that the path length of the center node and "GDP growth rate" is 1, and the path length of the center node and "GDP growth rate" is 2. The electronic device calculates the semantic similarity between the query field "GDP growth rate" and "GDP growth rate" as 0.75, and the semantic similarity between the query field "GDP growth rate" and "GDP growth rate" as 0.75. Further, in combination with the semantic similarity and the path length, the comprehensive similarity between the query field and "GDP growth rate" is calculated as 0.6*0.75+0.4*0.5=0.45+0.2=0.65, and the comprehensive similarity between the query field and "GDP growth rate" is calculated as 0.6*0.75+0.4*0.33=0.39+0.132=0.582. Based on this, the electronic device can determine that the comprehensive similarity between the query field and "GDP growth rate" is higher, and therefore the electronic device takes "GDP growth rate" as the target node.

[0092] It should be noted that the above example is a simple example provided to better understand the role of the comprehensive similarity provided by the embodiments of the present application. In actual application, the complexity of the data query text can be higher, such as involving multiple query fields. In this case, the descriptions of the center entity and the query field can be different, and are determined according to the actual situation.

[0093] In a possible implementation, after determining the target node, the electronic device can also determine the foreign key association relationship of the multiple data tables involved in the data query text based on the data query text, the target entity, and the knowledge graph. For example, the data query text includes "query the total order amount of A city in 2023", the electronic device determines that the standard query field corresponding to the query field "total order amount" is "order amount", and the electronic device determines that the order amount table includes the fields of region ID, year, and order amount (corresponding to the nodes in the knowledge graph) according to the structure of the knowledge graph and the data query text. The region ID is associated with the region table as a foreign key, and the region table includes the fields of region ID and region name. Based on this, the electronic device can determine that the data query text involves two data tables (order amount table and region table), and the two data tables are associated through the region ID foreign key.

[0094] The semantic of the data query text is analyzed by the pre-trained large language model, and the connection relationship between the query field and each second candidate node is analyzed in combination with the context information of the at least one second candidate node in the knowledge graph, and then the target node matched with the semantic of the data query text can be queried from the at least one second candidate node, which is beneficial to improve the accuracy of determining the target node.

[0095] In S204, the data query text is converted into a structured query statement according to the at least one target node, the connection relationship between the target entity and the at least one target node, the target business rule, and the data query text.

[0096] Each target node in the at least one target node is determined based on the manners described in the foregoing steps S202-S203. The at least one target node indicates a standard query field corresponding to the data query text. The connection relationship between the target entity and the at least one target node includes a relationship between a table and a column, and a relationship between columns. The relationship between columns includes data association across tables or columns through foreign keys, calculation logic, business rules, etc., and the relationship between a table and a column includes definition of table structure and data rules through primary keys, data types, constraints, indexes, etc. The connection relationship between the target entity and the at least one target node can be understood as a JOIN condition. The target business rule can be determined according to the data query requirement of the user. The target business rule can be preconfigured in the electronic device and matched from a business rule library based on the semantic of the data query text. For example, when the data queried by the user is different from the data unit of the data in the data table, the target business rule can be a unit conversion formula.

[0097] Specifically, the electronic device can input the at least one target node, the connection relationship between the target entity and the at least one target node, the target business rule, and the data query text into a pre-trained sentence conversion model to obtain a structured query statement. The pre-trained sentence conversion model is trained according to a sample query statement data set. The sentence conversion model can be a large language model, a deep learning model, or a machine learning model, etc.

[0098] In a possible implementation, after obtaining the structured query statement, the electronic device can execute the structured query statement to query target data matched with the data query text from a plurality of data tables. The specific manner in which the electronic device executes the structured query statement to query the target data is the same as the traditional query manner, which is not limited in the embodiments of the present application.

[0099] It can be seen that, in the embodiment of the present application, since the target entity indicates the query intention of the data query text, when the structural similarity between the query field and each first candidate node is calculated, the target entity is taken as the center node (or starting node), and the path length between the target entity and each first candidate node is calculated to calculate the structural similarity between the query field and each first candidate node. In this way, the shorter the path length between each first candidate node and the target entity, the more closely the business association between each first candidate node and the target entity, and the more closely the business association between the query field and each first candidate node. By combining the semantic similarity and the structural similarity to calculate the comprehensive similarity, the comprehensive similarity can reflect not only the semantic association relationship between the query field and the node, but also the structural association relationship between the query field and the node. Based on this, the target node is obtained according to the comprehensive similarity, which can effectively avoid the case that the query field and the node are semantically similar but have no business association, thereby improving the accuracy of determining the target node, and further improving the accuracy of the converted SQL statement.

[0100] The method for converting a natural language sentence into an SQL provided in the embodiments of the present application can be applied to various data query scenarios, especially in data query scenarios where multiple fields have similar semantics, such as medical data query scenarios, financial data query scenarios, and the like.

[0101] Based on the same inventive concept, the embodiments of the present application provide a device for converting a natural language sentence into an SQL, which is used to implement any of the above methods for converting a natural language sentence into an SQL, for example, the method for converting a natural language sentence into an SQL shown in FIG. 8, and the device can also implement the functions of the electronic device described above. Figure 2

[0102] Please refer to Figure 5 , which is a structural schematic diagram of a device for converting a natural language sentence into an SQL provided in the embodiments of the present application. As shown in Figure 5 Figure 5 The device for converting a natural language sentence into an SQL includes an analysis module 501, a determination module 502, and a conversion module 503.

[0103] ​​The parsing module 501 is configured to perform semantic parsing on the data query text to extract a target entity and at least one query field, where the target entity is used to indicate a query intention of the data query text.

[0104] In a possible implementation, the determining module 502 is further configured to: traverse the knowledge graph to determine path lengths from the target entity to the first candidate nodes; and calculate the structural similarity between each query field and each first candidate node according to the path lengths from the target entity to the first candidate nodes and a preset inverse function.

[0105] In a possible implementation, the determining module 502 is specifically configured to: for each of the first candidate nodes, calculate a first similarity between each query field and each first candidate node according to a product of the semantic similarity between each query field and each first candidate node and a first preset weight; calculate a second similarity between each query field and each first candidate node according to the structural similarity between each query field and each first candidate node and a second preset weight; and determine the comprehensive similarity between each query field and each first candidate node according to a sum of the first similarity and the second similarity, to obtain the comprehensive similarity between each query field and each first candidate node.

[0106] In a possible implementation, the determining module 502 is further configured to: before determining the comprehensive similarity between each query field and each first candidate node according to the semantic similarity and the structural similarity between each query field and each first candidate node, calculate the semantic similarity between each query field and each node in the knowledge graph; and determine the first candidate nodes according to the semantic similarity between each query field and each node and a first similarity threshold.

[0107] In a possible implementation, the determining module 502 is specifically configured to: determine at least one second candidate node according to the comprehensive similarity between each query field and each first candidate node and the second similarity threshold; and input the at least one second candidate node, the data query text, and the context information of the at least one second candidate node in the knowledge graph into the pre-trained large language model to obtain the target node.

[0108] In a possible implementation, the determining module 502 is further configured to: before determining the comprehensive similarity between each query field and each first candidate node according to the semantic similarity and the structural similarity between each query field in the at least one query field and each first candidate node, extract metadata information of each data table in the plurality of data tables, where the metadata information includes table description information and column description information; construct a plurality of nodes and attribute information of each node in the plurality of nodes according to the table description information and the column description information, where one node is used to indicate one table entity or column entity; extract the table-column relationship and the column-column relationship between the plurality of nodes according to the table description information and the column description information; and construct relationship edges between the plurality of nodes according to the table-column relationship and the column-column relationship, to obtain the knowledge graph.

[0109] In a possible implementation, the converting module 503 is specifically configured to: input the at least one target node, the target entity, the connection relationship between the at least one target node and the target entity, the target business rule, and the data query text into a pre-trained sentence conversion model to obtain a structured query statement, where the pre-trained sentence conversion model is trained according to a sample query statement data set.

[0110] Based on the same inventive concept, an embodiment of the present application provides another device for converting a natural language sentence into SQL. The device is used to implement any of the methods for converting a natural language sentence into SQL described above, for example, the method for converting a natural language sentence into SQL shown in Figure 2 The device can also implement the functions of the electronic device described above.

[0111] Please refer to Figure 6 for a structural schematic diagram of another device for converting a natural language sentence into SQL provided by an embodiment of the present application. Figure 6 The device for converting a natural language sentence into SQL includes at least one processor 601 and a memory 602 communicatively connected to the at least one processor 601.

[0112] The processor 601 can be a general-purpose processor or a special-purpose processor. The processor 601 includes, for example, a baseband processor or a central processing unit. The baseband processor can be used to process a communication protocol and communication data. The central processing unit can be used to process Figure 6The natural language sentence conversion SQL device shown controls, executes software programs and / or processes data. Different processors can be independent devices or can be arranged in one or more processing circuits, for example, integrated on one or more application-specific integrated circuits.

[0113] In one embodiment, the memory 602 stores instructions executable by the at least one processor 601, and the at least one processor 601 implements the functions of the electronic device described above by executing the instructions stored in the memory 602. Accordingly, the at least one processor 601 can also implement the steps performed by the electronic device described above.

[0114] In this embodiment, Figure 6 The natural language sentence conversion SQL device shown can also implement the functions of the Figure 5 The natural language sentence conversion SQL device shown, and Figure 6 The at least one processor 601 in the natural language sentence conversion SQL device shown can also implement the functions of the parsing module 501, the determination module 502 and the conversion module 503.

[0115] Based on the same inventive concept, the embodiments of the present application provide a computer readable storage medium, which stores computer instructions, and when the computer instructions are run on a computer, the computer executes the natural language sentence conversion SQL method of any of the above embodiments, for example, the natural language sentence conversion SQL method shown above. Figure 2 The natural language sentence conversion SQL method shown.

[0116] Based on the same inventive concept, the embodiments of the present application provide a computer program product, which contains computer instructions, and when the computer instructions are run on a computer, the natural language sentence conversion SQL method of any of the above embodiments is implemented, for example, the natural language sentence conversion SQL method shown above. Figure 2 The natural language sentence conversion SQL method shown.

[0117] It should be understood that, in the embodiments of the present application, the processor can be a central processing unit (CPU), and the processor can also be other general-purpose processors, digital signal processors (DSPs), application-specific integrated circuits (ASICs), field programmable gate arrays (FPGAs) or other programmable logic devices, discrete gates or transistor logic devices, discrete hardware components, etc. The general-purpose processor can be a microprocessor or the processor can also be any conventional processor.

[0118] In the implementation process, the steps of the above method can be completed by integrated logic circuits of hardware in the processor or instructions in the form of software. The steps of the method disclosed in combination with the embodiments of the present application can be directly embodied as hardware processor execution completion, or executed by a combination of hardware and software modules in the processor. The software module can be located in a mature storage medium in the art such as random access memory, flash memory, read-only memory, programmable read-only memory, electrically erasable programmable memory, register, etc. The storage medium is located in the memory, and the processor executes the instructions in the memory to complete the steps of the above method in combination with its hardware. To avoid repetition, it will not be described in detail here.

[0119] Those of ordinary skill in the art can realize that the units and algorithm steps of each example described in combination with the embodiments disclosed herein can be realized in electronic hardware or a combination of computer software and electronic hardware. Whether the functions are executed in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of the present application.

[0120] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working processes of the above-described system, device and unit can refer to the corresponding processes in the foregoing method embodiments, which will not be described here.

[0121] In several embodiments provided in the present application, it should be understood that the disclosed system, device and method can be implemented in other ways. For example, the device embodiments described above are only schematic. For example, the division of the units is only a logical function division, and actual implementation can have another division manner. For example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. In addition, the coupling or direct coupling or communication connection between the units shown or discussed can be indirect coupling or communication connection through some interface, device or unit, and can be electrical, mechanical or other forms.

[0122] The units described as separate components can or can not be physically separated, and the components shown as units can or can not be physical units, i.e. they can be located in one place or distributed on multiple network units. Some or all of the units can be selected according to actual needs to achieve the purpose of the embodiment.

[0123] In addition, each functional unit in each embodiment of the present application can be integrated into one processing unit, or each unit can exist physically, or two or more units can be integrated into one unit.

[0124] If the functions are implemented in the form of software function units and sold or used as independent products, they can be stored in a computer readable storage medium. Based on this understanding, the technical solutions of the present application or the parts that contribute to the related art or the parts of the technical solutions can be embodied in the form of software products. The computer software product is stored in a storage medium and includes a plurality of instructions for causing a computer device (which can be a personal computer, a server, or a network device, etc.) to execute all or part of the steps of the methods described in the embodiments of the present application. The aforementioned storage medium includes a U disk, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk, and various media that can store program codes.

[0125] The above is only a specific implementation of the present application, but the protection scope of the present application is not limited thereto. Any person skilled in the art can easily think of changes or replacements within the technical scope disclosed in the present application, which should be covered within the protection scope of the present application. Therefore, the protection scope of the present application should be subject to the protection scope of the claims.

Claims

1. A method for converting natural language statements into SQL, characterized in that: include: Performing semantic parsing on the data query text to extract a target entity and at least one query field, wherein the target entity is used to indicate the query intent of the data query text; Traversing a pre-stored knowledge graph to determine the path length from the target entity to each first candidate node in the knowledge graph; Calculating the structural similarity between each query field in the at least one query field and each first candidate node based on the path length from the target entity to the first candidate nodes and a preset inverse function; Determine, based on the semantic similarity and structural similarity between each query field in the at least one query field and each first candidate node in a pre-stored knowledge graph, a comprehensive similarity between each query field and each first candidate node, wherein the knowledge graph is constructed based on multiple data tables, and the structural similarity is used to indicate the degree of structural association between each query field and each first candidate node in the knowledge graph. The structural similarity between each query field and each first candidate node is determined based on the path length between the target entity and each first candidate node, and the structural similarity is further used to indicate the degree of business association between each query field and each first candidate node; Determining a target node corresponding to each query field based on the comprehensive similarity between each query field and each first candidate node; Input at least one target node, the connection relationship between the target entity and the at least one target node, the target business rule, and the data query text into a pre-trained statement conversion model to obtain a structured query statement, wherein the pre-trained statement conversion model is trained based on a sample query statement data set.

2. The method according to claim 1, characterized in that The determining, based on the semantic similarity and structural similarity between each query field in the at least one query field and each first candidate node in the pre-stored knowledge graph, a comprehensive similarity between each query field and each first candidate node includes: For each of the first candidate nodes, calculate a first similarity based on a product of a semantic similarity between each query field and each first candidate node and a first preset weight; Calculating a second similarity based on the structural similarity between each query field and each first candidate node and a second preset weight; The comprehensive similarity between each query field and each first candidate node is determined according to the sum of the first similarity and the second similarity, so as to obtain the comprehensive similarity between each query field and each first candidate node.

3. The method according to claim 1, characterized in that Before determining the comprehensive similarity between each query field and each first candidate node based on the semantic similarity and structural similarity between each query field in the at least one query field and each first candidate node, the method further includes: Calculating the semantic similarity between each query field and each node in the knowledge graph; The first candidate nodes are determined according to the semantic similarity between each query field and the nodes and a first similarity threshold.

4. The method according to claim 1, wherein The determining, based on the comprehensive similarity between each query field and each first candidate node, a target node corresponding to each query field includes: Determining at least one second candidate node according to the comprehensive similarity between each query field and each first candidate node and a second similarity threshold; The at least one second candidate node, the data query text, and the context information of the at least one second candidate node in the knowledge graph are input into a pre-trained large language model to obtain the target node.

5. The method according to any one of claims 1 to 4, characterized in that Before determining the comprehensive similarity between each query field and each first candidate node based on the semantic similarity and structural similarity between each query field in the at least one query field and each first candidate node, the method further includes: Extracting metadata information of each data table from the plurality of data tables, wherein the metadata information includes table description information and column description information; Constructing a plurality of nodes and attribute information of each of the plurality of nodes according to the table description information and the column description information, wherein a node is used to indicate a table entity or a column entity; Extracting table-column relationships and column-column relationships between multiple nodes based on the table description information and the column description information; According to the table-column relationship and the column-column relationship, the relationship edges between the multiple nodes are constructed to obtain the knowledge graph.

6. A device for converting natural language statements into SQL, characterized in that: include: A parsing module, configured to perform semantic parsing on the data query text to extract a target entity and at least one query field, wherein the target entity is used to indicate the query intent of the data query text; a determination module, configured to traverse a pre-stored knowledge graph, determine a path length from the target entity to each first candidate node in the knowledge graph, and calculate a structural similarity between each query field in the at least one query field and each first candidate node based on the path length from the target entity to the each first candidate node and a preset inverse function; The determination module is further configured to determine a comprehensive similarity between each query field and each first candidate node based on semantic similarity and structural similarity between each query field in the at least one query field and each first candidate node in a pre-stored knowledge graph, wherein the knowledge graph is constructed based on multiple data tables, and the structural similarity is used to indicate a degree of structural association between each query field and each first candidate node in the knowledge graph. The structural similarity between each query field and each first candidate node is determined based on a path length between the target entity and each first candidate node, and the structural similarity is further used to indicate a degree of business association between each query field and each first candidate node. The determining module is further configured to determine a target node corresponding to each query field based on the comprehensive similarity between each query field and each first candidate node; A conversion module is used to input at least one target node, the connection relationship between the target entity and the at least one target node, the target business rules and the data query text into a pre-trained statement conversion model to obtain a structured query statement, wherein the pre-trained statement conversion model is trained based on a sample query statement data set.

7. A device for converting natural language statements into SQL, characterized in that: include: a memory storing executable program code; a processor coupled to the memory; The processor calls the executable program code stored in the memory to execute the method according to any one of claims 1 to 5.

8. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the method according to any one of claims 1 to 5 is implemented.

Citation Information

Patent Citations

  • Multi-skill task type dialogue system construction method fusing chat and common sense

    CN114153955A

  • Unmanned aerial vehicle fault diagnosis method, device and equipment and storage medium

    CN118445450A