Method, device and medium for converting natural language into database query statements

By combining a general parsing model with multiple entity recognition technologies, the problem of inaccurate entity recognition by the general parsing model is solved, resulting in more accurate database query statement generation, which is suitable for a variety of application scenarios.

CN115098657BActive Publication Date: 2025-11-04ALIBABA CLOUD COMPUTING CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202210743819.1
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-06-27
Publication Date
2025-11-04
Estimated Expiration
2042-06-27

AI Technical Summary

Technical Problem

The general parsing model has low accuracy in identifying entities, resulting in inaccurate database query statements.

Method used

A general parsing model and various entity recognition technologies are used to perform query parsing processing on natural language text. Through query understanding processing, the association mapping results that match the fields of the data table are obtained, and the matching database query statement is generated.

Benefits of technology

It improves the accuracy of entity recognition, thereby improving the accuracy of converted database query statements, and is suitable for different application scenarios.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115098657B_ABST
    Figure CN115098657B_ABST
Patent Text Reader

Abstract

The application provides a method, device and medium for converting a natural language into a database query statement, the method comprising: obtaining a natural language text to be queried; performing query analysis and processing on the natural language text by using a general analysis model and multiple entity recognition technologies to obtain an element to be queried in the natural language text; performing query understanding processing on the natural language text according to the element to be queried to obtain an associated mapping result matched with fields of at least one data table; and performing query conversion processing on the natural language text according to the matched associated mapping result to generate a matched database query statement. Since the entity in the natural language text is recognized by combining the entity recognition technology, the recognition result obtained by using the general analysis model can be adjusted, so that the accuracy of the recognized entity can be improved, and the accuracy of the converted database query statement can be further improved.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present application relates to intelligent search technology, and in particular to a method and device for converting a natural language into a database query statement, and a medium. BACKGROUND

[0002] With the advent of the big data era, the cost of data acquisition has been greatly reduced, and as the cost of data storage is further reduced, companies will store as much data as possible that is continuously produced in the process of operation and that is considered to be useful. In order to enable non-technical personnel who do not use big data query tools to utilize data, data analysis can be achieved by converting a natural language into a database query statement, thereby reducing the threshold for using data.

[0003] At present, a general parsing model is usually used to perform query analysis processing such as word segmentation processing, segmentation processing, general entity recognition processing, operator recognition processing, and aggregation symbol recognition processing on a natural language text. However, the general parsing model has low accuracy in recognizing entities, which may result in inaccurate converted database query statements. SUMMARY

[0004] The present application provides a method and device for converting a natural language into a database query statement, and a medium, to solve the problem of low accuracy in recognizing entities by a general parsing model, which may result in inaccurate converted database query statements.

[0005] In a first aspect, an embodiment of the present application provides a method for converting a natural language into a database query statement, comprising:

[0006] obtaining a natural language text to be queried;

[0007] performing query analysis processing on the natural language text by using a general parsing model and multiple entity recognition technologies, to obtain 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 an associated mapping result matched with fields of at least one data table;

[0009] performing query escaping processing on the natural language text according to the matched associated mapping result, to generate a matched database query statement.

[0010] In a second aspect, an embodiment of the present application provides an electronic device, comprising a processor and a memory in communication connection with the processor;

[0011] the memory stores computer execution instructions;

[0012] the processor executes the computer execution instructions stored in the memory, to implement the method according to the first aspect.

[0013] In a third aspect, the embodiments of the present application provide a computer readable storage medium, the computer readable storage medium stores computer execution instructions, and the computer execution instructions are executed by a processor to implement the method in the first aspect.

[0014] The method, device and medium for converting a natural language into a database query statement are provided. A natural language text to be queried is obtained. A general analysis model and multiple entity recognition technologies are used to perform query analysis processing on the natural language text to obtain an element to be queried of the natural language text. Query understanding processing is performed on the natural language text according to the element to be queried to obtain an associated mapping result matched with a field of at least one data table. Query escaping processing is performed on the natural language text according to the associated mapping result matched to generate a matched database query statement. The general entity recognized by the general analysis model and the labeled data can be adjusted according to the application scenario, the accuracy of the recognized entity can be improved, and the multiple entity recognition technologies can avoid misrecognition and missing recognition, thereby improving the accuracy of the recognized entity. The associated relationship between the element to be queried and the field of the data table is preconfigured, the table and the field to be searched are determined to complete the query understanding processing, the query escaping processing is performed according to the table and the field to be searched to generate the matched database query statement, and therefore, the accuracy of the recognized entity is improved to further improve the accuracy of the converted database query statement. BRIEF DESCRIPTION OF DRAWINGS

[0015] The accompanying drawings, which are incorporated herein and form part of the specification, illustrate embodiments consistent with the present application and, together with the description, further serve to explain the principles of the application.

[0016] Figure 1 An application scenario diagram is provided for the embodiments of the present application.

[0017] Figure 2 A flowchart of a method for converting a natural language into a database query statement is provided for the embodiments of the present application.

[0018] Figure 3 A plurality of query templates are provided for the embodiments of the present application.

[0019] Figure 4 A method flowchart for converting a natural language into a database query statement is provided for the embodiments of the present application.

[0020] Figure 5 A structure diagram of a device for converting a natural language into a database query statement is provided for the seventh embodiment of the present application.

[0021] Figure 6 The structural schematic diagram of the electronic device provided by the embodiment of the present application is shown in the following figure.

[0022] The specific embodiments of the present application have been shown in the above figures, and will be described in more detail hereinafter. These figures and the written description 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

[0023] The exemplary embodiments will be described in detail herein with reference to the accompanying drawings. In the following description, unless otherwise indicated, the same numbers in different drawings represent the same or similar elements. The embodiments described in the following exemplary embodiments are not meant to represent all embodiments consistent with the present application. Rather, they are merely examples of apparatus and methods consistent with some aspects of the present application.

[0024] The terms "first", "second", and the like are used only for descriptive purposes, and are not to be construed as indicating or implying relative importance or a specific number of the technical features indicated. In the description of the following embodiments, the meaning of "a plurality of" is two or more, unless otherwise specifically limited.

[0025] In order to clearly understand the technical solutions of the present application, the prior art solutions are first described in detail.

[0026] Since the accuracy of entity recognition by the general parsing model is low, the converted database query statement is not accurate, so the query parsing processing can be combined with the entity recognition technology to improve the accuracy of entity recognition. Therefore, the present application provides a method for converting a database query statement from natural language, obtaining a natural language text to be queried; using a general parsing model and a plurality of entity recognition technologies to perform 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 to-be-queried element to obtain an associated mapping result matched with a field of at least one data table; and performing query escaping processing on the natural language text according to the matched associated mapping result to generate a matched database query statement. Through the query parsing processing, query understanding processing, and query escaping processing on the natural language text to convert to a database query statement, since the entity recognition technology is combined to recognize the entity in the natural language text, the recognition result using the general parsing model can be adjusted, so that the accuracy of recognizing the entity can be improved, and the accuracy of the converted database query statement can be further improved.

