Query statement generation method and device based on syntax analysis tree, equipment and medium

By generating an initial syntax parse tree and combining it with database mapping relationships, the problem of inaccurate expression of user query intent was solved, thereby improving the accuracy of query statements.

CN116304231BActive Publication Date: 2026-04-21PING AN TECH (SHENZHEN) CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
PING AN TECH (SHENZHEN) CO LTD
Filing Date
2023-04-07
Publication Date
2026-04-21

AI Technical Summary

Technical Problem

In existing technologies, the personalization and complexity of user questions lead to low accuracy of query statements, which cannot accurately express the user's query intent.

Method used

By generating an initial parse tree, extracting candidate query syntax components by combining database mapping relationships, and interacting with the target object to obtain feedback information, a target parse tree is generated, ultimately yielding an accurate query statement.

Benefits of technology

It improves the accuracy of query statements, resolves ambiguity issues, and uncovers the query intent of the target object.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN116304231B_ABST
    Figure CN116304231B_ABST
Patent Text Reader

Abstract

The method and device for generating a query statement based on a syntax analysis tree, equipment and medium provided by the application relate to the technical field of computers. The method comprises the following steps: receiving a question query statement sent by a target object; generating an initial syntax analysis tree according to the question query statement; extracting a syntax mapping result of each initial node from a preset database according to each initial node to obtain the syntax mapping result of each initial node; sending at least two candidate query syntax components to the target object so as to obtain a target query syntax component according to component feedback information; assembling the initial nodes according to the target query syntax component to obtain a target syntax analysis tree; and translating the target syntax analysis tree to obtain a target query statement; wherein the target query statement comprises an SQL statement. Through interaction with the target object, the ambiguity problem can be solved, and the query intention of the target object can be mined. In summary, the accuracy of the target query statement can be improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of computer technology, and in particular to a method, apparatus, device, and medium for generating query statements based on a syntax parse tree. Background Technology

[0002] With the rapid development of artificial intelligence technology, the fast iteration and updating of big data necessitates faster and more automated query technologies. Especially in the widely used field of human-computer interaction, natural language interfaces can convert user questions into corresponding query statements, enabling interaction with the database to return relevant answers. Currently, related technologies typically customize syntax rules for each database to generate query statements. However, due to the personalization and complexity of user questions, query statements generated through customized syntax rules often fail to accurately express the user's query intent, resulting in low accuracy. Therefore, providing a query statement generation method based on syntax parse trees to improve query accuracy has become an urgent technical problem to be solved. Summary of the Invention

[0003] The main objective of this application is to propose a query statement generation method, apparatus, device, and medium based on a syntax parse tree, which can improve the accuracy of query statements.

[0004] To achieve the above objectives, a first aspect of this application proposes a query statement generation method based on a syntax parse tree, the method comprising:

[0005] Receive a query statement sent by the target object; wherein the query statement includes an SQL statement;

[0006] An initial syntax parse tree is generated based on the query statement; wherein the initial syntax parse tree includes at least two initial nodes;

[0007] Based on the mapping relationship extracted from the preset database for each initial node, a syntax mapping result for each initial node is obtained; wherein, the syntax mapping result includes a first result or a second result, the first result is used to indicate that the initial node includes a candidate query syntax component, and the second result is used to indicate that the initial node includes at least two candidate query syntax components;

[0008] If the syntax mapping result is the first result, the candidate query syntax component is used as the target query syntax component, and the initial node is assembled according to the target query syntax component to obtain the target syntax parse tree;

[0009] If the syntax mapping result is the second result, the at least two candidate query syntax components are sent to the target object according to the second result, and the component feedback information fed back by the target object according to the at least two candidate query syntax components is obtained. The target query syntax component is obtained according to the component feedback information, and the initial node is assembled according to the target query syntax component to obtain the target syntax parse tree.

[0010] The target syntax parse tree is translated to obtain the target query statement; wherein, the target query statement includes an SQL statement.

[0011] In some embodiments, after obtaining the syntax mapping result for each of the initial nodes, the method further includes:

[0012] If the syntax mapping result is the second result, the initial node is assembled according to at least two candidate query syntax components to obtain at least two candidate syntax parse trees;

[0013] Each candidate parse tree is translated to obtain the initial candidate query statement;

[0014] Send at least two of the initial candidate query statements to the target object;

[0015] Obtain statement feedback information of the target object based on at least two initial candidate query statements, and obtain the target candidate query statement based on the statement feedback information;

[0016] Based on the target candidate query statement, at least two candidate parse trees are filtered to obtain the target parse tree.

[0017] In some embodiments, the step of extracting mapping relationships from a preset database based on each initial node to obtain the syntax mapping result of each initial node includes:

[0018] Determine the syntax component mapping table based on the database;

[0019] Extract the node category of the initial node to obtain the initial node category;

[0020] The syntax mapping result of each initial node is obtained from the syntax component mapping table according to the initial node category.

[0021] In some embodiments, the step of extracting mapping relationships from a preset database based on each initial node to obtain the syntax mapping result of each initial node includes:

[0022] Determine the syntax component mapping table based on the database;

[0023] Extract the node category of the initial node to obtain the first node category;

[0024] The node relationships between the initial nodes are extracted from the initial syntax parse tree to obtain initial relationships; wherein, the initial relationships are used to indicate that there is an inclusion relationship between the initial nodes;

[0025] The syntax mapping result of each initial node is obtained from the syntax component mapping table based on the first node category and the initial relationship.

[0026] In some embodiments, obtaining the syntax mapping result of each initial node from the syntax component mapping table based on the first node category and the initial relationship includes:

[0027] The grammar component mapping table is filtered according to the first node category to obtain at least one candidate grammar component for each initial node.

[0028] For each initial node, at least one candidate grammar component of the initial node, at least one candidate grammar component of the parent node that conforms to the initial relationship with the initial node, and at least one candidate grammar component of the child node that conforms to the initial relationship with the initial node are aggregated to obtain the grammar mapping result of the initial node.

