Method, device and medium for converting database query statements into natural language
By identifying intention and semantic roles for natural language text and query escape processing combined with association mapping results, the problem of inaccurate database query statements in the existing technology is solved, and the accuracy of database query statements is improved Spend.
Patent Information
- Application Number
- CN202210743832.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-06-27
- Publication Date
- 2024-11-29
- Estimated Expiration
- 2042-06-27
AI Technical Summary
When the prior art deals with natural language texts with relationships between multiple roles and multiple roles, it is difficult to accurately determine the association mapping results that match the data table fields, resulting in inaccurate database query statements generated.
By querying and understanding natural language text, the intention, semantic role and association mapping results of natural language text are identified, and query escape processing is combined with this information to generate more accurate database query statements.
The accuracy of the generated database query statements is improved, and the accuracy of finding data based on the database query statements is improved.
Smart Images

Figure CN114936271B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to intelligent search technology, and more particularly to a method, device and medium for converting database query statements into natural language. Background Art
[0002] With the outbreak of the big data era, the cost of acquiring data has been greatly reduced, and as the cost of data storage has been further reduced, companies and enterprises will store as much data as possible that is continuously generated in operations and that they believe may be useful. In order to enable non-technical personnel who do not know how to use big data tools to make use of data, data analysis can be achieved by converting natural language into database query statements, thus lowering the threshold for using data.
[0003] At present, when processing natural language text, only the association mapping results that match the key elements in the natural language text with the fields of at least one data table are determined, and then the natural language text is converted into a database query statement through the association mapping results that match the fields of at least one data table. This method is only applicable to the processing of only one role in the natural language text. Then, after assuming that the natural language text has only one role, for more complex natural language texts, such as when there are multiple roles in the natural language text and there are relationships between the multiple roles, the determined association mapping results that match the fields of at least one data table are inaccurate, which in turn leads to inaccurate database query statements converted from the natural language text according to the matched association mapping results. Summary of the invention
[0004] The present application provides a method, device and medium for converting natural language into database query statements, which are used to solve the problem in the prior art that the association mapping result determined to match the field of at least one data table is inaccurate, which in turn leads to inaccurate database query statements converted from natural language text according to the matching association mapping result.
[0005] In a first aspect, an embodiment of the present application provides a method for converting a database query statement from a natural language, comprising:
[0006] Obtaining natural language text to be queried;
[0007] Performing query parsing processing on the natural language text to obtain the elements to be queried of the natural language text;
[0008] Performing query understanding processing on the natural language text according to the elements to be queried to obtain the intent of the natural language text, a semantic role recognition result, and an association mapping result matching a field of at least one data table;
[0009] The natural language text is subjected to query escape processing according to the intention of the natural language text, the semantic role recognition result and the association mapping result matching the field of at least one data table to generate a matching database query statement.
[0010] In a second aspect, an embodiment of the present application provides an electronic device, comprising: a processor, and a memory communicatively connected to the processor;
[0011] Memory stores computer-executable instructions;
[0012] The processor executes the computer-executable instructions stored in the memory to implement the method according to the first aspect.
[0013] In a third aspect, an embodiment of the present application provides a computer-readable storage medium, in which computer-executable instructions are stored. When the computer-executable instructions are executed by a processor, they are used to implement the method of the first aspect.
[0014] The present application provides a method, device and medium for converting natural language into database query statements, which obtains natural language text to be queried; performs query parsing processing on the natural language text to obtain the elements to be queried of the natural language text; performs query understanding processing on the natural language text according to the elements to be queried to obtain the intention of the natural language text, the semantic role recognition result and the associated mapping result matching the field of at least one data table; performs query escape processing on the natural language text according to the intention of the natural language text, the semantic role recognition result and the associated mapping result matching the field of at least one data table to generate a matching database query statement. Because when performing query understanding processing on the natural language text, not only the associated mapping result matching the field of the natural language text and at least one data table is determined, but also the intention of the natural language text is identified and the semantic role is identified. When performing query escape processing on the natural language text, the associated mapping result matching the field of at least one data table is combined with the intention of the natural language text and the relationship between the roles to perform query escape processing on the natural language text, which can more accurately determine the queried data table and field, thereby improving the accuracy of the generated database query statement, and further improving the accuracy of finding data according to the database query statement. BRIEF DESCRIPTION OF THE DRAWINGS
[0015] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present application and, together with the description, serve to explain the principles of the present application.
[0016] Figure 1 A schematic diagram of an application scenario provided for an embodiment of the present application;
[0017] Figure 2A flowchart of a method for converting a natural language into a database query statement provided in Example 1 of the present application;
[0018] Figure 3 A flowchart of a method for converting a natural language into a database query statement provided in Embodiment 3 of the present application;
[0019] Figure 4 A schematic diagram of constructing a role relationship tree provided in an embodiment of the present application;
[0020] Figure 5 A flowchart of a method for converting a natural language into a database query statement provided in Embodiment 4 of the present application;
[0021] Figure 6 A schematic diagram of the structure of an apparatus for converting a database query statement from a natural language provided in Example 6 of the present application;
[0022] Figure 7 This is a schematic diagram of the structure of an electronic device provided in Example 7 of the present application.
[0023] The above drawings have shown clear embodiments of the present application, which will be described in more detail later. These drawings and text descriptions are not intended to limit the scope of the present application in any way, but to illustrate the concept of the present application to those skilled in the art by referring to specific embodiments. DETAILED DESCRIPTION
[0024] Here, exemplary embodiments will be described in detail, and examples thereof are shown in the accompanying drawings. When the following description refers to the accompanying drawings, unless otherwise indicated, the same numbers in different drawings represent the same or similar elements. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with the present application. Instead, they are only examples of devices and methods consistent with some aspects of the present application.
[0025] The terms "first", "second", etc. are used for descriptive purposes only and should not be understood as indicating or implying relative importance or implicitly indicating the number of technical features indicated. In the description of the following embodiments, "multiple" means more than two, unless otherwise clearly and specifically defined.
[0026] In order to clearly understand the technical solution of the present application, the solution of the prior art is first introduced in detail.
[0027] In the prior art, when there is only one role in a natural language text, such as "Zhang San from Hubei", it is easy to determine that Hubei is Zhang San's attribute, and the determined association mapping result that matches the field of at least one data table is relatively accurate. However, in the case of multiple roles and relationships between multiple roles, such as "Li Si, a classmate of Zhang San from Hubei", it is difficult to determine whether Hubei is Zhang San's attribute or Li Si's attribute. Hubei may be determined as Li Si's attribute, and Li Si is searched for in the table or field of Hubei. Therefore, it is difficult to determine an accurate association mapping result that matches the field of at least one data table, resulting in inaccurate database query statements generated by query escape processing of natural language text according to the matching association mapping results, and further resulting in inaccurate data searched according to the database query statements.
[0028] Since it is difficult to accurately determine the association mapping results that match the fields of at least one data table when there are multiple roles and relationships between the multiple roles, the generated database query statement is inaccurate. Therefore, when performing query understanding processing on natural language text, it is not only possible to determine the association mapping results that match the fields of at least one data table, but also to identify the intention of the natural language text and identify the semantic role. The combination of the association mapping results that match the fields of at least one data table, the intention of the natural language text and the identified at least one role can provide an accurate reference basis for the query escape processing of the natural language text. Further, when performing query escape processing on the natural language text, the association mapping results that match the fields of at least one data table are combined with the intention of the natural language text and the relationship between the roles to perform query escape processing on the natural language text, which can more accurately determine the queried data table and field, thereby improving the accuracy of the generated database query statement, and further improving the accuracy of finding data according to the database query statement.
[0029] Figure 1 The following is a schematic diagram of an application scenario provided by an embodiment of the present application, such as Figure 1 As shown, the embodiment of the present application can be applied in the field of campus intelligent search, and the natural language text is the query text related to the application scenario of campus intelligent search. For example, the natural language text can be "Hubei people in the same class as Zhang San". Through the query parsing and query understanding processing of "Hubei people in the same class as Zhang San", it can be determined that the data table to be searched is the class table, and the searched field is the information of students with Hubei household registration in the same class as Zhang San, and a matching database query statement is generated; according to the database query statement, data is searched in the data table, and the found data is displayed, such as Figure 1 As shown in , the headshot, name, student ID number and other information of the students in the same class as Zhang San whose registered residence is in Hubei can be displayed. Figure 1 As shown, the student numbers in the figure are hidden.
[0030] It can be determined that the technical solution of the present application and how the technical solution of the present application solves the above-mentioned technical problems are described in detail below with specific embodiments. The following specific embodiments can be combined with each other, and the same or similar concepts or processes may not be repeated in some embodiments. The embodiments of the present application will be described below in conjunction with the accompanying drawings.
[0031] Embodiment 1
[0032] Figure 2 A flowchart of a method for converting a database query statement from a natural language is provided in the first embodiment of the present application. The embodiment of the present application provides a method for converting a database query statement from a natural language to a database, in order to solve the problem that the association mapping result matched with the field of at least one data table determined by the prior art is inaccurate, which in turn leads to the problem that the database query statement converted from the natural language text according to the matched association mapping result is inaccurate. The execution subject of the method for converting a database query statement from a natural language provided in this embodiment may be a device for converting a database query statement from a natural language. In practical applications, the device for converting a database query statement from a natural language may be implemented by a computer program, such as application software, etc., or by a medium storing a relevant computer program, such as a USB flash drive, a CD, etc., or by a physical device integrated or installed with a relevant computer program, such as a chip, a board, etc.
[0033] In addition, the device for converting the database query statement from natural language can be located in an electronic device. The electronic device can be a digital computer representing various forms, such as a cellular phone, a smart phone, a laptop computer, a desktop computer, a workbench, a personal digital assistant, a server, a blade server, a mainframe computer, and other suitable computers.
[0034] The method for converting a natural language query statement provided in this embodiment includes the following steps:
[0035] Step S101: Obtain the natural language text to be queried.
[0036] In the embodiment of the present application, the natural language text is a text composed of natural language for the purpose of query. Natural language refers to the language that naturally evolves with culture and is the main tool for human communication and thinking.
[0037] Exemplarily, the natural language text input by the user in the input box provided by the device for converting natural language to database query statements can be obtained, the natural language text pre-stored in the database can be obtained, and the voice input by the user can be obtained and converted into natural language text. The embodiments of the present application do not specifically limit this.
[0038] Step S102: perform query parsing processing on the natural language text to obtain the to-be-queried element of the natural language text.
[0039] In the embodiment of the present application, the query parsing process is used to identify the elements to be queried in the natural language text, wherein the elements to be queried include entities, operators, and aggregators in the natural language text.
[0040] In the embodiments of the present application, an entity is a specific person, thing, object, or concept in a natural language text. For example, in the field of news, an entity is the subject of an emergency, such as a person, place, or time; in the field of commodities, an entity can also be a brand word, an item word, or an item attribute word, such as color, material, etc.
[0041] Specifically, query parsing processes such as word segmentation, segmentation, entity recognition, operator recognition, and aggregator recognition can be performed on the natural language text to obtain query elements such as entities, operators, and aggregators determined by the query parsing process.
[0042] The embodiments of the present application do not limit the manner in which query parsing is performed on natural language text. For example, a general parsing model may be used to perform query parsing on natural language text, and at least one entity recognition technology may be used to perform more accurate entity recognition on natural language text before or after the general parsing model performs query parsing on natural language text. The general parsing model is a model that can realize functions such as word segmentation, segmentation, general entity recognition, operator recognition, and aggregator recognition.
[0043] Step S103: performing query understanding processing on the natural language text according to the element to be queried, so as to obtain the intention of the natural language text, a semantic role recognition result, and an association mapping result matching a field of at least one data table.
[0044] In the embodiment of the present application, the query understanding process is used to determine the fields of the data table that need to be queried based on the elements to be queried.
[0045] In the embodiment of the present application, the intent recognition and semantic role recognition can be performed on the natural language text respectively to obtain the intent and semantic role recognition results of the natural language text, and determine the association mapping result that matches the field of at least one data table.
[0046] In the embodiment of the present application, the intent of the natural language text can be obtained through intent recognition, and at least one queried entity of the natural language text can be determined. The semantic role recognition result can be obtained through semantic role recognition, and at least one entity determined as a role in the entity of the element to be queried can be determined, and if there are multiple roles, the relationship between the multiple roles can be determined. The association mapping result matching the field of at least one data table is determined based on the semantic role recognition result through database association recognition technology.
[0047] Exemplarily, the database association identification technology can obtain an association mapping result that matches the field of at least one data table by: pre-configuring a mapping relationship between entities, fields, and the data tables where the fields are located, and determining at least one field of the data table associated with the element to be queried that is an entity based on the mapping relationship between the entity, the data table, and the field; determining the entities and values corresponding to the operators and aggregators in the element to be queried, and determining at least one field of the data table associated with the element to be queried that is an operator or aggregator based on the mapping relationship between the corresponding entities, the data tables, and the fields and the corresponding values.
[0048] Step S104: perform query escape processing on the natural language text according to the intention of the natural language text, the semantic role recognition result, and the association mapping result matching the field of at least one data table to generate a matching database query statement.
[0049] In the embodiment of the present application, the query escape processing is used to generate a database query statement according to the fields of the data table to be queried.
[0050] Specifically, the data table and field to be queried are determined according to the intention of the natural language text, the semantic role recognition results and the matching association mapping results, the natural language text is converted into an abstract syntax tree (AST for short) according to the fields of the queried data table, and the abstract syntax tree corresponding to the natural language text is assembled into a matching database query statement.
[0051] The embodiments of the present application do not limit the method for determining the fields of the queried data table. Exemplarily, the main data table for the query can be determined based on the intention of the natural language text, or the association between entities can be determined through semantic role recognition, combined with determining the queried entity based on the association between entities: the fields of at least one data table that matches the queried entity are determined as the queried data table and fields.
[0052] The embodiments of the present application do not limit the method of converting natural language text into an abstract syntax tree. For example, a pre-set query interface that matches the natural language text can be determined, and the natural language text can be converted into an abstract syntax tree according to the query interface; or a query strategy that consumes the least computing resources or time resources can be determined, and the natural language text can be converted into an abstract syntax tree according to the query strategy.
[0053] The embodiment of the present application does not limit the method of assembling the abstract syntax tree into a matching database query statement. Exemplarily, a compiler may be used to assemble the abstract syntax tree into a matching database query statement.
[0054] The method for converting a natural language into a database query statement provided in an embodiment of the present application obtains a natural language text to be queried; performs query parsing processing on the natural language text to obtain the elements to be queried of the natural language text; performs query understanding processing on the natural language text according to the elements to be queried to obtain the intention of the natural language text, the semantic role recognition result and the associated mapping result matching the field of at least one data table; performs query escape processing on the natural language text according to the intention of the natural language text, the semantic role recognition result and the associated mapping result matching the field of at least one data table to generate a matching database query statement. Because when performing query understanding processing on the natural language text, not only the associated mapping result matching the field of the natural language text and at least one data table is determined, but also the intention of the natural language text is identified and the semantic role is identified. When performing query escape processing on the natural language text, the associated mapping result matching the field of at least one data table is combined with the intention of the natural language text and the relationship between the roles to perform query escape processing on the natural language text, which can more accurately determine the queried data table and field, thereby improving the accuracy of the generated database query statement, and further improving the accuracy of the data searched according to the database query statement.
[0055] Embodiment 2
[0056] On the basis of any of the above embodiments, the embodiment of the present application relates to a refinement of an implementation method of performing query understanding processing on the natural language text according to the element to be queried to obtain the intention of the natural language text, the semantic role recognition result and the association mapping result matching the field of at least one data table, which specifically includes the following steps:
[0057] Step S201: perform intent recognition on the natural language text to obtain an intent recognition result.
[0058] In the embodiment of the present application, a deep learning model for intent recognition can be pre-trained by annotating the intent of the first training sample, and the trained deep learning model for intent recognition can be used to perform intent recognition on natural language text to obtain intent recognition results. The first training sample is a plurality of natural language texts for training the deep learning model for intent recognition.
[0059] Step S202: Perform semantic role recognition on the natural language text according to the element to be queried to obtain a semantic role recognition result.
[0060] In the embodiment of the present application, the role is an individual included in the natural language text, which can be a person or an object.
[0061] The embodiment of the present application does not limit the method of semantic role recognition of natural language text. For example, a deep learning model for semantic role recognition can be pre-trained by marking the roles of the second training sample, and if there are multiple roles, the relationship between the roles can be also marked. The trained deep learning model for semantic role recognition is used to perform semantic role recognition on the natural language text to obtain a semantic role recognition result. The second training sample is a plurality of natural language texts for training the deep learning model for semantic role recognition.
[0062] In the embodiment of the present application, the role in the element to be queried can be determined through the semantic role recognition result, and if there are multiple roles, the relationship between the multiple roles can also be determined. The attribute text under each role can also be determined.
[0063] Step S203: Perform corresponding semantic standardization processing on the texts in the natural language texts that meet the semantic standardization requirements to obtain semantic standardization results.
[0064] In the embodiment of the present application, the text that meets the semantic standardization requirements may be time, address, unit quantifier, and other texts.
[0065] Specifically, it can be determined whether there is text in the natural language text that meets the semantic standardization requirements. If there is text that meets the semantic standardization requirements, the text that meets the semantic standardization requirements is converted into text in a standard format or standard unit.
[0066] For example, the standard format of time can be set to year, month, and day. If there is an entity of type time in the natural language text, such as the last three days, the current date and the date three days ago can be determined, and the last three days can be converted into the standard format of a certain year, month, and day to a certain year, month, and day. The standard unit of the unit quantifier can be set, such as setting the standard unit of length to meter, and the standard format is value + unit. If there is an entity of type unit quantifier in the natural language text, such as 1.8 meters, 1.8 meters can be converted into the text 1.8 meters represented by the standard format. The standard format of the address can be set, such as setting the standard format of the address to a certain city + a certain district + a certain street.
[0067] The embodiments of the present application do not limit the method of converting text that meets the semantic standardization requirements into text in a standard format or standard unit for corresponding semantic standardization processing. For example, the text that meets the semantic standardization requirements can be converted into text in a standard format or standard unit according to pre-configured rules, or the text that meets the semantic standardization requirements can be converted into text in a standard format or standard unit according to a pre-trained standardization model.
[0068] Step S204: determining an association mapping result that matches a field of at least one data table according to the element to be queried, the semantic role recognition result, and the semantic normalization result.
[0069] Specifically, the relationship between the entity determined as the role in the element to be queried and other entities determined as the role, as well as the relationship between the entity determined as the role and the attribute in the natural language text can be determined based on the semantic role identification result; the semantic standardization result and the element to be queried can be mapped to a format aligned with the database to determine the entity-operator relationship, the entity-aggregator relationship, and based on the entity-entity relationship, entity-operator relationship, and entity-aggregator relationship, the query field, aggregation field, aggregation method, query operator, etc. can be further determined to determine the association mapping result that matches the field of at least one data table.
[0070] Among them, the aggregation field is the field corresponding to the aggregation operation, the aggregation method is the aggregation operation method of the aggregation field, and the query operator is the screening condition. For example, taking the natural language text to be queried as "the names of students with average scores greater than 60 points", the query field is the field corresponding to the name, the aggregation field is the field corresponding to the score, the aggregation method is to calculate the average of the scores, the query operator is greater than, and the operation value corresponding to the query operator is 60 points.
[0071] Exemplarily, taking the natural language text to be queried as "the past three days" as an example, through semantic standardization, the past three days are converted into the standard format of a certain year, month, and day to a certain year, month, and day, such as March 1, 2021 to March 3, 2021; the semantic standardization results and the elements to be queried are mapped to a format aligned with the database, such as 21 / 3 / 1 to 21 / 3 / 3, and the query operator is determined to be greater than, and the corresponding operation value is 21 / 3 / 1, and the query operator is less than, and the corresponding operation value is 21 / 3 / 3.
[0072] The method for converting natural language into database query statements provided in the embodiment of the present application performs intent recognition on natural language text to obtain intent recognition results; performs semantic role recognition on natural language text according to the elements to be queried to obtain semantic role recognition results; performs corresponding semantic standardization processing on the text in the natural language text that meets the semantic standardization requirements to obtain semantic standardization results; determines the association mapping results that match the fields of at least one data table according to the elements to be queried, the semantic role recognition results and the semantic standardization results. Through the semantic standardization results, the entities that play a role in the query in the natural language text can be mapped to a unified format, and converted from a unified format to a format that matches the fields of the database, which further facilitates the generation of database query statements. And when determining the fields of the corresponding database, it will not cause errors in the role relationship and cause errors in the association mapping results, thereby improving the accuracy of determining the association mapping results that match the fields of at least one data table.
[0073] Embodiment 3
[0074] Figure 3 A flowchart of a method for converting a natural language into a database query statement provided in Embodiment 3 of the present application. Based on any of the above embodiments, the embodiment of the present application involves a refinement of an implementation method of performing semantic role recognition on a natural language text according to an element to be queried to obtain a semantic role recognition result, such as Figure 3 As shown, the specific steps include:
[0075] Step S301: Use a role sequence labeling model to predict the number of roles in a natural language text, and determine the corresponding role according to the element to be queried.
[0076] Among them, the role sequence labeling model is a deep learning model that determines the number of roles by labeling the role corresponding to each word in the natural language text.
[0077] In an embodiment of the present application, the role sequence labeling model can label the role corresponding to each word in the natural language text. If the corresponding roles are the same, the same character or string is used for labeling. The number of roles in the natural language text can be determined by the number of different characters or strings used for labeling.
[0078] The embodiments of the present application do not limit the method of marking the corresponding role of each character. For example, each character in the natural language text can be marked with a serial number, or each character in the natural language text can be marked with a letter.
[0079] In an optional implementation manner, by marking each character in the natural language text with a corresponding role by marking a serial number, the method for determining the corresponding role according to the element to be queried may include the following steps:
[0080] Step S3011: determine the corresponding entity in the natural query text according to the position of the marked serial number of each role.
[0081] Step S3012: Determine the corresponding entity as the corresponding role.
[0082] Exemplarily, if the position of the marked serial number of a role is the first, second, or fifth position, an entity is obtained from the words corresponding to the first, second, and fifth positions in the natural query text, and the entity is determined as the corresponding role.
[0083] The method for converting natural language into database query statements provided in the embodiment of the present application determines the corresponding entity in the natural query text according to the position of the labeled serial number of each role, and determines the corresponding entity as the corresponding role, so as to quickly determine the role corresponding to each labeled serial number.
[0084] Step S302: If there are multiple roles, an attribute sequence labeling model is used to predict the role attribution of the attribute text in the natural language text according to the number of roles to determine the attribute text under each role.
[0085] In an embodiment of the present application, the role sequence labeling model can label the roles corresponding to the attribute text in the natural language text, and the number of labeled roles is consistent with the number of roles determined in step S301, thereby determining the attribute text under each role based on the labeling of the attribute text.
[0086] In an optional implementation, a specific implementation method of using an attribute sequence labeling model to predict the role attribution of attribute text in a natural language text according to the number of roles to determine the attribute text under each role includes the following steps:
[0087] Step S3021: input the natural language text and the number of roles into the attribute sequence labeling model.
[0088] Step S3022: Use the attribute sequence labeling model to label the role to which each character in the natural language text belongs.
[0089] Step S3023: Obtain the text under the same annotation serial number as the attribute text under the same role.
[0090] In an embodiment of the present application, a method for obtaining text under the same annotation serial number is to obtain text at the same position from natural query text according to the position of the same annotation serial number, and use the obtained text as attribute text under the same role.
[0091] For example, if the natural language text is "the Hangzhou people who took the same train as Zhang San's father", and the number of roles is 3, the result of serial numbering the roles to which each character belongs is "1, 2, 2, 3, 3, 1, 1, 1, 1, 1, 1, 1", where serial number 1 corresponds to role 1, serial number 2 corresponds to role 2, and serial number 3 corresponds to role 3. It is determined that "and", "on the same train", "Hangzhou people" are the attribute texts of role 1, "Zhang San" is the attribute text of role 2, and "father" is the attribute text of role 3.
[0092] The method for converting natural language into database query statements provided in the embodiment of the present application inputs the natural language text and the number of roles into the attribute sequence labeling model, uses the attribute sequence labeling model to label the role to which each word in the natural language text belongs, and obtains the text with the same labeling sequence number as the attribute text under the same role. The attribute text under the same role can be accurately determined, and thus the relationship between the role and the attribute text can be accurately determined.
[0093] Step S303: using a role relationship recognition model to identify the relationship between multiple roles.
[0094] In an embodiment of the present application, relationships between multiple roles can be pre-set, such as kinship relationships, peer relationships, etc., and the role relationship recognition model can determine the relationship between multiple roles based on the pre-set relationships between the multiple roles.
[0095] In an optional implementation, a role relationship identification model is used to identify the relationship between multiple roles. A specific implementation method includes the following steps:
[0096] Step S3031: input the natural language text into the role relationship recognition model.
[0097] Step S3032: Use the role relationship recognition model to identify the relationship between every two adjacent roles.
[0098] Among them, the relationship between every two adjacent roles can be the relationship between corresponding roles with adjacent marked serial numbers. For example, serial number 1 corresponds to role 1, serial number 2 corresponds to role 2, and serial number 3 corresponds to role 3, then the relationship between role 1 and role 2, and the relationship between role 2 and role 3 are determined.
[0099] In the embodiment of the present application, the same natural language text can be used as a row vector and a column vector to input into the role relationship recognition model respectively. The role relationship recognition model traverses each word in the natural language text according to the matrix formed by the row vector and the column vector, and determines the relationship between each element in the row vector and each element in the column vector, that is, the relationship between each word in the natural language text and other words and the relationship between the same two words. If there is a relationship between the two words, the roles corresponding to the two words can be determined, and the relationship between the two roles is the relationship between the two words. The relationship between every two roles can be determined, so the relationship between every two adjacent roles can be determined.
[0100] In the embodiment of the present application, the roles and the relationships between the roles in the third training sample can be annotated in advance, and the role relationship recognition model can be trained based on the third training sample, the roles in the annotated third training sample, and the relationships between the roles. The third training sample is a plurality of natural language texts used to train the role relationship recognition model.
[0101] The method for converting natural language into database query statements provided in the embodiment of the present application inputs natural language text into a role relationship recognition model, and uses the role relationship recognition model to recognize the relationship between each two adjacent roles. The relationship between the two roles can be accurately determined, and further, the relationship between entities can be determined.
[0102] Step S304: construct a role relationship tree according to the relationships between multiple roles and the attribute text under each role to obtain a semantic role recognition result.
[0103] In the embodiment of the present application, the relationship between roles can be used as a root node or child node, and multiple roles can be used as leaf nodes to construct a preliminary role relationship tree, and the attribute text under each role determined in step S302 is mounted on the leaf node corresponding to the preliminary role relationship tree to obtain a complete role relationship tree. Among them, the leaf nodes of the preliminary role relationship tree are roles, and the leaf nodes of the complete role relationship tree are attribute texts.
[0104] In an optional implementation manner, a specific implementation method of constructing a role relationship tree according to the relationship between multiple roles and the attribute text under each role to obtain a semantic role recognition result includes the following steps:
[0105] Step S3041, taking the relationship between the current two roles as the left node of the current layer, the next role in the relationship between the next roles as the right node of the current layer, and the relationship between the next roles as the left node of the previous layer as the basis for iterative construction of the role relationship tree.
[0106] Step S3042: Determine the attribute text under each role as a leaf node of the role relationship tree.
[0107] Specifically, determine whether there is a relationship between the two current roles through the result of step S303. If so, take the two roles as child nodes, and take the relationship between the two roles as the parent node of the child nodes corresponding to the two roles; determine whether there is a relationship between the latter role and any of the two current roles through the result of step S303. If so, take the parent node of the previous step and the latter role as child nodes, and take the relationship between the latter role as the parent node of the previous step and the parent node of the child node corresponding to the latter role, and so on to complete the construction of the preliminary role relationship tree; add the corresponding attribute text under the leaf node of the preliminary role relationship tree to form a new leaf node, and complete the construction of the complete role relationship tree.
[0108] The method for converting database query statements from natural language provided in the embodiment of the present application uses the relationship between the current two roles as the left node of the current layer, the latter role in the relationship between the latter roles as the right node of the current layer, and the relationship between the latter roles as the left node of the previous layer to iteratively construct a role relationship tree, and determines the attribute text under each role as the leaf node of the role relationship tree. The constructed role relationship tree can clearly express the relationship between the various roles. It can also highlight the semantic role recognition results, and determine the attribute text under each role as the leaf node of the role relationship tree, and can also clearly express the attribute text under each role.
[0109] For example, Figure 4 A schematic diagram of constructing a role relationship tree provided in an embodiment of the present application, Figure 4 The corresponding natural language text is "The Hangzhou people who are on the same train with Zhang San's father", which includes three roles, namely role 1, role 2, and role 3. Role 1 corresponds to Zhang San, role 2 corresponds to Zhang San's father, and role 3 corresponds to Hangzhou people. The relationship between role 1 and role 2 is a father-son relationship, and the relationship between role 2 and role 3 is a relationship of being on the same train. If Figure 4 As shown, the current two roles are role 1 and role 2. The parent-child relationship is used as the left node of the current layer, role 3 is used as the right node of the current layer, and the same train relationship is used as the left node of the previous layer to construct a preliminary role relationship tree.
[0110] The method for converting natural language into database query statements provided in an embodiment of the present application adopts a role sequence annotation model to predict the number of roles in a natural language text, and determines the corresponding role according to the element to be queried; if there are multiple roles, an attribute sequence annotation model is adopted to predict the role attribution of the attribute text in the natural language text according to the number of roles, so as to determine the attribute text under each role; a role relationship recognition model is adopted to recognize the relationship between multiple roles; a role relationship tree is constructed according to the relationship between multiple roles and the attribute text under each role, so as to obtain a semantic role recognition result, and the relationship between entities can be determined through the relationship between multiple roles and the attribute text under each role, and the queried data table and field can be accurately determined, thereby improving the accuracy of the database query statement generated according to the semantic role recognition result.
[0111] Embodiment 4
[0112] Figure 5 A flowchart of a method for converting a natural language into a database query statement provided for Embodiment 4 of the present application Based on any of the above embodiments, the embodiment of the present application involves a refinement of an implementation method of using a role sequence annotation model to predict the number of roles in a natural language text in step S301, wherein the role sequence annotation model may include: an explicit role sequence annotation model and an implicit role sequence annotation model, such as Figure 5 As shown, step S301 specifically includes the following steps:
[0113] Step S401: Use an explicit role sequence labeling model to predict the number of explicit roles in a natural language text.
[0114] Among them, explicit roles are roles that are directly reflected in natural language texts.
[0115] In an embodiment of the present application, the explicit role sequence labeling model can label the role corresponding to each word in the natural language text, and the number of explicit roles in the natural language text can be determined by the number of different characters or character strings used for labeling.
[0116] Optionally, a method for predicting the number of explicit roles in a natural language text using an explicit role sequence labeling model includes the following steps:
[0117] Step S4011: input the natural language text into the explicit role sequence labeling model.
[0118] Step S4012: annotate the role of each character in the natural language text with a serial number using an explicit role sequence labeling model.
[0119] Step S4013: Determine the number of explicit roles according to the category of the marked serial number.
[0120] Specifically, an explicit role sequence labeling model is used to label the serial number corresponding to each word in the natural language text, the same serial number is determined as an explicit role, and the number of serial number categories is determined as the number of explicit roles.
[0121] Among them, the explicit role sequence labeling model can be an explicit role sequence labeling model based on BERT.
[0122] In the embodiment of the present application, the training of the explicit role sequence labeling model can be completed by labeling the role corresponding to each character in the fourth training sample. The fourth training sample is a plurality of natural language texts used to train the explicit role sequence labeling model.
[0123] Specifically, the method for training the explicit role sequence labeling model can be: obtaining a fourth training sample and pre-labeling the role corresponding to each character in the fourth training sample; inputting the fourth training sample into the explicit role sequence labeling model, and adjusting the parameters in the explicit role sequence labeling model according to the role corresponding to each character in the output fourth training sample and the role corresponding to each character in the pre-labeled fourth training sample, until the model convergence condition is met, such as when the error is less than a certain value, the training of the explicit role sequence labeling model is completed.
[0124] The method for converting natural language into database query statements provided in the embodiment of the present application inputs the natural language text into the explicit role sequence labeling model; the role to which each character in the natural language text belongs is labeled with a serial number through the explicit role sequence labeling model; and the number of explicit roles is determined according to the category of the labeled serial number. By labeling the role to which each character belongs with a serial number through the explicit role sequence labeling model to determine the number of explicit roles, the complexity of the explicit role sequence labeling model can be reduced compared to labeling the role to which the element to be queried in the natural language text belongs with a serial number after the natural language text and the determined element to be queried are input into the explicit role sequence labeling model, and further, the time for determining the number of explicit roles can be shortened. And because the explicit role sequence labeling model is a deep learning model, the accuracy of labeling the role to which each character in the natural language text belongs can be guaranteed, thereby ensuring the accuracy of the determined number of explicit roles.
[0125] Step S402: Use the implicit role sequence labeling model to predict the number of implicit roles in the natural language text.
[0126] Among them, implicit roles are roles that are not explicitly reflected in natural language texts.
[0127] In the embodiment of the present application, the implicit role sequence labeling model can label the implicit roles between two adjacent words in a natural language text or before or after a natural language text.
[0128] Optionally, a method for predicting the number of implicit roles in a natural language text using an implicit role sequence labeling model includes the following steps:
[0129] Step S4021: input the natural language text into the implicit role sequence labeling model.
[0130] Step S4022: annotate the role to which each character in the natural language text belongs with a serial number through the implicit role sequence labeling model, and annotate the predicted position of the implicit role.
[0131] Step S4023, determining the number of hidden roles according to the role labeling serial number to which each character belongs and the position of the hidden role.
[0132] Specifically, the method for marking the predicted position of the hidden role is: using the hidden role sequence labeling model to mark whether there is a hidden role before or after each word in the natural language text, if there is a hidden role, then the hidden role and the position of the hidden role are marked.
[0133] For example, if a character belongs to explicit role 1, the annotation of explicit role 1 is 1, and there is an implicit role before the character, then the annotation for the character can be 1|before, indicating that there is an implicit role before the character; if there is an implicit role after the character, then the annotation for the character can be 1|after, indicating that there is an implicit role after the character.
[0134] In the embodiment of the present application, when determining the number of hidden roles according to the role labeling serial number to which each character belongs and the position of the hidden role, the position of the hidden role in the natural language text is determined, and the number of labels of the positions of different hidden roles is determined as the number of hidden roles. Among them, the hidden roles at the same position in the natural language text are the same hidden role. For example, there is a hidden role after the third character in the natural language text, and there is a hidden role before the fourth character in the natural language text. These two hidden roles are at the same position in the natural language text and are the same hidden role.
[0135] In the embodiment of the present application, the training of the implicit role sequence labeling model can be completed by labeling the role corresponding to each character in the fifth training sample. The fifth training sample is a plurality of natural language texts used to train the implicit role sequence labeling model.
[0136] Specifically, the implicit role sequence labeling model can be trained by: obtaining a fifth training sample and pre-labeling the position of the implicit role in the fifth training sample; inputting the fifth training sample into the implicit role sequence labeling model, and adjusting the parameters in the implicit role sequence labeling model according to the output position of the implicit role in the fifth training sample until the model convergence condition is reached, such as when the error is less than a certain value, completing the training of the implicit role sequence labeling model.
[0137] The method for converting a natural language into a database query statement provided in an embodiment of the present application inputs a natural language text into a hidden role sequence labeling model, labels the role to which each character in the natural language text belongs by a serial number through the hidden role sequence labeling model, labels the predicted position of the hidden role, and determines the number of hidden roles according to the labeled serial number of the role to which each character belongs and the position of the hidden role. Compared with inputting the natural language text and the determined elements to be queried into the hidden role sequence labeling model to label the position of the hidden role relative to the elements to be queried, the complexity of the hidden role sequence labeling model can be reduced, and further, the time for determining the number of hidden roles can be shortened. And because the hidden role sequence labeling model is a deep learning model, the accuracy of labeling the position of the hidden role in the natural language text can be guaranteed, thereby ensuring the accuracy of the determined number of hidden roles.
[0138] Optionally, after predicting the number of implicit characters in the natural language text using the implicit character sequence labeling model in step S402, the method further includes: verifying the number of implicit characters using a verification algorithm.
[0139] Specifically, if it is determined that there is an implicit character before a word, and the word is not the first word in the natural language text, then it is determined whether there is an implicit character after the word before the word. If so, it is determined that the implicit character exists in the natural language text; if not, it is determined that the implicit character does not exist in the natural language text; if it is determined that there is an implicit character after a word, and the word is not the last word in the natural language text, then it is determined whether there is an implicit character before the word after the word. If so, it is determined that the implicit character exists in the natural language text; if not, it is determined that the implicit character does not exist in the natural language text.
[0140] The method for converting natural language into database query statements provided in the embodiment of the present application uses a verification algorithm to verify the number of implicit roles, which can improve the accuracy of determining the number of implicit roles existing in the natural language text, and further, can improve the accuracy of determining the number of roles.
[0141] Step S403: Determine the sum of the number of explicit roles and the number of implicit roles as the number of roles.
[0142] Specifically, after determining the number of explicit roles and the number of implicit roles, the number of explicit roles and the number of implicit roles are added, and the addition result is determined as the number of roles in the natural language text.
[0143] The method for converting a natural language into a database query statement provided in an embodiment of the present application uses an explicit role sequence labeling model to predict the number of explicit roles in a natural language text; uses an implicit role sequence labeling model to predict the number of implicit roles in a natural language text; and determines the sum of the number of explicit roles and the number of implicit roles as the number of roles. The implicit roles in the natural language text can be fully identified, thereby improving the accuracy of determining the number of roles.
[0144] Embodiment 5
[0145] On the basis of any of the above embodiments, the embodiment of the present application relates to a refinement of an implementation method of step S104, performing query escape processing on the natural language text according to the intention of the natural language text, the semantic role recognition result and the association mapping result matching the field of at least one data table to generate a matching database query statement, specifically including the following steps:
[0146] Step S501: Determine the main data table to be queried according to the intention of the natural language text.
[0147] Step S502: determining a preferred query strategy according to the semantic role recognition result and the association mapping result matching the field of at least one data table.
[0148] Step S503: perform query escape processing on the natural language text according to the preferred query strategy and the main data table to generate a matching abstract syntax tree.
[0149] Step S504: assemble query statements on the abstract syntax tree to generate matching database query statements.
[0150] The preferred query strategy is the query strategy that consumes the least time resources or computing resources for searching data tables and fields.
[0151] Specifically, the main data table to be queried is determined according to the intention of the natural language text, and the data tables and fields to be queried are determined according to the semantic role recognition results and the associated mapping results that match the fields of at least one data table, and the preferred query strategy for the main data table to be queried and the data tables and fields to be queried is determined, a matching abstract syntax tree is generated according to the preferred query strategy, and the abstract syntax tree is assembled into a matching database query statement.
[0152] In the embodiment of the present application, the relationship between roles and the relationship between roles and attribute texts can be determined through the semantic role recognition results. By determining the entities corresponding to the roles and the entities corresponding to the attribute texts, the relationship between entities can be determined, so that the data table and field to be queried can be determined based on the relationship between entities. Exemplarily, the natural language text is "Li Si, a Hubei native who took the same train to Beijing as Zhang San, a Hangzhou native", then being Hubei is an attribute of Li Si, and it can be determined to find Li Si from the data table corresponding to Hubei people, and going to Beijing is also an attribute of Li Si, or Li Si can be found from the travel table with the destination being Beijing.
[0153] The method for converting natural language to database query statements provided in the embodiment of the present application determines the main data table for query according to the intention of natural language text; determines the preferred query strategy according to the semantic role recognition result and the associated mapping result matching the field of at least one data table; performs query escape processing on the natural language text according to the preferred query strategy and the main data table to generate a matching abstract syntax tree; and performs query statement assembly on the abstract syntax tree to generate a matching database query statement. Determining the preferred query strategy in combination with the intention of the natural language text and the semantic role recognition result, and performing query escape processing according to the preferred query strategy can save time resources or computing resources consumed by the query, and can improve the accuracy of the generated database query language, and further improve the accuracy of the data found according to the database query statement.
[0154] Embodiment 6
[0155] Figure 6 A schematic diagram of the structure of the device for converting a database query statement into a natural language provided in Example 6 of the present application, such as Figure 6 As shown, the device 60 for converting a natural language into a database query statement provided in this embodiment includes: an acquisition module 601 , a parsing module 602 , a comprehension module 603 and an escape module 604 .
[0156] The acquisition module 601 is used to acquire the natural language text to be queried.
[0157] The parsing module 602 is used to perform query parsing processing on the natural language text to obtain the to-be-queried element of the natural language text.
[0158] The understanding module 603 is used to perform query understanding processing on the natural language text according to the element to be queried, so as to obtain the intention of the natural language text, the semantic role recognition result and the association mapping result matching the field of at least one data table.
[0159] The escape module 604 is used to perform query escape processing on the natural language text according to the intention of the natural language text, the semantic role recognition result and the association mapping result matching the field of at least one data table, so as to generate a matching database query statement.
[0160] In an optional implementation, the understanding module 603 includes: an intent recognition unit, a role recognition unit, a standardization processing unit, and an association mapping unit; the intent recognition unit is used to: perform intent recognition on natural language text to obtain an intent recognition result; the role recognition unit is used to: perform semantic role recognition on natural language text according to the element to be queried to obtain a semantic role recognition result; the standardization processing unit is used to: perform corresponding semantic standardization processing on the text in the natural language text that meets the semantic standardization requirements to obtain a semantic standardization result; the association mapping unit is used to: determine an association mapping result that matches a field of at least one data table according to the element to be queried, the semantic role recognition result and the semantic standardization result.
[0161] In an optional implementation, the role identification unit is specifically used to: use a role sequence labeling model to predict the number of roles in a natural language text, and determine the corresponding role based on the element to be queried; if there are multiple roles, use an attribute sequence labeling model to predict the role attribution of the attribute text in the natural language text according to the number of roles to determine the attribute text under each role; use a role relationship identification model to identify the relationship between multiple roles; and construct a role relationship tree based on the relationship between multiple roles and the attribute text under each role to obtain a semantic role identification result.
[0162] In an optional implementation, the role identification unit includes: a role determination subunit; the role determination subunit is used to: use an explicit role sequence labeling model to predict the number of explicit roles in a natural language text; use an implicit role sequence labeling model to predict the number of implicit roles in a natural language text; and determine the sum of the number of explicit roles and the number of implicit roles as the number of roles.
[0163] In an optional implementation, the role determination subunit is specifically used to: input the natural language text into the explicit role sequence labeling model; label the role to which each character in the natural language text belongs by the explicit role sequence labeling model; and determine the number of explicit roles according to the category of the labeled serial number.
[0164] In an optional implementation, the role determination subunit is specifically used to: input the natural language text into the implicit role sequence labeling model; label the role to which each character in the natural language text belongs with a serial number through the implicit role sequence labeling model, and label the predicted position of the implicit role; determine the number of implicit roles based on the labeled serial number of the role to which each character belongs and the position of the implicit role.
[0165] In an optional implementation manner, the role determination subunit is further used to: verify the number of implicit roles using a verification algorithm.
[0166] In an optional implementation manner, the role determination subunit is further used to: determine the corresponding entity in the natural query text according to the position of the marked serial number of each role; and determine the corresponding entity as the corresponding role.
[0167] In an optional implementation, the role identification unit includes: an attribute determination subunit; the attribute determination subunit is used to: input the natural language text and the number of roles into an attribute sequence labeling model; use the attribute sequence labeling model to label the role to which each character in the natural language text belongs with a serial number; and obtain the text under the same labeled serial number as the attribute text under the same role.
[0168] In an optional implementation manner, the role identification unit includes: a relationship identification subunit; the relationship identification subunit is used to: input the natural language text into the role relationship identification model; and use the role relationship identification model to identify the relationship between every two adjacent roles.
[0169] In an optional implementation, the role identification unit includes: a relationship tree construction subunit; the relationship tree construction subunit is used to: use the relationship between the current two roles as the left node of the current layer, the subsequent role in the relationship between the subsequent roles as the right node of the current layer, and the relationship between the subsequent roles as the left node of the previous layer as a reference to iteratively construct a role relationship tree; determine the attribute text under each role as a leaf node of the role relationship tree.
[0170] In an optional implementation, the escape module 604 is specifically used to: determine the main data table for query based on the intention of the natural language text; determine the preferred query strategy based on the semantic role recognition result and the associated mapping result matching the field of at least one data table; perform query escape processing on the natural language text according to the preferred query strategy and the main data table to generate a matching abstract syntax tree; and perform query statement assembly on the abstract syntax tree to generate a matching database query statement.
[0171] It should be noted that the technical solutions and effects of the device for converting database query statements from natural language provided in this embodiment can be found in the relevant contents of the aforementioned method embodiments, which will not be repeated here.
[0172] Embodiment 7
[0173] Figure 7 This is a schematic diagram of the structure of an electronic device provided in Embodiment 7 of the present application, such as Figure 7 As shown, the present application also provides an electronic device 70 , including: a memory 701 and a processor 702 .
[0174] The memory 701 is used to store programs. Specifically, the program may include program code, and the program code includes computer execution instructions. The memory 701 may include a high-speed RAM memory, and may also include a non-volatile memory (non-volatile memory), such as at least one disk memory.
[0175] The processor 702 is used to execute the program stored in the memory 701 .
[0176] The computer program is stored in the memory 701 and is configured to be executed by the processor 702 to implement the method for converting a database query statement from a natural language provided in any embodiment of the present application. The relevant description can be understood by referring to the relevant descriptions and effects corresponding to the steps in the accompanying drawings, and no further details are given here.
[0177] In this embodiment, the memory 701 and the processor 702 are connected via a bus. The bus may be an Industry Standard Architecture (ISA) bus, a Peripheral Component Interconnect (PCI) bus, or an Extended Industry Standard Architecture (EISA) bus. The bus may be divided into an address bus, a data bus, a control bus, etc. For ease of representation, Figure 7 Only one thick line is used in the diagram, but this does not mean that there is only one bus or only one type of bus.
[0178] An embodiment of the present application also provides a computer-readable storage medium on which a computer program is stored. The computer program is executed by a processor to implement the method for converting a database query statement from a natural language provided in any embodiment of the present application.
[0179] An embodiment of the present application also provides a computer program product, including a computer program, which, when executed by a processor, implements the method for converting database query statements into natural language provided by any embodiment of the present application.
[0180] In the several embodiments provided in the present application, it should be understood that the disclosed devices and methods can be implemented in other ways. For example, the device embodiments described above are only schematic. For example, the division of modules is only a logical function division. There may be other division methods in actual implementation, such as multiple modules or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of devices or modules, which can be electrical, mechanical or other forms.
[0181] The modules described as separate components may or may not be physically separated, and the components shown as modules may or may not be physical modules, that is, they may be located in one place or distributed on multiple network modules. Some or all of the modules may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0182] In addition, each functional module in each embodiment of the present application can be integrated into one processing module, or each module can exist physically separately, or two or more modules can be integrated into one module. The above integrated modules can be implemented in the form of hardware or in the form of hardware plus software functional modules.
[0183] The program code for implementing the method of the present application can be written in any combination of one or more programming languages. These program codes can be provided to a processor or controller of a general-purpose computer, a special-purpose computer, or other programmable natural language conversion database query statement device, so that the program code, when executed by the processor or controller, enables the functions / operations specified in the flow chart and / or block diagram to be implemented. The program code can be executed entirely on the machine, partially on the machine, partially on the machine as a stand-alone software package and partially on a remote machine, or entirely on a remote machine or server.
[0184] In the context of the present application, a machine-readable medium may be a tangible medium that may contain or store a program for use by or in conjunction with an instruction execution system, device, or equipment. A machine-readable medium may be a machine-readable signal medium or a machine-readable storage medium. A machine-readable medium may include, but is not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, device, or equipment, or any suitable combination of the foregoing. A more specific example of a machine-readable storage medium may include an electrical connection based on one or more lines, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.
[0185] In addition, although each operation is described in a specific order, this should be understood as requiring such operation to be performed in the specific order shown or in a sequential order, or requiring that all illustrated operations should be performed to obtain desired results. Under certain circumstances, multitasking and parallel processing may be advantageous. Similarly, although some specific implementation details are included in the above discussion, these should not be interpreted as limiting the scope of the application. Some features described in the context of a separate embodiment can also be implemented in a single implementation in combination. On the contrary, the various features described in the context of a single implementation can also be implemented in multiple implementations individually or in any suitable sub-combination mode.
[0186] Those skilled in the art will readily appreciate other embodiments of the present application after considering the specification and practicing the invention disclosed herein. The present application is intended to cover any modification, use or adaptation of the present application, which follows the general principles of the present application and includes common knowledge or customary techniques in the art that are not disclosed in the present application. The specification and examples are intended to be exemplary only, and the true scope and spirit of the present application are indicated by the following claims.
[0187] It should be understood that the present application is not limited to the precise structures that have been described above and shown in the drawings, and that various modifications and changes may be made without departing from the scope thereof. The scope of the present application is limited only by the appended claims.
Claims
1. A method for converting a database query statement from a natural language, characterized in that: include: Obtaining natural language text to be queried; Performing query parsing processing on the natural language text to obtain a to-be-queried element of the natural language text; Performing query understanding processing on the natural language text according to the element to be queried to obtain the intent of the natural language text and a semantic role recognition result, and determining an association mapping result matching a field of at least one data table based on the intent of the natural language text and the semantic role recognition result; The semantic role recognition result includes the relationship between multiple roles and the attribute text under each role, wherein the role is a person or object included in the natural language text; query escape processing is performed on the natural language text according to the intention of the natural language text, the semantic role recognition result and the association mapping result matching the field of at least one data table to generate a matching database query statement.
2. The method according to claim 1, characterized in that The query understanding processing is performed on the natural language text according to the element to be queried to obtain the intention of the natural language text and the semantic role recognition result, and the association mapping result matching the field of at least one data table is determined based on the intention of the natural language text and the semantic role recognition result, including: Performing intent recognition on the natural language text to obtain an intent recognition result; Performing semantic role recognition on the natural language text according to the element to be queried to obtain a semantic role recognition result; Performing corresponding semantic standardization processing on the texts in the natural language texts that meet the semantic standardization requirements to obtain semantic standardization results; An association mapping result matching a field of at least one data table is determined according to the element to be queried, the semantic role identification result and the semantic standardization result.
3. The method according to claim 2, characterized in that The performing semantic role recognition on the natural language text according to the element to be queried to obtain a semantic role recognition result includes: Using a role sequence labeling model to predict the number of roles in the natural language text, and determining a corresponding role according to the element to be queried; If there are multiple roles, an attribute sequence labeling model is used to predict the role attribution of the attribute text in the natural language text according to the number of roles, so as to determine the attribute text under each role; Use the role relationship recognition model to identify the relationship between multiple roles; A role relationship tree is constructed based on the relationships between multiple roles and the attribute text under each role to obtain semantic role recognition results.
4. The method according to claim 3, characterized in that The role sequence labeling model includes: an explicit role sequence labeling model and an implicit role sequence labeling model; The step of using a role sequence labeling model to predict the number of roles in the natural language text includes: Predicting the number of explicit characters in the natural language text using an explicit character sequence labeling model; Predicting the number of implicit characters in the natural language text using an implicit character sequence labeling model; The sum of the number of explicit roles and the number of implicit roles is determined as the number of roles.
5. The method according to claim 4, characterized in that The method of using the explicit role sequence labeling model to predict the number of explicit roles in the natural language text includes: Inputting the natural language text into an explicit role sequence labeling model; Using the explicit role sequence labeling model, the role to which each character in the natural language text belongs is labeled with a serial number; The number of explicit roles is determined based on the category of the marked serial number.
6. The method according to claim 5, characterized in that The method of using the implicit role sequence labeling model to predict the number of implicit roles in the natural language text includes: Inputting the natural language text into an implicit role sequence labeling model; Using the implicit role sequence labeling model, the role to which each character in the natural language text belongs is labeled with a serial number, and the position of the predicted implicit role is labeled; The number of the hidden characters is determined according to the character labeling serial number to which each character belongs and the position of the hidden character.
7. The method according to claim 4, characterized in that After predicting the number of implicit roles in the natural language text using the implicit role sequence labeling model, the method further includes: A verification algorithm is used to verify the number of the hidden roles.
8. The method according to claim 6, characterized in that The determining a corresponding role according to the element to be queried includes: Determine the corresponding entity in the natural query text according to the position of the marked serial number of each role; The corresponding entity is determined as the corresponding role.
9. The method according to claim 3, characterized in that: The method of using the attribute sequence labeling model to predict the role attribution of the attribute text in the natural language text according to the number of roles to determine the attribute text under each role includes: Inputting the natural language text and the number of roles into the attribute sequence labeling model; Using the attribute sequence labeling model to label the role to which each word in the natural language text belongs; Get the text under the same annotation sequence number as the attribute text under the same role.
10. The method according to claim 3, characterized in that: The adopting of the role relationship identification model to identify the relationship between multiple roles includes: Inputting the natural language text into a role relationship recognition model; The role relationship recognition model is used to identify the relationship between every two adjacent roles.
11. The method according to claim 10, characterized in that The step of constructing a role relationship tree according to the relationships between multiple roles and the attribute text under each role to obtain a semantic role recognition result includes: The relationship between the current two roles is used as the left node of the current layer, the next role in the relationship between the next roles is used as the right node of the current layer, and the relationship between the next roles is used as the left node of the previous layer as the basis for iterative construction of the role relationship tree; The attribute text under each role is determined as a leaf node of the role relationship tree.
12. The method according to any one of claims 1 to 11, characterized in that: The query escape processing is performed on the natural language text according to the intention of the natural language text, the semantic role recognition result and the association mapping result matching the field of at least one data table to generate a matching database query statement, including: Determine a master data table to be queried according to the intent of the natural language text; Determining a preferred query strategy according to the semantic role recognition result and the association mapping result matching the field of at least one data table; Performing query escape processing on the natural language text according to the preferred query strategy and the main data table to generate a matching abstract syntax tree; The abstract syntax tree is assembled with query statements to generate matching database query statements.
13. An electronic device, characterized in that: include: A processor, and a memory communicatively connected to the processor; The memory stores computer-executable instructions; The processor executes the computer-executable instructions stored in the memory to implement the method according to any one of claims 1 to 12.
14. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer-executable instructions, which are used to implement the method according to any one of claims 1 to 12 when executed by a processor.
Citation Information
Patent Citations
Database query method and device, computer equipment and storage medium
CN114253990A
Method and equipment for escaping meaning from natural language to SQL (Structured Query Language) and storage medium
CN114265858A