[0027] Figure 1 The application scenario schematic diagram provided by the embodiment of the present application is shown in the following figure. Figure 1As shown, in the application scenario of campus intelligent search, the natural language text might be "third-grade students with the surname Li." Through query parsing and query understanding processing of third-grade students with the surname Li, the search table can be determined to be the student table, with fields for students whose grade is third, whose hometown is Qingdao, and whose first character of their name is Li. A matching database query statement is then generated. Based on the database query statement, data is searched in the data table, and the found data is displayed, such as... Figure 1 As shown, it can display the student's avatar, name, student ID, and other information.

[0028] The technical solution of this application and how the technical solution of this application solves the above-mentioned technical problems are described in detail below with specific embodiments. These specific embodiments can be combined with each other, and the same or similar concepts or processes may not be described again in some embodiments. The embodiments of this application will now be described with reference to the accompanying drawings.

[0029] Example 1

[0030] Figure 2 This document presents a flowchart illustrating a method for converting natural language into database query statements, as provided in this embodiment. This embodiment addresses the problem in existing technologies where retraining the model is required when adding or modifying tables, fields, or query requirements, making it inflexible for different application scenarios. The execution entity of this method can be a device for converting natural language into database query statements. In practical applications, this device can be implemented through a computer program, such as application software, or through a medium storing the relevant computer program, such as a USB flash drive or optical disc. Alternatively, it can be implemented through a physical device integrating or installing the relevant computer program, such as a chip or circuit board.

[0031] Furthermore, the device for converting natural language into database queries can be located in an electronic device. This electronic device can be a digital computer representing various forms, such as cellular phones, smartphones, laptops, desktop computers, workstations, personal digital assistants, servers, blade servers, mainframes, and other suitable computers.

[0032] like Figure 2 As shown, the method for converting natural language into database query statements provided in this embodiment includes the following steps:

[0033] Step S101: Obtain the natural language text to be queried.

[0034] The natural language text is a query-oriented text composed of a natural language. The natural language refers to a language that naturally evolves with culture and is a main tool for human communication and thinking.

[0035] The embodiments of the present application do not limit the manner of obtaining the natural language text. For example, the natural language text input by a user in an input box provided by a device for converting a natural language into a database query statement can be obtained. The natural language text pre-stored in a database can also be obtained. The voice input by a user can also be obtained, and the voice is converted into the natural language text.

[0036] In step S102, a general analysis model and multiple entity recognition technologies are used to perform query analysis processing on the natural language text to obtain the to-be-queried elements of the natural language text.

[0037] In the embodiments of the present application, the query analysis processing is used to identify the to-be-queried elements in the natural language text. The to-be-queried elements include entities, operators, and aggregation symbols in the natural language text.

[0038] The general analysis model can realize functions such as word segmentation, segmentation, general entity recognition, operator recognition, and aggregation symbol recognition. For example, the general analysis model can be a BERT-based NL2SQL model. The entity recognition technology can be used to identify the entities in the natural language text and determine the entity types of the entities.

[0039] In the embodiments of the present application, the entity is a specific person, thing, or concept in the natural language text. For example, in the news field, the entity is the subject of a sudden event, such as a person, a place, or a time. In the commodity field, the entity can also be a brand word, an article word, or an article attribute word, such as a color or a material.

[0040] Specifically, the general analysis model can be used to perform query analysis processing such as word segmentation processing, segmentation processing, general entity recognition processing, operator recognition processing, and aggregation symbol recognition processing on the natural language text, and multiple entity recognition technologies can be used to assist in identifying the entities in the natural language text and determining the entity types of the entities.

[0041] The multiple entity recognition technologies can identify entities that match the application scenario based on an application scenario knowledge graph. The multiple entity recognition technologies can be at least two of a standard entity recognition technology based on a knowledge graph, a regular entity recognition technology based on a regular rule, and a machine learning-based entity recognition technology (such as a BERT-based entity recognition technology). The use of multiple entity recognition technologies can improve the accuracy of identifying entities and avoid misidentification and missed identification.

[0042] In the embodiments of the present application, after the natural language text is processed by the general analysis model, the entity in the natural language text can be identified by using multiple entity recognition techniques to adjust the query analysis processing result obtained by using the general analysis model. For example, if the general analysis model determines that the entity of the natural language text is “A” “middle school”, the multiple entity recognition techniques can merge “A” “middle school” into one entity “A middle school”, where A middle school is the name of a school.

[0043] In step S103, the natural language text is processed by query understanding according to the to-be-queried element to obtain an associated mapping result matched with the fields of the at least one data table.

[0044] In the embodiments of the present application, the query understanding processing is used to determine the fields of the data table that need to be queried according to the to-be-queried element. For example, if the to-be-queried element includes “season” and “fruit”, it is determined according to the to-be-queried element “fruit” that the data table that needs to be queried is the fruit table, and the to-be-queried field is the fruit name; and it is determined according to the to-be-queried element “season” that the aggregation symbol field is the ripening time, and the aggregation value is the current season. For example, the way of processing the natural language text by query understanding according to the to-be-queried element can be: the mapping relationship between the entity and the field and the data table where the field is located can be pre-configured, the field of the at least one data table associated with the to-be-queried element of the entity is determined according to the mapping relationship between the entity and the data table and the field; the entity and the value corresponding to the operator and the aggregation symbol are determined, and the field of the at least one data table associated with the to-be-queried element of the operator and the aggregation symbol is determined according to the mapping relationship between the corresponding entity and the data table and the field and the corresponding value.

[0045] In addition, the query method of the to-be-queried element can also be determined, for example, fuzzy query or accurate query.

[0046] In step S104, the natural language text is processed by query escaping according to the matched associated mapping result to generate a matched database query statement.

[0047] In the embodiments of the present application, the query escaping processing is used to generate a database query statement according to the fields of the data table that need to be queried.

[0048] Specifically, the natural language text is converted into an abstract syntax tree (AST for short) according to the matched associated mapping result, and the abstract syntax tree corresponding to the natural language text is assembled into a matched database query statement.

[0049] The embodiments of the present application do not limit the method of converting the natural language text into the abstract syntax tree. Exemplarily, a preset query interface matching the natural language text can be determined, and the natural language text can be converted into the abstract syntax tree according to the query interface; or a query strategy with the least consumed computing resource or time resource can be determined, and the natural language text can be converted into the abstract syntax tree according to the query strategy.

[0050] The embodiments of the present application do not limit the method of assembling the abstract syntax tree into the matched database query statement, and exemplarily, the compiler can be used to assemble the abstract syntax tree into the matched database query statement.

[0051] The method of converting the natural language into the database query statement provided by the embodiments of the present application includes the following steps: obtaining the natural language text to be queried; performing query analysis processing on the natural language text by using a general analysis model and multiple entity recognition technologies to obtain the query element of the natural language text; performing query understanding processing on the natural language text according to the query element to obtain an associated mapping result matching the field of at least one data table; and performing query escaping processing on the natural language text according to the associated mapping result to generate a matched database query statement. The general analysis model and the multiple entity recognition technologies are used to recognize the entity of the natural language text, the general entity and the labeled data recognized by the general analysis model can be adjusted according to the application scenario, the accuracy of the recognized entity can be improved, and the multiple entity recognition technologies can avoid misrecognition and missed recognition, thereby improving the accuracy of the recognized entity. The associated relationship between the query element and the field of the data table is preconfigured, the table and the field to be searched are determined to complete the query understanding processing, the query escaping processing is performed according to the table and the field to be searched to generate the matched database query statement, and therefore, the accuracy of the converted database query statement can be further improved by improving the accuracy of the recognized entity.