[0029] In some embodiments, the target syntax parse tree includes at least two target nodes, each target node including target child nodes. Before translating the target syntax parse tree to obtain the target query statement, the method further includes:

[0030] The target syntax parse tree is updated; specifically, this includes:

[0031] Traverse the target nodes of the target syntax parse tree, extract the node categories of the target nodes, and obtain the second node category;

[0032] If the second node category belongs to a preset computing node type, then at least one child node to be added is generated;

[0033] Based on the target syntax parse tree, the target node and the target child node are assembled into a sentence to obtain the original sentence;

[0034] The target node, the target child node, and the child node to be added are assembled into a sentence to obtain the target statement;

[0035] The similarity between the original statement and the target statement is calculated to obtain the sentence similarity.

[0036] If the sentence similarity is greater than a preset similarity threshold, the child node to be added is used as a new child node of the target node, and the target syntax parse tree is updated according to the new child node.

[0037] In some embodiments, generating an initial syntax parse tree based on the query statement includes:

[0038] The query statement is subjected to part-of-speech tagging to obtain a part-of-speech tagging sequence; wherein, the part-of-speech tagging sequence includes at least two word segments and the part-of-speech tagging of each word segment;

[0039] Determine the inclusion relationship between the word segments based on their parts of speech;

[0040] The word segmentation order is extracted from the part-of-speech tagging sequence. Based on the word segmentation order, the word segments whose part of speech belongs to subject, predicate, and object are taken as the main word segments. Among them, the remaining word segments other than the main word segments are the additional word segments.

[0041] Based on each of the main word segments, a main node is created, and the main nodes are assembled according to a preset grammatical order to obtain a main syntax parse tree.

[0042] Based on the inclusion relationship, the additional word segment is determined to be a child node of the main node, and the main syntax parse tree is processed by adding nodes based on the child nodes to obtain the initial syntax parse tree.

[0043] To achieve the above objectives, a second aspect of this application provides a query statement generation apparatus based on a syntax parse tree, the apparatus comprising:

[0044] The problem query statement receiving module is used to receive problem query statements sent by the target object; wherein, the problem query statement includes an SQL statement;

[0045] An initial syntax parse tree generation module is used to generate an initial syntax parse tree based on the question query statement; wherein, the initial syntax parse tree includes at least two initial nodes;

[0046] The query syntax component mapping module is used to extract mapping relationships from a preset database based on each initial node to obtain a syntax mapping result for each initial node; wherein, the syntax mapping result includes a first result or a second result, the first result being used to indicate that the initial node includes a candidate query syntax component, and the second result being used to indicate that the initial node includes at least two candidate query syntax components;

[0047] The first syntax parse tree generation module is used to, if the syntax mapping result is the first result, take the candidate query syntax component as the target query syntax component, assemble the initial node according to the target query syntax component, and obtain the target syntax parse tree;

[0048] The second syntax parse tree generation module is used to, if the syntax mapping result is the second result, send the at least two candidate query syntax components to the target object according to the second result, obtain the component feedback information fed back by the target object according to the at least two candidate query syntax components, obtain the target query syntax component according to the component feedback information, and assemble the initial node according to the target query syntax component to obtain the target syntax parse tree;

[0049] The target query statement generation module is used to translate the target syntax parse tree to obtain the target query statement; wherein, the target query statement includes an SQL statement.

[0050] To achieve the above objectives, a third aspect of this application provides an electronic device, which includes a memory and a processor. The memory stores a computer program, and the processor executes the computer program to implement the method described in the first aspect.

[0051] To achieve the above objectives, a fourth aspect of the present application provides a storage medium, which is a computer-readable storage medium storing a computer program that, when executed by a processor, implements the method described in the first aspect.

[0052] The query statement generation method, apparatus, device, and medium proposed in this application, based on a syntax parse tree, improves query statement generation efficiency by converting the query statement into an initial syntax parse tree. Mapping the initial syntax parse tree to a database yields an initial syntax parse tree conforming to the database schema. To reduce ambiguity in the initial syntax parse tree, this embodiment sends candidate query syntax components generated by the mapping to a target object. The aim is to obtain the target query syntax component through interaction with the target object. Based on the target query syntax component, a target syntax parse tree is generated, and finally, the target query statement is obtained from the target syntax parse tree. In summary, the embodiments of this application can improve the accuracy of the target query statement. Attached Figure Description

[0053] Figure 1 This is a flowchart of a query statement generation method based on a syntax parsing tree provided in an embodiment of this application;

[0054] Figure 2 yes Figure 1 The flowchart of step S102 in the document;

[0055] Figure 3 yes Figure 1 The flowchart of step S103 in the process;

[0056] Figure 4 yes Figure 1 The flowchart of step S103 in the process;

[0057] Figure 5 yes Figure 1 The flowchart of step S404 in the document;

[0058] Figure 6 This is a flowchart of a query statement generation method based on a syntax parsing tree provided in another embodiment of this application;

[0059] Figure 7 This is a flowchart of a query statement generation method based on a syntax parsing tree provided in another embodiment of this application;

[0060] Figure 8 This is a block diagram of the module structure of the query statement generation device based on the syntax parsing tree provided in the embodiments of this application;

[0061] Figure 9 This is a schematic diagram of the hardware structure of the electronic device provided in the embodiments of this application. Detailed Implementation

[0062] To make the objectives, technical solutions, and advantages of this application clearer, the following detailed description is provided in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative and not intended to limit the scope of this application.

[0063] It should be noted that although functional modules are divided in the device schematic diagram and a logical order is shown in the flowchart, in some cases, the steps shown or described may be performed in a different order than the module division in the device or the order in the flowchart. The terms "first," "second," etc., in the specification, claims, and the aforementioned drawings are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence.

[0064] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as commonly understood by one of ordinary skill in the art to which this application belongs. The terminology used herein is for the purpose of describing embodiments of this application only and is not intended to limit this application.

[0065] First, let's analyze some of the terms used in this application:

[0066] Artificial intelligence (AI) is a new branch of computer science that studies, develops, and applies theories, methods, technologies, and systems to simulate, extend, and expand human intelligence. It aims to understand the essence of intelligence and produce intelligent machines that can react in a way similar to human intelligence. Research in this field includes robotics, speech recognition, image recognition, natural language processing, and expert systems. AI can simulate the information processes of human consciousness and thought. Furthermore, AI utilizes digital computers or machines controlled by digital computers to simulate, extend, and expand human intelligence, perceiving the environment, acquiring knowledge, and using that knowledge to achieve optimal results.

[0067] Natural Language Processing (NLP): NLP uses computers to process, understand, and utilize human language (such as Chinese and English). NLP is a branch of artificial intelligence and an interdisciplinary field of computer science and linguistics, often referred to as computational linguistics. NLP includes syntactic analysis, semantic analysis, and discourse understanding. It is commonly used in machine translation, handwritten and printed character recognition, speech recognition and text-to-speech conversion, intent recognition, information extraction and filtering, text classification and clustering, sentiment analysis, and opinion mining. It involves data mining, machine learning, knowledge acquisition, knowledge engineering, artificial intelligence research, and linguistic research related to language computation.

[0068] Structured Query Language (SQL) is the standard language for relational databases, used to modify and query data stored in relational databases.

[0069] Abstract Syntax Tree (AST): A tree-like representation of the abstract syntactic structure of source code, where each node in the tree represents a structure in the source code. In this embodiment, it is represented as a syntax parse tree.

[0070] Currently, with the rapid development of artificial intelligence technology, the rapid iteration and updating of big data necessitates faster and more automated query technologies. Especially in the widely used field of human-computer interaction, natural language interfaces can convert user questions into corresponding SQL query statements. These SQL queries then interact with the database to return the appropriate answers. The key technology lies in how the system can, in multi-round interaction scenarios, uncover the user's explicit or implicit query intent and, in conjunction with the database schema, generate query statements that match the user's target intent.

[0071] In most related technologies, manual syntax is custom-designed for each database, resulting in poor scalability and generalization across different databases. Normal natural language questions often lack fixed formats and semantics, leading to low matching rates between questions and queries designed using manual syntax rules. Furthermore, the inability to accurately capture the user's query intent results in low query accuracy.

[0072] Therefore, how to provide a query statement generation method based on syntax parse trees that can improve the accuracy of query statements has become an urgent technical problem to be solved.

[0073] Based on this, the main objective of the embodiments of this application is to propose a query statement generation method, apparatus, device, and medium based on a syntax parsing tree. The aim is to use natural language understanding technology to transform a given natural language problem into a tree structure, and to interact with the target object through the tree structure in order to parse and reconstruct the tree structure, resolve ambiguity issues, uncover effective query intent, and generate accurate SQL query statements.

[0074] The query statement generation method based on syntax parse trees provided in this application can be applied to the server side, or it can be software running on a terminal or server side. The server side can be configured as an independent physical server, or as a server cluster or distributed system composed of multiple physical servers, or as a cloud server providing basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communication, middleware services, domain name services, security services, CDN, and big data and artificial intelligence platforms; the software can be an application that implements the query statement generation method based on syntax parse trees, etc., but is not limited to the above forms.

[0075] This application can be used in a wide variety of general-purpose or special-purpose computer system environments or configurations. Examples include server computers, multiprocessor systems, microprocessor-based systems, set-top boxes, programmable consumer electronics devices, network PCs, and distributed computing environments including any of the above systems or devices. This application can be described in the general context of computer-executable instructions executed by a computer, such as program modules. Generally, program modules include routines, programs, objects, components, data structures, etc., that perform specific tasks or implement specific abstract data types. This application can also be practiced in distributed computing environments where tasks are performed by remote processing devices connected via a communication network. In distributed computing environments, program modules can reside in local and remote computer storage media, including storage devices.

[0076] This application provides a method, apparatus, device, and medium for generating query statements based on a syntax parse tree. The specific implementation is described in the following embodiments. First, the method for generating query statements based on a syntax parse tree in this application is described.

[0077] It should be noted that in all specific embodiments of this application, when processing data related to user identity or characteristics, such as user information, user behavior data, user historical data, and user location information, user permission or consent is obtained first. Furthermore, the collection, use, and processing of this data comply with relevant laws, regulations, and standards. In addition, when embodiments of this application require access to sensitive personal information of users, separate permission or consent from the user is obtained through pop-ups or redirection to confirmation pages. Only after obtaining the user's separate permission or consent is the necessary user-related data required for the proper functioning of these embodiments acquired.

[0078] Figure 1 This is an optional flowchart of a query statement generation method based on a syntax parsing tree provided in the embodiments of this application, which may include, but is not limited to, steps S101 to S106.

[0079] Step S101: Receive a problem query statement sent by the target object; wherein, the problem query statement includes an SQL statement;

[0080] Step S102: Generate an initial syntax parse tree based on the query statement; wherein the initial syntax parse tree includes at least two initial nodes;

[0081] Step S103: Extract the mapping relationship from the preset database according to each initial node to obtain the syntax mapping result of each initial node; wherein, the syntax mapping result includes a first result or a second result, the first result is used to indicate that the initial node includes a candidate query syntax component, and the second result is used to indicate that the initial node includes at least two candidate query syntax components.

[0082] Step S104: If the syntax mapping result is the first result, the candidate query syntax component is used as the target query syntax component, and the initial node is assembled according to the target query syntax component to obtain the target syntax parse tree.

[0083] Step S105: If the syntax mapping result is the second result, send at least two candidate query syntax components to the target object according to the second result, obtain the component feedback information from the target object based on the at least two candidate query syntax components, obtain the target query syntax component based on the component feedback information, assemble the initial node according to the target query syntax component, and obtain the target syntax parse tree.

[0084] Step S106: Translate the target syntax parse tree to obtain the target query statement; wherein, the target query statement includes an SQL statement.