[0052] Embodiment two

[0053] On the basis of any of the above embodiments, the embodiments of the present application relate to a refinement of one implementation manner of step S102, that is, performing query analysis processing on the natural language text by using a general analysis model and multiple entity recognition technologies to obtain the query element of the natural language text, and specifically includes the following steps:

[0054] Step S201, performing entity recognition on the natural language text by using a preposed entity recognition technology.

[0055] In the embodiments of the present application, the preposed entity recognition technology is an entity recognition technology used to recognize the general entity in the natural language text before performing query analysis processing by using the general analysis model. The general entity is an entity that can be contained in each application scenario.

[0056] Specifically, the pre-entity recognition technology is used for entity recognition. If a general entity can be detected, the natural language text is the general entity, the general entity is determined as the query element, and step S103 and subsequent steps are executed. If no general entity in the natural language text is detected, step S201 and subsequent steps are executed to obtain the query element of the natural language text.

[0057] Optionally, the pre-entity recognition technology can include a first regular entity recognition technology and a first standard entity recognition technology. The entity recognition of the natural language text by using the pre-entity recognition technology can include the following steps:

[0058] Step S2011, the first regular entity recognition technology is used to recognize the general unified format entity in the natural language text.

[0059] The first regular entity recognition technology is one of the pre-entity recognition technologies. The first regular entity recognition technology recognizes the general unified format entity through the word formation rule of the general entity.

[0060] In the embodiment of the application, the first regular entity recognition technology can recognize the general unified format entity and type in the natural language text. For example, whether the natural language text is a mobile phone number can be recognized according to the same format of the mobile phone number.

[0061] Step S2012, the first standard entity recognition technology is used to recognize the entity matching the general knowledge graph in the natural language text.

[0062] The first standard entity recognition technology is one of the pre-entity recognition technologies. The first standard entity recognition technology recognizes the general entity in the natural language text through the pre-configured general knowledge graph. The general knowledge graph can include the name of the general entity and the corresponding label data.

[0063] Specifically, the general knowledge graph can be constructed in advance. The general knowledge graph can include the name of the general entity and the corresponding type. Whether the natural language text is an entity matching the general knowledge graph is determined by searching the general knowledge graph. If the natural language text can be found in the general knowledge graph, the entity matching the general knowledge graph is detected and the type of the entity can be determined. If the natural language text cannot be found in the general knowledge graph, no entity matching the general knowledge graph is detected.

[0064] The method provided in the embodiment of the application can identify entities in a general unified format through the first regular entity recognition technology, and can identify entities matched with a general knowledge graph through the first standard entity recognition technology, so that the case that the natural language text is a general entity can be identified before a general analysis model is used, and in this case, the natural language text can be directly determined as the to-be-queried element, without subsequent query analysis processing, and the efficiency of the query analysis processing can be improved.

[0065] In step S202, if it is determined that the preposed entity recognition technology does not detect the entity in the natural language text, the general analysis model is used to perform word segmentation and segmentation processing on the natural language text and identify the to-be-queried element.

[0066] The to-be-queried element at least includes a general entity, an operator, and an aggregation symbol.

[0067] Specifically, the general analysis model can be used to perform word segmentation and segmentation processing on the natural language text, and identify the to-be-queried element in the natural language text and the type of the to-be-queried element.

[0068] In step S203, the postposed entity recognition technology is used to adjust the general entity and the annotation data to obtain an entity matched with the application scenario of the search.

[0069] The annotation data is the identification result corresponding to the general entity. In the embodiment of the application, when multiple entity recognition technologies are used to identify the entity, the type of the entity can be determined, and the identifier corresponding to the type of the entity is determined as the annotation data of the entity. The identifier corresponding to the type of the entity can be a type name or a unique string composed of numbers and letters.

[0070] It should be understood that the method of converting natural language into a database query statement usually relies on a training set, and when a table, a field, or a query requirement is added or modified, the model needs to be retrained, and the method cannot be flexibly applied to different application scenarios.

[0071] In the embodiment of the application, the postposed entity recognition technology is an entity recognition technology used to identify an entity matched with the application scenario of the search in the natural language text after the query analysis processing is performed by using the general analysis model. The entity matched with the application scenario of the search is an entity specific to the application scenario of the search or having a specific meaning.

[0072] Specifically, the post-entity recognition technology is used to recognize the entity matched with the application scenario in the natural language text. If the recognized entity matched with the application scenario is a combination of general entities, the general entities are combined into the entity matched with the application scenario, and the corresponding annotation data is adjusted. If the type of the recognized entity matched with the application scenario is different from the type of the general entity corresponding to the entity, the annotation data corresponding to the entity is adjusted according to the type of the entity matched with the application scenario.

[0073] The method provided by the embodiment of the application adopts the pre-entity recognition technology to perform entity recognition on the natural language text. If it is determined that the pre-entity recognition technology does not detect the entity in the natural language text, the general analysis model is used to perform word segmentation and segmentation processing and recognition of the to-be-queried element on the natural language text. The to-be-queried element at least includes a general entity, an operator and an aggregation symbol. The post-entity recognition technology is used to adjust the general entity and the annotation data, so as to obtain the entity matched with the searched application scenario. The annotation data is the recognition result corresponding to the general entity. The pre-entity recognition technology can recognize the case that the natural language text is a general entity. In this case, the natural language text can be directly determined as the to-be-queried element, without subsequent query analysis processing, so that the efficiency of the query analysis processing can be improved. The general analysis model can recognize the to-be-queried element. The post-entity recognition technology can adjust the general entity and the annotation data according to the application scenario, so that the entity is matched with the searched application scenario, the method can be flexibly applied to different application scenarios, and the accuracy of the recognized entity can be further improved.

[0074] Embodiment three

[0075] On the basis of any of the above embodiments, the embodiment of the application relates to a refinement of one implementation manner of step S203, that is, the post-entity recognition technology is used to adjust the general entity and the annotation data, so as to obtain the entity matched with the searched application scenario. The post-entity recognition technology can include a second regular entity recognition technology, a second standard entity recognition technology and a positioning word entity recognition technology. Step S203 specifically includes the following steps:

[0076] Step S301: The second regular entity recognition technology is used to adjust the general entity, so as to obtain the entity in a unified format matched with the application scenario.

[0077] The second regular entity recognition technology is one of the regular entity recognition technologies in the post-entity recognition technology. The second regular entity recognition technology recognizes the entity in a unified format through the word formation rule of the pre-configured entity matched with the application scenario. For example, in the production scenario, the word formation rule of the serial number can be pre-configured to recognize the entity as the serial number in the natural language text.

[0078] Specifically, the second regular entity recognition is performed on a word or a combination of adjacent words according to the query parsing processing result of the general parsing model by using the second regular entity recognition technology; if a word is recognized as an entity in a uniform format matched with the application scenario, the label data of the entity can be adjusted; if a combination of adjacent words is recognized as an entity in a uniform format matched with the application scenario, the adjacent words can be combined into an entity and the label data of the entity can be determined.

[0079] In step S302, the general entity is adjusted by using the second standard entity recognition technology to obtain an entity matched with the application scenario knowledge graph.

[0080] The second standard entity recognition technology is one of the post-entity recognition technologies. The second standard entity recognition technology identifies an entity matched with the application scenario in the natural language text by using a pre-configured application scenario knowledge graph. The application scenario knowledge graph can include the name of a specific entity in the application scenario and corresponding label data.

[0081] In the embodiment of the application, the specific manner of adjusting the general entity by using the second standard entity recognition technology is similar to the manner of adjusting the general entity by using the second regular entity recognition technology, which will not be described here. For example, the general entity in the natural language text includes an apple and a mobile phone. The entity can be configured as an apple mobile phone in the application scenario knowledge graph, and an entity matched with the application scenario knowledge graph, i.e., an apple mobile phone, can be obtained.

[0082] In step S303, if it is determined that the label data of the general entity includes a pre-configured positioning word, the label data of the target general entity is adjusted by using the positioning word entity recognition technology to obtain label data matched with the database field.

[0083] The target general entity is an entity whose label data includes a pre-configured positioning word. The positioning word is label data corresponding to the general type of the target general entity.

[0084] Specifically, the identifier of the general type corresponding to the entity having a special type in the application scenario can be pre-configured as the positioning word. The positioning word is searched in the label data of the general entity in the natural language text. If it is determined that the label data of the general entity includes a pre-configured positioning word, the general entity is determined as the target general entity, and the label data of the target general entity is adjusted. If the positioning word is not found in the label data of the general entity, there is no target general entity.

[0085] In the embodiments of the present application, the positioning word entity recognition technology can be used to adjust the annotation data of the target general entity to the annotation data matching the database field. For example, the general entity is apple, the general type of September is time, and in some cases, the type of September is birth time. Therefore, the identifier of the positioning word can be configured as time, so as to adjust the annotation data of the entity corresponding to time, i.e., September, to the identifier of the birth time.

[0086] The method provided by the embodiments of the present application adjusts the general entity by using the second regular entity recognition technology to obtain an entity in a unified format matching the application scenario, adjusts the general entity by using the second standard entity recognition technology to obtain an entity matching the knowledge graph of the application scenario, and adjusts the annotation data of the target general entity by using the positioning word entity recognition technology if it is determined that the annotation data of the general entity has a pre-configured positioning word, so as to obtain annotation data matching the database field. The target general entity is an entity whose annotation data is a pre-configured positioning word. The adjustment of the general entity and the annotation data by using the second regular entity recognition technology, the second standard entity recognition technology, and the positioning word entity recognition technology can identify and search the entity matching the application scenario from multiple angles, can improve the accuracy of the identified and searched entity matching the application scenario, and can obtain an entity matching the application scenario by adjusting the general entity, so that the entity is more suitable for the database and the scenario, and the method can be flexibly applied to different application scenarios.

[0087] In an optional implementation, the identifier of the entity type is a type name, that is, the annotation data is a type name. An implementation of adjusting the annotation data of the target general entity by using the positioning word entity recognition technology includes the following steps:

[0088] In step S3031, a pre-configured judgment word matching the application scenario is obtained.

[0089] In step S3032, it is determined whether the target general entity and the judgment word in the natural language text are in the same segment.

[0090] The judgment word is a word used to determine the special type of the target general entity. For example, the positioning word is time, and the judgment word can be configured as birth, death, or departure, arrival, etc. according to the application scenario.

[0091] Specifically, if it is determined that the annotation data of the general entity has a pre-configured positioning word, the judgment word is searched in the natural language text, and it is determined whether the target general entity and the judgment word are in the same segment according to the segmentation result obtained by using the general parsing model.

[0092] The embodiments of the present application do not limit the manner of judging whether the target general entity and the judgment word are in the same segment. For example, the judgment word can be searched in the segment where the target general entity is located, and if the judgment word is found, it is determined that the target general entity and the judgment word are in the same segment. The judgment word can also be searched in the natural language text, and if the judgment word is found, it is further determined whether the found judgment word is in the same segment as the target general entity.

[0093] In step S3033, if it is determined that the target general entity and the judgment word are in the same segment, the annotation data of the target general entity is adjusted to the combined word of the positioning word and the judgment word.

[0094] In the embodiments of the present application, if it is determined that the target general entity and the judgment word are not in the same segment, or the judgment word does not exist in the natural language text, the annotation data of the target general entity is not adjusted. If it is determined that the target general entity and the judgment word are in the same segment, the annotation data of the target general entity that matches the database field is obtained through the combined word of the positioning word and the judgment word.

[0095] For example, the annotation data of the target general entity can be adjusted to the combined word of the positioning word and the judgment word by adding the judgment word at the front end of the annotation data of the target general entity, so as to realize the adjustment of the annotation data of the target general entity to the combined word of the positioning word and the judgment word.

[0096] The method provided by the embodiments of the present application acquires the judgment word that is pre-configured and matches the application scenario, judges whether the target general entity and the judgment word in the natural language text are in the same segment, and adjusts the annotation data of the target general entity to the combined word of the positioning word and the judgment word if it is determined that the target general entity and the judgment word are in the same segment. The type of the target general entity in the application scenario can be determined through the judgment word, and further, the annotation data of the target general entity can be adjusted to the annotation data that matches the database field, so that the method can be flexibly applied to different application scenarios.

[0097] Embodiment Four

[0098] Based on any of the above embodiments, the embodiments of the present application relate to a refinement of one implementation manner of step S104, which performs query escaping processing on the natural language text according to the matched association mapping result to generate a matched database query statement, and specifically includes the following steps:

[0099] In step S401, a plurality of query templates pre-configured are acquired.

[0100] The query template is a template of a natural language query sentence, which is composed of identification data of the to-be-queried element or a name of the to-be-queried element and a connecting word between the to-be-queried elements.

[0101] Exemplarily, the query template can be: {start time}, from, {start address}, to, {end address}, of, [person|personnel]. Wherein, the identification data of the to-be-queried element is in the curly brackets {}, the name of the to-be-queried element is in the square brackets [], and the conjunction between the to-be-queried elements does not use brackets. Person|personnel indicates that the name of the to-be-queried element can be person or personnel.

[0102] In step S402, the parsed result of the natural language text is matched with each query template to obtain a corresponding template matching degree.

[0103] It should be understood that the query parsing processing of the natural language text can determine the identification data of the to-be-queried element. The identification data of the to-be-queried element and the conjunction between the to-be-queried elements in the natural language text can be matched with each query template to obtain a corresponding template matching degree. Wherein, the template matching degree is the similarity between the query template and the natural language text, and the more similar the query template and the natural language text, the higher the template matching degree.

[0104] In addition, the corresponding template matching degree can also be obtained according to the semantics of the natural language text and the semantics of the query template.

[0105] Optionally, the way of matching the parsed result of the natural language text with each query template to obtain a corresponding template matching degree can be: matching the parsed result of the natural language text with the query template according to the arrangement order of the segmented words and semantic matching to determine the template matching degree.