[0085] Steps S101 to S106 of this embodiment, by converting the query statement into an initial syntax parse tree, can improve the efficiency of query statement generation. Mapping the initial syntax parse tree to the database yields an initial syntax parse tree that conforms to the database schema. To reduce ambiguity in the initial syntax parse tree, this embodiment sends the candidate query syntax components generated by the mapping to the target object. The aim is to obtain the target query syntax component through interaction with the target object. Based on the target syntax parse tree generated from the target query syntax component, the target query statement is finally obtained through the target syntax parse tree. This not only resolves ambiguity but also uncovers the query intent of the target object. In summary, this embodiment can improve the accuracy of the target query statement.

[0086] It should be noted that the target objects referred to in this application include robots, clients, and servers, which can send query statements. For example, a user enters a query statement on a human-computer interaction interface, and the intelligent robot (target object) uploads the query statement to the server so that this application embodiment can receive query statements sent by the target object. As another example, a user enters a query statement on the client's query interface, and the client (target object) sends the query statement outwards so that this application embodiment can receive query statements sent by the target object. Yet another example is the interaction between two servers. The first server receives the query statement uploaded by the user and forwards it outwards so that the second server can receive the query statement sent by the first server (target object).

[0087] In step S101 of some embodiments, the received query statement can be in text form or in voice form. If it is in voice form, it is converted into text form using a speech recognition method.

[0088] In step S102 of some embodiments, for the question query statement, natural language understanding technology is used to convert the question query statement into a syntax parse tree. Specifically, the question query statement is segmented into words and part-of-speech tagging is performed to obtain the part-of-speech tagging results. An initial node is generated based on each word segment, and the initial nodes are assembled according to the word relationships between the word segments to obtain an initial syntax parse tree. It should be noted that the word relationships include sequence relationships, subject-verb-object relationships, and inclusion relationships. During the assembly of the initial nodes, the initial nodes are added to the initial syntax parse tree according to the word relationships. For example, the question query statement is "I want to apply for Class A car insurance". According to the sequence relationship, "I" as the subject is the root node, the first-level child node is "apply" (verb), and then the second-level child node is "car insurance" (object). Since there is an inclusion relationship between car insurance and Class A insurance, "Class A insurance" is a child node of "car insurance".

[0089] Please see Figure 2 In some embodiments, step S102 may include, but is not limited to, steps S201 to S205:

[0090] Step S201: Perform part-of-speech tagging on the query statement to obtain a part-of-speech tagging sequence; wherein, the part-of-speech tagging sequence includes at least two word segments and the part-of-speech tagging of each word segment;

[0091] Step S202: Determine the inclusion relationship between word segments based on their parts of speech;

[0092] Step S203: Extract the word segmentation order from the part-of-speech tagging sequence, and select the word segments whose parts of speech belong to subject, predicate, and object as the main word segments according to the word segmentation order; among them, the remaining word segments other than the main word segments are the additional word segments;

[0093] Step S204: Create a main node based on each main word segmentation, and assemble the main nodes according to a preset grammatical order to obtain a main syntax parse tree.

[0094] Step S205: Determine the child nodes of the main node based on the inclusion relationship of the additional word segmentation, and perform node addition processing on the main syntax parse tree based on the child nodes to obtain the initial syntax parse tree.

[0095] Steps S201 to S205 of this embodiment involve using part-of-speech tagging (e.g., the NLTK toolkit) to tag each word in the query statement with its part-of-speech tagging and extracting inter-word relationships. These inter-word relationships include inclusion relationships, subject-verb-object relationships, and order relationships. Each word is mapped to a node in the initial parse tree based on these relationships, thus obtaining the initial parse tree. This embodiment can improve the accuracy of generating the initial parse tree.

[0096] Understandably, the initial parse tree can express the query statement, but the database cannot match it, preventing the generation of the target query statement. Therefore, it is necessary to extract the mapping relationship from the initial parse tree in conjunction with the database, with the aim of generating a target parse tree that matches the database schema.

[0097] In step S103 of some embodiments, the initial node is mapped using the database to obtain a syntax component mapping result for the initial node. The syntax component mapping result includes a first result or a second result. The first result indicates that the initial node includes one candidate query syntax component. The second result indicates that the initial node includes at least two candidate query syntax components.

[0098] It should be noted that the database includes database schema information. Database schema information includes table information and column information. Table information includes at least one table name, and column information includes at least one column name. By combining the database schema information with the initial node, the mapping result of the initial node's syntax components is obtained. Alternatively, it can mean combining the database table information and database column information to map the initial node to a database table name, column name, or SQL keyword.

[0099] Please see Figure 3 In some embodiments, step S103 may include, but is not limited to, steps S301 to S303:

[0100] Step S301: Determine the syntax component mapping table based on the database;

[0101] Step S302: Extract the node category of the initial node to obtain the initial node category;

[0102] Step S303: Obtain the syntax mapping result of each initial node from the syntax component mapping table according to the initial node category.

[0103] Node categories Corresponding SQL syntax components Select Node (SN) SELECT Operator node (ON) This represents an operator, such as "= or < or >". Named Node (NN) Corresponds to a table name or column name field in the database. Value Node (NN) The value corresponding to the name node field in the database Metric Node (QN) ALL, SOME, ANY, etc. Logical Node (LN) AND, OR, NOT Compute function nodes (FN) This represents a computation function, such as COUNT, MIN, etc.

[0104] Table 1

[0105] Steps S301 to S303, as illustrated in the embodiments of this application, refer to Table 1 to determine a syntax component mapping table based on the database. The syntax component mapping table includes the mapping relationship between node categories and syntax components. Therefore, at least one candidate query syntax component for each initial node can be obtained from the syntax component mapping table based on the initial node category. The syntax mapping result is obtained by aggregating the candidate query syntax components.

[0106] It is understandable that steps S301 to S303 can map individual initial nodes. Considering that there are node relationships between initial nodes in the initial syntax parse tree, mapping at least two initial nodes that match the node relationships will help increase the number of candidate query syntax components for each initial node. In this way, the component feedback information of the target object based on the candidate query syntax components will better express the query intent of the target object. Please refer to the following embodiment for details.