[0106] Specifically, the to-be-queried element of a determinable type in the natural language text is replaced with the corresponding identification data, and the replaced natural language text is matched with the query template. The more the identification data, to-be-queried elements and conjunctions consistent in the query template with the replaced natural language text, and the more similar the arrangement order of the consistent identification data, to-be-queried elements and conjunctions in the query template to the arrangement order in the replaced natural language text, the higher the determined template matching degree.

[0107] The method for converting natural language into database query statements provided by the embodiment of the application matches the parsed result of the natural language text with the query template according to the arrangement order and semantic matching to determine the template matching degree, which combines the arrangement order of the segmented words to determine the template matching degree, and the accuracy of the determined template matching degree is higher than that of the template matching degree determined only by the number of segmented words in the query template matched with the replaced natural language text.

[0108] In step S403, the query template matched with the natural language text is determined according to each template matching degree.

[0109] The embodiments of the present application do not limit the manner of determining the matched query template according to the template matching degree. For example, the query template with the template matching degree exceeding the preset matching degree threshold can be determined as the query template matched with the natural language text, the query templates can be sorted in descending order of the template matching degree, and the first query template can be determined as the query template matched with the natural language text, or the combination of the above two manners.

[0110] In step S404, if it is determined that the matched query template is pre-configured with a query strategy, the pre-configured query strategy is determined as the preferred query strategy.

[0111] Specifically, if it is determined that the matched query template is pre-configured with a query strategy, such as a specified query interface or a filtering rule for a data table or a field, the pre-configured query strategy is determined as the preferred query strategy. After the preferred query strategy is determined, the natural language text is converted into an abstract syntax tree according to the preferred query strategy, and is assembled into a matched database query statement.

[0112] Alternatively, if it is determined that the matched query template is not pre-configured with a query strategy or there is no matched query template, the preferred query strategy is filtered from a plurality of preset general query strategies. The general query strategies at least include a minimum table strategy, an entity table priority strategy, and a parent entity priority strategy. The preferred query strategy filtered from the plurality of preset general query strategies can be a query strategy with the least consumed computing resources or time resources.

[0113] For example, a manner of filtering the preferred query strategy from the plurality of preset general query strategies is to determine the query time of each preset query strategy when querying the natural language text, and determine the query strategy with the shortest query time as the preferred query strategy.

[0114] The method for converting the natural language into a database query statement provided by the embodiments of the present application can generate a matched database query statement according to the preferred query strategy when no matched query strategy is pre-configured, so that the time resources or computing resources can be saved.

[0115] In step 405, the natural language text is subjected to query escaping processing according to the matched association mapping result and the preferred query strategy, so as to generate a matched database query statement.

[0116] Specifically, the data table and the field of the matched association mapping result are converted into an abstract syntax tree according to the preferred query strategy, and the abstract syntax tree corresponding to the natural language text is assembled into a matched database query statement according to the query syntax of the corresponding database engine.

[0117] The method for converting a natural language into a database query statement provided by the embodiments of the present application comprises the following steps: obtaining a plurality of query templates configured in advance; matching the analysis result of the natural language text with each query template to obtain a corresponding template matching degree; determining a query template matched with the natural language text according to each template matching degree; if it is determined that the matched query template is configured with a query strategy in advance, determining the query strategy configured in advance as an optimal query strategy; and performing query escaping processing on the natural language text according to the matched association mapping result and the optimal query strategy to generate a matched database query statement. Whether the matched query strategy is configured in advance can be determined through the query template, and when the matched query strategy is configured in advance, the matched database query statement is generated according to the matched query strategy, so that the individual customization of the query strategy based on the application scenario can be realized; when the matched query strategy is not configured in advance, the matched database query statement can be generated according to the optimal query strategy, so that the time resource or the computing resource can be saved.

[0118] Embodiment five

[0119] On the basis of any of the above embodiments, the embodiments of the present application relate to a refinement of one implementation manner of the step S403 of determining a query template matched with the natural language text according to each template matching degree, which specifically comprises the following steps:

[0120] In step S501, if it is determined that at least one template matching degree is greater than or equal to a preset matching degree threshold, the query template corresponding to the maximum template matching degree is determined as the query template matched with the natural language text.

[0121] In step S502, if it is determined that each template matching degree is less than the preset matching degree threshold, the plurality of query templates satisfying the fusion condition are fused to obtain at least one fused query template, and the query template matched with the natural language text is determined according to the fused query template.

[0122] The query template satisfying the fusion condition is at least a query template comprising the identification data of the to-be-queried element of the natural language text, or the to-be-queried element, or the connecting word between the to-be-queried elements.

[0123] The embodiments of the present application do not limit the manner of fusing the plurality of query templates and the manner of determining the matched query template according to the fused query template. Exemplarily, the template matching degree of each fused query template with the natural language text can be calculated, and the fused query template with the highest template matching degree is determined as the matched query template.

[0124] Optionally, the implementation of determining the query template matched with the natural language text according to the fused query templates comprises: matching the natural language text with the fused query templates to obtain corresponding template matching degrees; and determining the fused query template matched with the natural language text according to the template matching degrees.

[0125] It should be understood that the manner of obtaining the template matching degrees corresponding to the natural language text and the fused query templates is similar to step S402, and the manner of determining the matched fused query template according to the template matching degrees is similar to step S403, which will not be described herein. For example, the fused query template with the template matching degree greater than the matching degree threshold and the greatest template matching degree can be determined as the matched fused query template.

[0126] In the embodiment of the application, after the matched fused query template is determined, the matched database query statement can be generated according to the query strategy corresponding to the fused query template.

[0127] The method for converting the natural language into the database query statement provided by the embodiment of the application can determine the query template corresponding to the greatest template matching degree as the query template matched with the natural language text if it is determined that at least one template matching degree is greater than or equal to the preset matching degree threshold, and can fuse the multiple query templates satisfying the fusion condition to obtain at least one fused query template, and then determine the query template matched with the natural language text according to the fused query template if it is determined that all the template matching degrees are less than the preset matching degree threshold. In this way, the multiple query templates can be fused when none of the query templates can match the natural language text, and the query template with a greater matching degree can be automatically fused from the fused query templates, which can reduce the number of query templates to be configured and improve the configuration efficiency when the method is adapted to different application scenarios.

[0128] Optionally, the implementation of fusing the multiple query templates satisfying the fusion condition to obtain at least one fused query template comprises the following steps:

[0129] Step S5021, establishing an ordered linked list of the query templates satisfying the fusion condition, and numbering the query templates in the ordered linked list according to the order of the word segmentation, and the same word segmentation has the same number.