[0107] Node relationships include parent-child relationships and parallel relationships. Node relationships can also include inclusion relationships and non-inclusion relationships. A parent-child relationship indicates that there is a parent-child relationship between the initial nodes. A parallel relationship indicates that there is a parallel relationship between the initial nodes. An inclusion relationship indicates that there is an inclusion relationship between the initial nodes. For example, in the sentence "I applied for Class A and Class B car insurance," "I" and "applied for" have a parent-child relationship; "applied for" and "car insurance" have a parent-child relationship; "car insurance" and "Class A insurance" have a parent-child relationship; and "car insurance" and "Class B insurance" have a parent-child relationship. "Class A car insurance" and "Class B insurance" have a parallel relationship. Within this, "car insurance" and "Class A insurance" have an inclusion relationship, and "car insurance" and "Class B insurance" also have an inclusion relationship.

[0108] In some embodiments, a syntax component mapping table is determined based on a database; the node category of the initial node is extracted to obtain a first node category; the node relationships between the initial nodes are extracted from the initial syntax parse tree to obtain initial relationships; wherein, the initial relationships include parent-child relationships, parallel relationships, and inclusion relationships; and the syntax mapping result of each initial node is obtained from the syntax component mapping table based on the first node category and the initial relationships. More specifically, for each initial node, at least one candidate syntax component of the initial node and at least one candidate syntax component of nodes that conform to the initial relationship with the initial node are aggregated to obtain the syntax mapping result of the initial node. In this embodiment, the candidate query syntax components of the initial node and other nodes that have node relationships with the initial node are aggregated as the syntax mapping result of the initial node. It can be understood that the syntax mapping result includes at least two candidate query syntax components so that the target object can provide component feedback information that better reflects the query intent. The target syntax parse tree will better express the query intent of the target object, which helps to improve the accuracy of the target syntax parse tree.

[0109] Please see Figure 4 In some other embodiments, step S103 may include, but is not limited to, steps S401 to S404:

[0110] Step S401: Determine the syntax component mapping table based on the database;

[0111] Step S402: Extract the node category of the initial node to obtain the first node category;

[0112] Step S403: Extract the node relationships between initial nodes from the initial syntax parse tree to obtain the initial relationships; wherein, the initial relationships are used to indicate that there are containment relationships between the initial nodes;

[0113] Step S404: Obtain the syntax mapping result of each initial node from the syntax component mapping table according to the first node category and the initial relationship.

[0114] In steps S401 to S404 of this embodiment, the node relationships include inclusion relationships and non-inclusion relationships. The initial relationship in this embodiment indicates that there is an inclusion relationship between initial nodes. At least one candidate query syntax component can be obtained from the syntax component mapping table according to the first category. At least one candidate query syntax component of a parent node with an initial relationship to the initial node, or at least one candidate query syntax component of a parent node with an initial relationship to the initial node, can also be obtained according to the initial relationship. The obtained at least two candidate query syntax components are aggregated to obtain the syntax mapping result for each initial node.

[0115] Please see Figure 5 In some embodiments, step S404 may include, but is not limited to, steps S501 to S502:

[0116] Step S501: The syntax component mapping table is filtered according to the first node category to obtain at least one candidate syntax component for each initial node.

[0117] Step S502: For each initial node, at least one candidate grammatical component of the initial node, at least one candidate grammatical component of the parent node that conforms to the initial relationship with the initial node, and at least one candidate grammatical component of the child node that conforms to the initial relationship with the initial node are aggregated to obtain the grammatical mapping result of the initial node.

[0118] Steps S501 to S502, as illustrated in the embodiments of this application, can increase the number of candidate query syntax components. By restricting the components to conforming to the initial relationship and to being the parent or child node of the initial node, the query quality of the candidate query syntax components is guaranteed. This reduces the response time of the target object, improving the efficiency and quality of the interaction.

[0119] In step S104 of some embodiments, generally, if the mapping result of the syntax component is the first result, it means that the initial node has only one candidate query syntax component in the database. Therefore, the initial node has only a unique mapping relationship in the database, and there will be no ambiguity. Directly using the candidate query syntax component as the target query syntax component will result in a target syntax parse tree without ambiguity.

[0120] In step S105 of some embodiments, if the grammar component mapping result is the second result, it indicates that the initial node includes at least two candidate query grammar components in the database. This means the initial node includes at least two mapping relationships in the database, which can lead to ambiguity. In related technologies, this ambiguity is generally ignored, and one mapping relationship is automatically selected. However, this selection method increases the ambiguity of the parse tree and ignores the query intent of the target object. Therefore, in this embodiment, whenever the grammar component mapping result is the second result, at least two candidate query grammar components are sent to the target object. Component feedback information from the target object is obtained, and the target parse tree is generated based on the component feedback information. It is understood that by introducing interaction with the target object, the ambiguity caused by the mapping process can be resolved. Furthermore, by interacting with the target object, the query intent of the target object can be further confirmed and explored. This embodiment further improves the accuracy of the target parse tree.

[0121] It should be noted that after step S103, the syntax component mapping result is obtained. If the syntax component mapping result is the first result, step S104 is executed. If the syntax component mapping result is the second result, step S105 is executed. Please refer to [link to relevant documentation]. Figure 6 In other embodiments, if the syntax component mapping result is the second result, then steps S601 to S605 are executed:

[0122] Step S601: If the syntax mapping result is the second result, assemble the initial node according to at least two candidate query syntax components to obtain at least two candidate syntax parse trees;

[0123] Step S602: Translate each candidate parse tree to obtain the initial candidate query statement;

[0124] Step S603: Send at least two initial candidate query statements to the target object;

[0125] Step S604: Obtain statement feedback information of the target object based on at least two initial candidate query statements, and obtain the target candidate query statement based on the statement feedback information;

[0126] Step S605: Filter at least two candidate syntax parse trees according to the target candidate query statement to obtain the target syntax parse tree.

[0127] In steps S601 to S605 of the embodiments of this application, if the syntax mapping result is the second result, it indicates that the initial result mapping has an ambiguity problem. Therefore, a corresponding candidate syntax parse tree is first generated based on at least two candidate query syntax components. The candidate syntax parse tree is translated to obtain the initial candidate query statement. The meanings of at least two initial candidate query statements are different, and the target object can provide statement feedback information. This statement feedback information can determine the target candidate query statement from at least two initial candidate query statements. By interacting with the target object, the ambiguity problem caused by the component mapping process is eliminated, and the accuracy of the target syntax parse tree is improved.

[0128] Understandably, after obtaining the target parse tree, considering the individualized and paradigmatic differences in the question expressions of different target objects, as well as the complexity and ellipsis inherent in natural language, simple parsing and mapping may produce incorrect relationships, and there may be missing nodes or relationships due to the omission of keywords in the question query. Therefore, it is necessary to optimize and update the target parse tree to generate a more accurate target parse tree, thereby improving the ability to handle natural language problems of varying difficulty.

[0129] Please see Figure 7 In some embodiments, the target syntax parse tree includes at least two target nodes, and each target node includes target child nodes. Before step S106, the query statement generation method based on the syntax parse tree in this application embodiment further includes updating the target syntax parse tree. Specifically, this includes steps S701 to S706:

[0130] Step S701: Traverse the target nodes of the target syntax parse tree, extract the node categories of the target nodes, and obtain the second node category;

[0131] Step S702: If the second node category belongs to the preset computing node type, then at least one child node to be added is generated.

[0132] Step S703: Based on the target syntax parse tree, the target node and target child node are assembled into sentences to obtain the original sentence;

[0133] Step S704: Assemble the target node, target child node, and child node to be added into a sentence to obtain the target statement;

[0134] Step S705: Calculate the similarity between the original sentence and the target sentence to obtain the sentence similarity.

[0135] Step S706: If the sentence similarity is greater than the preset similarity threshold, the child node to be added is used as a new child node of the target node, and the target syntax parse tree is updated according to the new child node.

[0136] Steps S701 to S706 of this embodiment, referring to Table 1, show that the second node category includes value nodes, computational function nodes, and metric nodes. Among these, computational function nodes belong to the computational node type. In the computational node type, query statements often omit some content, resulting in missing nodes in the target parse tree. For example, the query statement is "I have more papers than yours," omitting "the number of" and abbreviating "yourpapers" to "yours." The target node "more" is identified as belonging to the computational node type. The target node "than" is also identified as belonging to the computational node type. The target node "more" is expanded using a part-of-speech tagging tool (e.g., NLTK) to obtain the omitted text, and at least one child node to be added is generated based on the omitted text. Then, the sentence similarity between the original statement and the target statement is calculated. The higher the sentence similarity value, the more similar they are. If the sentence similarity is greater than the similarity threshold (0.8), the child node to be added is added to the target parse tree, thus updating the target parse tree. If the sentence similarity is less than or equal to the similarity threshold (0.8), the child node to be added is deleted, and the target syntax parse tree is not updated.

[0137] Please see Figure 8 This application also provides a query statement generation apparatus based on a syntax parse tree, which can implement the above-described query statement generation method based on a syntax parse tree. Figure 8The block diagram of the module structure of the query statement generation device based on the syntax parse tree provided in this application embodiment includes: a question query statement receiving module 801, an initial syntax parse tree generation module 802, a query syntax component mapping module 803, a first syntax parse tree generation module 804, a second syntax parse tree generation module 805, and a target query statement generation module 806. The question query statement receiving module 801 is used to receive a question query statement sent by a target object; wherein the question query statement includes an SQL statement; the initial syntax parse tree generation module 802 is used to generate an initial syntax parse tree based on the question query statement; wherein the initial syntax parse tree includes at least two initial nodes; the query syntax component mapping module 803 is used to extract mapping relationships from a preset database based on each initial node to obtain a syntax mapping result for each initial node; wherein the syntax mapping result includes a first result or a second result, the first result indicating that the initial node includes one candidate query syntax component, and the second result indicating that the initial node includes at least two candidate query syntax components; the first syntax parse tree generation module 804 is used to generate a target query statement. If the syntax mapping result is the first result, the candidate query syntax components are used as the target query syntax components. The initial nodes are assembled based on the target query syntax components to obtain the target syntax parse tree. If the syntax mapping result is the second result, the second syntax parse tree generation module 805 is used to send at least two candidate query syntax components to the target object based on the second result, and obtain the component feedback information from the target object based on the at least two candidate query syntax components. The target query syntax components are obtained based on the component feedback information. The initial nodes are assembled based on the target query syntax components to obtain the target syntax parse tree. The target query statement generation module 806 is used to translate the target syntax parse tree to obtain the target query statement. The target query statement includes an SQL statement.

[0138] It should be noted that the specific implementation of the query statement generation device based on the syntax parse tree is basically the same as the specific implementation of the query statement generation method based on the syntax parse tree described above, and will not be repeated here.

[0139] This application also provides an electronic device, which includes: a memory, a processor, a program stored in the memory and executable on the processor, and a data bus for communication between the processor and the memory. When the program is executed by the processor, it implements the above-described query statement generation method based on a syntax tree. This electronic device can be any smart terminal, including tablet computers, in-vehicle computers, etc.

[0140] Please see Figure 9 , Figure 9 The hardware structure of an electronic device according to another embodiment is illustrated. The electronic device includes:

[0141] The processor 901 can be implemented using a general-purpose CPU (Central Processing Unit), microprocessor, application-specific integrated circuit (ASIC), or one or more integrated circuits, and is used to execute relevant programs to implement the technical solutions provided in the embodiments of this application.

[0142] The memory 902 can be implemented as a read-only memory (ROM), static storage device, dynamic storage device, or random access memory (RAM). The memory 902 can store the operating system and other application programs. When the technical solutions provided in the embodiments of this specification are implemented through software or firmware, the relevant program code is stored in the memory 902 and is called and executed by the processor 901 using the query statement generation method based on the syntax parsing tree of this application embodiment.