[0130] Figure 3 The multiple query templates provided by the embodiment of the application are shown in FIG. 1. Figure 3As shown, the natural language text is: Persons with long hair wearing masks who take the train to Qingdao in the past three days. The query elements to be queried of determinable types (in the past three days, Qingdao, wearing masks, long hair) in the natural language text can be replaced with corresponding identification data (start time, end address, facial feature, attribute) to obtain Figure 3 The replaced natural language text in the first row of the second table in Figure 3 . According to the replaced natural language text, the query templates that meet the fusion conditions can be determined as query template 1 and query template 2; remove the query elements to be queried and identification data that are not included in the replaced natural language text in query template 1 and query template 2, so as to establish the replaced natural language text, query template 1 and query template 2 into an ordered linked list as shown in Figure 3 The third table; number the order of appearance of the word segmentation of the replaced natural language text; number the word segmentation in query template 1 and query template 2 according to the numbering of the word segmentation of the replaced natural language text, and the numbering of the same word segmentation is the same. If the word segmentation in query template 1 and query template 2 is not in the replaced natural language text, then number the word segmentation according to the numbering of the word segmentation before and after it. For example, "from" is not in the replaced natural language text, and the numbering of the word segmentation before it is 3 and the numbering of the previous word segmentation is 4, then take the middle number 3.5 of the numbering of the word segmentation before and after it to determine the numbering of "from".

[0131] Step S5022: Merge the ordered linked lists of each query template according to the numbering of the word segmentation to obtain the fused query template.

[0132] Exemplarily, Figure 3 Merge the ordered linked lists of query template 1 and query template 2 in the third table according to the numbering of the word segmentation to obtain Figure 3 The fused query template in the fourth table. Specifically, the word segmentation "facial feature" with a different numbering from query template 1 in query template 2 can be inserted into the ordered linked list of query template 1 in the order of numbering, so as to achieve the merging of query template 1 and query template 2.

[0133] The method for converting natural language to database query statements provided by the embodiments of the present application establishes an ordered linked list of each query template that meets the fusion conditions, numbers in the order of appearance of the word segmentation in the ordered linked list, and the numbering of the same word segmentation is the same; merge the ordered linked lists of each query template according to the numbering of the word segmentation to obtain the fused query template. Through the ordered linked lists of each query template, the ordered linked lists are fused, and the fusion of multiple query templates can be achieved. Further, the fused query template that matches can be determined.

[0134] Embodiment 6

[0135] On the basis of any of the above embodiments, the embodiment of the present application relates to that in step S102, the natural language text is parsed and processed by using a general parsing model and a plurality of entity recognition technologies, before the natural language text is parsed and processed, a method for preprocessing the natural language text can be adopted, and the method specifically comprises: preprocessing the natural language text, the preprocessing comprises: format normalization processing and / or text rewriting processing.

[0136] The format normalization processing can comprise full-half angle conversion, case conversion, punctuation symbol processing, etc. For example, the half-angle symbols in the natural language text can be converted into full-angle symbols by full-half angle conversion, the capital letters in the natural language text can be converted into small letters by case conversion, and the natural language text can be converted into or / and by punctuation symbol processing.

[0137] In addition, the text rewriting processing can be used to rewrite the ambiguous text in the natural language text.

[0138] The method for converting the natural language text into a database query statement provided by the embodiment of the present application can preprocess the natural language text, so as to reduce the difficulty of subsequent query parsing processing and improve the accuracy of determining the query element of the natural language text.

[0139] Optionally, an implementation manner of the text rewriting processing of the natural language text specifically comprises the following steps:

[0140] In step S601, if it is determined that the natural language text comprises the preconfigured ambiguous text, a rewriting strategy of the ambiguous text is acquired.

[0141] In step S602, the ambiguous text is rewritten according to the rewriting strategy, so as to complete the rewriting of the natural language text.

[0142] The rewriting strategy can comprise: rewriting the ambiguous text according to the mapping relationship between the ambiguous text and the rewritten text, rewriting the ambiguous text according to the context or other obtainable information.

[0143] For example, the relationship between "widow" and "married woman, whose husband has died" can be preconfigured, and the "widow" can be rewritten. The rewriting strategy of "the opposite sex" can be preconfigured, and whether the individual in the natural language text is male or female is identified, if the individual is male, the "opposite sex" is rewritten into female, and if the individual is female, the "opposite sex" is rewritten into male. The rewriting strategy of "people from Qing" can be preconfigured, the address of the input natural language text is acquired, if the address is "Qingdao", the "people from Qing" is rewritten into "people from Qingdao", and if the address is "Qinghai", the "people from Qing" is rewritten into "people from Qinghai".

[0144] The method for converting a natural language into a database query statement provided in the embodiments of the present application includes the following steps: if it is determined that the natural language text includes a preconfigured ambiguous text, a rewriting strategy of the ambiguous text is obtained; and the ambiguous text is rewritten according to the rewriting strategy, so as to complete rewriting of the natural language text. The ambiguous text can be rewritten into a text that is easy to recognize and has a definite meaning, which can reduce the difficulty of subsequent query analysis processing and improve the accuracy of determining the query element of the natural language text.

[0145] Figure 4 The method flowchart of the method for converting a natural language into a database query statement provided in the embodiments of the present application is shown in FIG. 1. Figure 4 As shown in FIG. 1, the method flowchart of the method for converting a natural language into a database query statement includes the following steps: the natural language text is preprocessed, and the preprocessing includes full-half angle conversion, case conversion, punctuation symbol processing and text rewriting processing; after the preprocessing is completed, the natural language text is subjected to query analysis processing by using a preposed entity recognition technology, a general analysis model and a postposed entity recognition technology in sequence; after the query analysis processing is completed, the natural language text is subjected to query understanding processing; after the query understanding processing is completed, the query analysis processing is performed, the template matching degrees corresponding to each query template are calculated, the matching query template is determined according to the matching degrees, the query strategy of the matching query template is determined as an optimal query strategy, if none of the query templates matches, the query templates are fused, the optimal query strategy is determined according to the fused query template or the minimum table query strategy, an abstract syntax tree is generated according to the optimal query strategy, and the abstract syntax tree is assembled into a matched database query statement.

[0146] Since various entity recognition technologies can recognize entities based on an application scenario knowledge graph, the entities matching the application scenario of the search can be recognized by using the general analysis model and the various entity recognition technologies; the table and the field to be searched for can be determined to complete the query understanding processing by using the preconfigured association relationship between the query element and the fields of the data table; the query escape processing can be performed according to the table and the field to be searched for to generate the matched database query statement; therefore, the method for converting a natural language into a database query statement can be applied in different scenarios by configuring the application scenario knowledge graph and the association relationship between the query element and the fields of the data table.

[0147] Embodiment Seven

[0148] Figure 5 The structural diagram of the device for converting a natural language into a database query statement provided in the seventh embodiment of the present application is shown in FIG. 2. Figure 5 As shown in FIG. 2, the device 70 for converting a natural language into a database query statement provided in the present embodiment includes an obtaining module 701, an analysis module 702, an understanding module 703 and an escape module 704.

[0149] The obtaining module 701 is configured to obtain a natural language text to be queried.

[0150] The parsing module 702 is configured to perform query parsing processing on the natural language text by using a general parsing model and a plurality of entity recognition technologies, to obtain a to-be-queried element of the natural language text.

[0151] The understanding module 703 is configured to perform query understanding processing on the natural language text according to the to-be-queried element, to obtain a matched association mapping result corresponding to a field of at least one data table.

[0152] The escaping module 704 is configured to perform query escaping processing on the natural language text according to the matched association mapping result, to generate a matched database query statement.