[0143] The input / output interface 903 is used to implement information input and output;

[0144] The communication interface 904 is used to enable communication and interaction between this device and other devices. Communication can be achieved through wired means (such as USB, Ethernet cable, etc.) or wireless means (such as mobile network, WIFI, Bluetooth, etc.).

[0145] Bus 905 transmits information between various components of the device (e.g., processor 901, memory 902, input / output interface 903, and communication interface 904);

[0146] The processor 901, memory 902, input / output interface 903, and communication interface 904 are connected to each other within the device via bus 905.

[0147] This application embodiment also provides a storage medium, which is a computer-readable storage medium for computer-readable storage. The storage medium stores one or more programs, which can be executed by one or more processors to implement the above-described query statement generation method based on syntax parse tree.

[0148] Memory, as a non-transitory computer-readable storage medium, can be used to store non-transitory software programs and non-transitory computer-executable programs. Furthermore, memory may include high-speed random access memory, and may also include non-transitory memory, such as at least one disk storage device, flash memory device, or other non-transitory solid-state storage device. In some embodiments, memory may optionally include memory remotely located relative to the processor, and these remote memories can be connected to the processor via a network. Examples of such networks include, but are not limited to, the Internet, intranets, local area networks, mobile communication networks, and combinations thereof.

[0149] The query statement generation method, apparatus, electronic device, and storage medium based on a parse tree provided in this application improve query statement generation efficiency by converting the query statement into an initial parse tree. Mapping the initial parse tree to a database yields an initial parse tree conforming to the database schema. To reduce ambiguity in the initial parse tree, this embodiment sends candidate query syntax components generated through mapping to the target object. The aim is to obtain the target query syntax component through interaction with the target object. Based on the target query syntax component, a target parse tree is generated, and finally, the target query statement is obtained from the target parse tree. This resolves ambiguity and reveals the target object's query intent. In summary, this application embodiment improves the accuracy of the target query statement.

[0150] The embodiments described in this application are for the purpose of more clearly illustrating the technical solutions of the embodiments of this application, and do not constitute a limitation on the technical solutions provided by the embodiments of this application. As those skilled in the art will know, with the evolution of technology and the emergence of new application scenarios, the technical solutions provided by the embodiments of this application are also applicable to similar technical problems.

[0151] It will be understood by those skilled in the art that Figure 1-7 The technical solutions shown do not constitute a limitation on the embodiments of this application, and may include more or fewer steps than shown, or combine certain steps, or different steps.

[0152] The device embodiments described above are merely illustrative. The units described as separate components may or may not be physically separate; that is, they may be located in one place or distributed across multiple network units. Some or all of the modules can be selected to achieve the purpose of this embodiment according to actual needs.

[0153] Those skilled in the art will understand that all or some of the steps in the methods disclosed above, as well as the functional modules / units in the systems and devices, can be implemented as software, firmware, hardware, or suitable combinations thereof.

[0154] The terms “first,” “second,” “third,” “fourth,” etc. (if present) in the specification and accompanying drawings of this application are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such data can be interchanged where appropriate so that the embodiments of this application described herein can be implemented in orders other than those illustrated or described herein. Furthermore, the terms “comprising” and “having,” and any variations thereof, are intended to cover non-exclusive inclusion; for example, a process, method, system, product, or apparatus that comprises a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units not explicitly listed or inherent to such processes, methods, products, or apparatus.

[0155] It should be understood that in this application, "at least one (item)" means one or more, and "more than" means two or more. "And / or" is used to describe the relationship between related objects, indicating that three relationships can exist. For example, "A and / or B" can represent three cases: only A exists, only B exists, and both A and B exist simultaneously, where A and B can be singular or plural. The character " / " generally indicates that the preceding and following related objects are in an "or" relationship. "At least one (item) of the following" or similar expressions refer to any combination of these items, including any combination of single or plural items. For example, at least one (item) of a, b, or c can represent: a, b, c, "a and b", "a and c", "b and c", or "a and b and c", where a, b, and c can be single or multiple.

[0156] In the several embodiments provided in this application, it should be understood that the disclosed apparatus and methods can be implemented in other ways. For example, the apparatus embodiments described above are merely illustrative; for instance, the division of units is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the coupling or direct coupling or communication connection shown or discussed may be through some interfaces; the indirect coupling or communication connection between apparatuses or units may be electrical, mechanical, or other forms.

[0157] The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of this embodiment according to actual needs.

[0158] Furthermore, the functional units in the various embodiments of this application can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or as a software functional unit.

[0159] If the integrated unit is implemented as a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, or all or part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes multiple instructions to cause an electronic device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of this application. The aforementioned storage medium includes various media capable of storing programs, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.

[0160] The preferred embodiments of the present application have been described above with reference to the accompanying drawings, but this does not limit the scope of the claims of the present application. Any modifications, equivalent substitutions, and improvements made by those skilled in the art without departing from the scope and substance of the embodiments of the present application shall be within the scope of the claims of the present application.

Claims

1. A query statement generation method based on a syntax parse tree, characterized in that, The method includes: Receive a query statement sent by the target object; wherein the query statement includes an SQL statement; An initial syntax parse tree is generated based on the query statement; wherein the initial syntax parse tree includes at least two initial nodes; The process involves extracting mapping relationships from a preset database for each initial node to obtain a syntax mapping result for each initial node. This includes: determining a syntax component mapping table based on the database, where the syntax component mapping table includes mapping relationships between node categories and syntax components; extracting the node category of the initial node to obtain an initial node category; and obtaining a syntax mapping result for each initial node from the syntax component mapping table based on the initial node category. The syntax mapping result includes a first result or a second result, where the first result indicates that the initial node includes one candidate query syntax component, and the second result indicates that the initial node includes at least two candidate query syntax components. If the syntax mapping result is the first result, the candidate query syntax component is used as the target query syntax component, and the initial node is assembled according to the target query syntax component to obtain the target syntax parse tree; If the syntax mapping result is the second result, the at least two candidate query syntax components are sent to the target object according to the second result, and the component feedback information fed back by the target object according to the at least two candidate query syntax components is obtained. The target query syntax component is obtained according to the component feedback information, and the initial node is assembled according to the target query syntax component to obtain the target syntax parse tree. The target syntax parse tree is translated to obtain the target query statement; wherein, the target query statement includes an SQL statement.

2. The method according to claim 1, characterized in that, After obtaining the syntax mapping result for each initial node, the method further includes: If the syntax mapping result is the second result, the initial node is assembled according to at least two candidate query syntax components to obtain at least two candidate syntax parse trees; Each candidate parse tree is translated to obtain the initial candidate query statement; Send at least two of the initial candidate query statements to the target object; Obtain statement feedback information of the target object based on at least two initial candidate query statements, and obtain the target candidate query statement based on the statement feedback information; Based on the target candidate query statement, at least two candidate parse trees are filtered to obtain the target parse tree.

3. The method according to claim 1, characterized in that, The step of extracting mapping relationships from a preset database based on each initial node to obtain the syntax mapping result of each initial node further includes: Extract the node category of the initial node to obtain the first node category; The node relationships between the initial nodes are extracted from the initial parsing tree to obtain initial relationships; wherein, the initial relationships are used to indicate that there is an inclusion relationship between the initial nodes; The syntax mapping result of each initial node is obtained from the syntax component mapping table based on the first node category and the initial relationship.

4. The method according to claim 3, characterized in that, The step of obtaining the syntax mapping result of each initial node from the syntax component mapping table according to the first node category and the initial relationship includes: The grammar component mapping table is filtered according to the first node category to obtain at least one candidate grammar component for each initial node. For each initial node, at least one candidate grammar component of the initial node, at least one candidate grammar component of the parent node that conforms to the initial relationship with the initial node, and at least one candidate grammar component of the child node that conforms to the initial relationship with the initial node are aggregated to obtain the grammar mapping result of the initial node.

5. The method according to any one of claims 1 to 4, characterized in that, The target syntax parse tree includes at least two target nodes, each target node including target child nodes. Before translating the target syntax parse tree to obtain the target query statement, the method further includes: The target syntax parse tree is updated; specifically, this includes: Traverse the target nodes of the target syntax parse tree, extract the node categories of the target nodes, and obtain the second node category; If the second node category belongs to a preset computing node type, then at least one child node to be added is generated; Based on the target syntax parse tree, the target node and the target child node are assembled into a sentence to obtain the original sentence; The target node, the target child node, and the child node to be added are assembled into a sentence to obtain the target statement; The similarity between the original statement and the target statement is calculated to obtain the sentence similarity. If the sentence similarity is greater than a preset similarity threshold, the child node to be added is used as a new child node of the target node, and the target syntax parse tree is updated according to the new child node.

6. The method according to any one of claims 1 to 4, characterized in that, The step of generating an initial syntax parse tree based on the query statement includes: The query statement is subjected to part-of-speech tagging to obtain a part-of-speech tagging sequence; wherein, the part-of-speech tagging sequence includes at least two word segments and the part-of-speech tagging of each word segment; Determine the inclusion relationship between the word segments based on their parts of speech; The word segmentation order is extracted from the part-of-speech tagging sequence. Based on the word segmentation order, the word segments whose part of speech belongs to subject, predicate, and object are taken as the main word segments. Among them, the remaining word segments other than the main word segments are the additional word segments. Based on each of the main word segments, a main node is created, and the main nodes are assembled according to a preset grammatical order to obtain a main syntax parse tree. Based on the inclusion relationship, the additional word segment is determined to be a child node of the main node, and the main syntax parse tree is processed by adding nodes based on the child nodes to obtain the initial syntax parse tree.

7. A query statement generation device based on a syntax parse tree, characterized in that, The device includes: The problem query statement receiving module is used to receive problem query statements sent by the target object; wherein, the problem query statement includes an SQL statement; An initial syntax parse tree generation module is used to generate an initial syntax parse tree based on the question query statement; wherein, the initial syntax parse tree includes at least two initial nodes; The query syntax component mapping module is used to extract mapping relationships from a preset database based on each initial node to obtain a syntax mapping result for each initial node. This includes: determining a syntax component mapping table based on the database, the syntax component mapping table including mapping relationships between node categories and syntax components; extracting the node category of the initial node to obtain an initial node category; and obtaining a syntax mapping result for each initial node from the syntax component mapping table based on the initial node category. The syntax mapping result includes a first result or a second result, where the first result indicates that the initial node includes one candidate query syntax component, and the second result indicates that the initial node includes at least two candidate query syntax components. The first syntax parse tree generation module is used to, if the syntax mapping result is the first result, take the candidate query syntax component as the target query syntax component, assemble the initial node according to the target query syntax component, and obtain the target syntax parse tree; The second syntax parse tree generation module is used to, if the syntax mapping result is the second result, send the at least two candidate query syntax components to the target object according to the second result, obtain the component feedback information fed back by the target object according to the at least two candidate query syntax components, obtain the target query syntax component according to the component feedback information, and assemble the initial node according to the target query syntax component to obtain the target syntax parse tree; The target query statement generation module is used to translate the target syntax parse tree to obtain the target query statement; wherein, the target query statement includes an SQL statement.

8. An electronic device, characterized in that, The electronic device includes a memory and a processor. The memory stores a computer program, and when the processor executes the computer program, it implements the query statement generation method based on the syntax parse tree as described in any one of claims 1 to 6.

9. A computer-readable storage medium storing a computer program, characterized in that, When the computer program is executed by a processor, it implements the query statement generation method based on a syntax parse tree as described in any one of claims 1 to 6.

Citation Information

Patent Citations

  • Data query method and device, electronic equipment and storage medium

    CN113672781A

  • Statement parsing method for database statement

    US20190361899A1