[0153] In an optional implementation, the parsing module 702 is specifically configured to: perform entity recognition on the natural language text by using a preposed entity recognition technology; if it is determined that the preposed entity recognition technology does not detect an entity in the natural language text, perform word segmentation and segmentation processing and identification of the to-be-queried element on the natural language text by using the general parsing model; the to-be-queried element at least includes a general entity, an operator, and an aggregation symbol; and adjust the general entity and labeled data by using a postposed entity recognition technology, to obtain an entity matched with a search application scenario, the labeled data being an identification result corresponding to the general entity.

[0154] In an optional implementation, the preposed entity recognition technology includes a first regular entity recognition technology and a first standard entity recognition technology; and the parsing module 702 includes a preposed entity recognition unit, which is specifically configured to: identify a general unified format entity in the natural language text by using the first regular entity recognition technology; and identify an entity matched with a general knowledge graph in the natural language text by using the first standard entity recognition technology.

[0155] In an optional implementation, the postposed entity recognition technology includes a second regular entity recognition technology, a second standard entity recognition technology, and a positioning word entity recognition technology; and the parsing module 702 includes a postposed entity recognition unit, which is specifically configured to: adjust the general entity and the labeled data by using the postposed entity recognition technology, to obtain an entity matched with a search application scenario, including: adjusting the general entity by using the second regular entity recognition technology, to obtain a unified format entity matched with the application scenario; adjusting the general entity by using the second standard entity recognition technology, to obtain an entity matched with a knowledge graph of the application scenario; and if it is determined that there is a preconfigured positioning word in the labeled data of the general entity, adjusting the labeled data of a target general entity by using the positioning word entity recognition technology, to obtain labeled data matched with a database field; the target general entity is an entity whose labeled data is the preconfigured positioning word.

[0156] In an optional implementation, the post-entity recognition unit is specifically configured to: obtain a judgment word that is pre-configured and matches the application scenario; determine whether the target general entity and the judgment word in the natural language text are in the same segment; and if it is determined that the target general entity and the judgment word are in the same segment, adjust the labeling data of the target general entity to a combination word of the positioning word and the judgment word.

[0157] In an optional implementation, the escape module 704 is specifically configured to: obtain a plurality of query templates that are pre-configured; match the parsed result of the natural language text with each query template to obtain a corresponding template matching degree; determine a query template that matches the natural language text according to each template matching degree; if it is determined that the matched query template is pre-configured with a query strategy, determine the pre-configured query strategy as an optimal query strategy; and perform query escape processing on the natural language text according to the matched association mapping result and the optimal query strategy to generate a matched database query statement.

[0158] In an optional implementation, the escape module 704 includes a matching degree determination unit, which is configured to: match the parsed result of the natural language text with the query templates in the arrangement order and in the semantic matching to determine the template matching degrees.

[0159] In an optional implementation, the escape module 704 includes a matching template determination unit, which is configured to: if it is determined that at least one template matching degree is greater than or equal to a preset matching degree threshold, determine the query template corresponding to the maximum template matching degree as the query template that matches the natural language text; and if it is determined that each template matching degree is less than the preset matching degree threshold, fuse a plurality of query templates that satisfy the fusion condition to obtain at least one fused query template, and determine the query template that matches the natural language text according to the fused query template.

[0160] In an optional implementation, the matching template determination unit is specifically configured to: establish an ordered linked list of each query template that satisfies the fusion condition, number the ordered linked list according to the order of the word segmentation, and the same number for the same word segmentation; and merge the ordered linked list of each query template according to the number of the word segmentation to obtain the fused query template.

[0161] In an optional implementation, the matching template determination unit is further configured to: match the natural language text with the fused query template to obtain a corresponding template matching degree; and determine the fused query template that matches the natural language text according to each template matching degree.

[0162] In an optional implementation, the device 70 for converting a natural language into a database query statement further comprises a preprocessing module; the preprocessing module is configured to preprocess the natural language text, and the preprocessing comprises format normalization processing and / or text rewriting processing.

[0163] In an optional implementation, the preprocessing module is specifically configured to: if it is determined that the natural language text comprises a preconfigured ambiguous meaning text, acquire a rewriting strategy of the ambiguous meaning text; and rewrite the ambiguous meaning text according to the rewriting strategy to complete rewriting of the natural language text.

[0164] It should be noted that the device for converting a natural language into a database query statement provided in this embodiment performs the technical solutions and effects as described in the foregoing method embodiments, which will not be repeated here.

[0165] Embodiment Eight

[0166] Figure 6 As shown in a structural schematic diagram of an electronic device provided in this application, Figure 6 The present application further provides an electronic device 80, comprising a memory 801 and a processor 802.

[0167] The memory 801 is configured to store a program. Specifically, the program can comprise program code, and the program code comprises computer execution instructions. The memory 801 can comprise a high-speed RAM memory, and can also comprise a non-volatile memory such as at least one disk memory.

[0168] The processor 802 is configured to execute the program stored in the memory 801.

[0169] The computer program is stored in the memory 801 and is configured to be executed by the processor 802 to implement the method for converting a natural language into a database query statement provided in any one of the embodiments of the present application. The relevant description and effects corresponding to the steps in the drawings can be understood, and will not be repeated here.

[0170] In this embodiment, the memory 801 and the processor 802 are connected through a bus. The bus can be an Industry Standard Architecture (ISA) bus, a Peripheral Component Interconnect (PCI) bus or an Extended Industry Standard Architecture (EISA) bus, etc. The bus can be divided into an address bus, a data bus and a control bus. For ease of representation,Figure 6 Only one bus or bus type is used in the figure, but it is understood that the communication infrastructure can also include other buses and bridges using any combination of bus types, including optical bus communications, point-to-point communications etc.

[0171] The embodiment of the present application further provides a computer readable storage medium, which stores a computer program, and the computer program is executed by a processor to implement the method for converting a natural language into a database query statement provided by any one of the embodiments of the present application.

[0172] The embodiment of the present application further provides a computer program product, which comprises a computer program, and the computer program is executed by a processor to implement the method for converting a natural language into a database query statement provided by any one of the embodiments of the present application.

[0173] In several embodiments provided in the present application, it should be understood that the disclosed apparatus and method can be implemented by other manners. For example, the apparatus embodiment described above is only schematic, for example, the division of the module is only a logical function division, and actual implementation can have another division manner, for example, a plurality of modules or components can be combined or integrated into another system, or some features can be ignored or not executed. In addition, the coupling or direct coupling or communication connection between the displayed or discussed each other can be indirect coupling or communication connection through some interfaces, apparatuses or modules, and can be electrical, mechanical or other forms.

[0174] The module described as a separate component can or can not be physically separated, and the component displayed as a module can or can not be a physical module, that is, it can be located in one place, or can be distributed to a plurality of network modules. Part or all of the modules can be selected according to actual needs to achieve the purpose of the embodiment scheme.

[0175] In addition, each function module in each embodiment of the present application can be integrated in one processing module, or each module can be physically present alone, or two or more modules can be integrated in one module. The above integrated module can be realized in the form of hardware or in the form of hardware plus software function module.

[0176] The program code for implementing the method of the present application can be written in any combination of one or more programming languages. The program code can be provided to the 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, causes the functions / operations specified in the flowchart and / or block diagram to be implemented. The program code can be executed completely on a machine, partially on a machine, partially on a machine as a separate software package, and partially on a remote machine or server.

[0177] In the context of this application, a machine-readable medium can be a tangible medium that contains or stores a program for use by or in connection with an instruction execution system, apparatus, or device. The machine-readable medium can be a machine-readable signal medium or a machine-readable storage medium. A machine-readable medium can include but is not limited to an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any suitable combination of the foregoing. More specific examples of the machine-readable storage medium would include an electrical connection based on one or more wires, 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 disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.

[0178] Further, although operations are depicted in a particular, sequential order, this should not be understood as requiring or implying that the operations are performed in the order illustrated, or that all illustrated operations are necessary for realizing the desired result. In certain contexts, multitasking and parallel processing can be advantageous. Likewise, the specific sequential order described above need not be adhered to but various features between two or more constituents can be performed in parallel or be carried out in any suitable order. Likewise, although specific implementation details are included in the above discussion, these should not be interpreted as limiting the scope of the application. Certain features described in the context of separate embodiments can also be implemented together in a single embodiment. Conversely, various features described in the context of a single embodiment can also be implemented separately or in any suitable subcombination.

[0179] Other embodiments of the application will be apparent to those skilled in the art from consideration of the specification and practice of the application disclosed herein. It is intended that the application be limited only by the scope of the claims, a properly construed, and it is intended that each definition in the claims be understood to embrace any and all equivalents. The specification and examples are illustrative only, and not intended to be limiting. It is intended that the true scope of the application be defined only by the claims.

[0180] It is to be understood that the application is not limited to the precise construction described and as shown in the attached drawings, and that various modifications and changes can be effected therein by those skilled in the art without departing from the scope of the application. The scope of the application is to be defined by the claims appended hereto.

Claims

1. A method of converting natural language database query statements, characterized by, The method comprises the following steps: acquiring natural language text to be queried; performing entity recognition on the natural language text by using pre- entity recognition technology; if it is determined that the pre-entity recognition technology detects a general entity in the natural language text, determining the general entity as a query element; if it is determined that the pre-entity recognition technology does not detect an entity in the natural language text, performing word segmentation and segmentation processing and query element recognition on the natural language text by using a general analysis model; the query element at least includes a general entity, an operator and an aggregation symbol; and adjusting the general entity and labeled data by using post-entity recognition technology to obtain an entity matched with an application scenario of searching, wherein the labeled data is a recognition result corresponding to the general entity; performing query understanding processing on the natural language text according to the query element to obtain an associated mapping result matched with a field of at least one data table; performing query escaping processing on the natural language text according to the associated mapping result to generate a matched database query statement.

2. The method of claim 1, wherein, The pre-entity recognition technology comprises a first regular entity recognition technology and a first standard entity recognition technology; the entity recognition on the natural language text by using the pre-entity recognition technology comprises: recognizing a general unified format entity in the natural language text by using the first regular entity recognition technology; recognizing an entity matched with a general knowledge graph in the natural language text by using the first standard entity recognition technology.

3. The method of claim 1, wherein, The post-entity recognition technology comprises a second regular entity recognition technology, a second standard entity recognition technology and a positioning word entity recognition technology; the adjustment of the general entity and the labeled data by using the post-entity recognition technology to obtain an entity matched with an application scenario of searching comprises: adjusting the general entity by using the second regular entity recognition technology to obtain a unified format entity matched with the application scenario; adjusting the general entity by using the second standard entity recognition technology to obtain an entity matched with an application scenario knowledge graph; if it is determined that the labeled data of the general entity has a preconfigured positioning word, adjusting the labeled data of a target general entity by using the positioning word entity recognition technology to obtain labeled data matched with a database field, wherein the target general entity is an entity whose labeled data is the preconfigured positioning word.

4. The method of claim 3, wherein, the adjustment of the labeled data of the target general entity by using the positioning word entity recognition technology to obtain the labeled data matched with the database field comprises: acquiring a preconfigured judgment word matched with the application scenario; determining whether the target general entity and the judgment word in the natural language text are in the same segment; if it is determined that the target general entity and the judgment word are in the same segment, adjusting the labeled data of the target general entity to a combination word of the positioning word and the judgment word.

5. The method of claim 1, wherein, the query escaping processing on the natural language text according to the associated mapping result to generate the matched database query statement comprises: acquiring a plurality of preconfigured query templates; matching the parsed result of the natural language text with each query template to obtain a corresponding template matching degree; determining a query template matched with the natural language text according to each template matching degree; if it is determined that the matched query template is pre-configured with a query strategy, determining the pre-configured query strategy as a preferred query strategy; performing query escaping processing on the natural language text according to the matched association mapping result and the preferred query strategy to generate a matched database query statement.

6. The method of claim 5, wherein, The matching of the parsed result of the natural language text with each query template to obtain a corresponding template matching degree comprises: matching the parsed result of the natural language text with the query template according to the arrangement order of the segmented words to determine the template matching degree.

7. The method of claim 5, wherein, The determination of a query template matched with the natural language text according to each template matching degree comprises: if it is determined that at least one template matching degree is greater than or equal to a preset matching degree threshold, determining the query template corresponding to the maximum template matching degree as the query template matched with the natural language text; if it is determined that each template matching degree is less than the preset matching degree threshold, fusing a plurality of query templates satisfying a fusion condition to obtain at least one fused query template, and determining the query template matched with the natural language text according to the fused query template.

8. The method of claim 7, wherein, The fusion of a plurality of query templates satisfying a fusion condition to obtain a fused query template comprises: establishing an ordered linked list of each query template satisfying the fusion condition, numbering in the ordered linked list according to the order of the segmented words, and the same number for the same segmented word; merging the ordered linked list of each query template according to the number of the segmented words to obtain the fused query template.

9. The method of claim 5, wherein, If it is determined that the matched query template is not pre-configured with a query strategy, it further comprises: selecting a preferred query strategy from a plurality of preset general query strategies; The general query strategy at least includes: minimum table strategy, entity table priority strategy, and parent entity priority strategy.

10. The method according to any one of claims 1 to 9, characterized in that, Before the query analysis processing of the natural language text by using the general analysis model and a plurality of entity recognition technologies to obtain the to-be-queried elements of the natural language text, it further comprises: preprocessing the natural language text, wherein the preprocessing comprises format normalization processing and / or text rewriting processing.

11. The method of claim 10, wherein, The text rewriting processing of the natural language text comprises: if it is determined that the natural language text includes a pre-configured ambiguous meaning text, obtaining a rewriting strategy of the ambiguous meaning text; rewriting the ambiguous meaning text according to the rewriting strategy to complete the rewriting of the natural language text.

12. An electronic device, comprising: It comprises: a processor and a memory connected in communication with the processor; the memory stores computer execution instructions; the processor executes the computer execution instructions stored in the memory to realize the method according to any one of claims 1-11.

13. A computer-readable storage medium, characterized in that, The computer readable storage medium stores computer execution instructions, and the computer execution instructions are executed by the processor to realize the method according to any one of claims 1-11.

14. A computer program product comprising a computer program which, when executed by a processor, implements the method according to any one of claims 1-11.

Citation Information

Patent Citations

  • Text processing method and device, electronic equipment and storage medium

    CN113468307A

  • Natural language query processing method and device

    CN114090619A