Method and apparatus for processing query request

By using entity recognition, syntactic analysis, and semantic analysis, natural language text is translated into data query scripts, solving the problem of high barriers to data analysis and achieving instant and highly accurate data query results, making it suitable for self-service data analysis by non-technical personnel.

CN115794857BActive Publication Date: 2026-01-06ALIPAY (HANGZHOU) INFORMATION TECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202211425428.1
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-01-19
Publication Date
2026-01-06
Estimated Expiration
2042-01-19

AI Technical Summary

Technical Problem

Existing technologies for data analysis have high barriers to entry, resulting in low data query efficiency and difficulty in meeting the needs of large and flexible data. Traditional methods require professionals to write scripts, which cannot achieve real-time and accurate data analysis.

Method used

By using entity recognition, syntactic analysis, and semantic analysis, natural language text is gradually translated into data query scripts. These scripts are then used to execute queries, lowering the barrier to data analysis and enabling non-technical personnel to perform self-service analysis.

Benefits of technology

It achieves instant and highly accurate data analysis results, lowers the barrier to data analysis, and enables non-technical personnel to quickly meet complex data needs.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115794857B_ABST
    Figure CN115794857B_ABST
Patent Text Reader

Abstract

The embodiment of the present specification provides a query request processing method, comprising: obtaining a query request for target data, the form of the query request being a natural language text; performing entity recognition on the natural language text to obtain a plurality of words and an entity category corresponding to each word; converting the plurality of words into a plurality of query elements according to the entity category, the plurality of query elements being related to metadata of the target data; obtaining a plurality of element combinations formed based on the plurality of query elements by performing syntax analysis on the plurality of words; performing semantic analysis on the plurality of element combinations to obtain a plurality of query objects; and constructing a data query script based on the plurality of query objects, the data query script being used to execute a query operation on the target data to obtain a query result corresponding to the query request.
Need to check novelty before this filing date? Find Prior Art

Description

[0001] This application is a divisional application of the invention patent application filed on January 19, 2022, with application number 202210058333.4, entitled "Method and apparatus for processing query requests". Technical Field

[0002] This specification relates to the field of data processing technology in one or more embodiments, and in particular to a method and apparatus for processing query requests. Background Technology

[0003] With the advent of the big data era, data analysis technology has been widely used to mine the value of data and maximize its effectiveness, and has become a current research hotspot.

[0004] However, current data analysis has a high barrier to entry, typically requiring professional analysts to write data query scripts, such as Structured Query Language (SQL) scripts, based on data requirements from business personnel. This results in slow data analysis efficiency and significant delays. As the demand for and flexibility of data analysis continue to increase, traditional data analysis processes are increasingly unable to meet the needs of real-world applications.

[0005] Therefore, there is an urgent need for a solution that can effectively lower the threshold for data analysis, enabling users' data needs to be met quickly, conveniently, and accurately. Summary of the Invention

[0006] This specification describes one or more embodiments of a query request processing method and apparatus, which enables real-time data querying by controllably and interpretably translating user query requests in natural language text form into a query programming language, thereby effectively lowering the threshold for data analysis while ensuring the accuracy and timeliness of data analysis results.

[0007] According to a first aspect, a method for processing a query request is provided, comprising: obtaining a query request for target data, wherein the query request is in the form of natural language text; performing entity recognition on the natural language text to obtain multiple word segments and entity categories corresponding to each word segment; converting the multiple word segments into multiple query elements according to the entity categories, wherein the multiple query elements are related to the metadata of the target data; performing syntactic analysis on the multiple word segments to obtain several element combinations formed based on the multiple query elements; performing semantic analysis on the several element combinations to obtain several query objects; and constructing a data query script based on the several query objects to execute a query operation on the target data and obtain query results corresponding to the query request.

[0008] In one embodiment, the natural language text is obtained by converting a user-input speech segment.

[0009] In one embodiment, entity recognition is performed on the natural language text to obtain multiple word segments and entity categories corresponding to each word segment, including: obtaining multiple pre-constructed dictionaries corresponding to multiple entity categories; and obtaining each word segment and its entity category by matching the natural language text with the multiple dictionaries.

[0010] In one embodiment, converting the multiple word segments into multiple query elements according to the entity category includes: for any first word segment, converting it into a first query element based on the conversion rules corresponding to its entity category.

[0011] In a specific embodiment, for any first word segment, based on the conversion rules corresponding to its entity category, it is converted into a first query element, including: if the entity category of the first word segment is a dimension name or a metric unit, then the first query element is formed based on the field name in the target data that matches the first word segment.

[0012] In another specific embodiment, for any first word segment, based on the conversion rules corresponding to its entity category, it is converted into a first query element, including: if the entity category of the first word segment is a dimension value, then based on the field value in the target data that matches the first word segment, the first query element is formed.

[0013] In another specific embodiment, for any first word segment, based on the conversion rules corresponding to its entity category, it is converted into a first query element, including: if the entity category of the first word segment is time, then the first word segment is converted into time data that conforms to a preset format and used as the first query element.

[0014] In another specific embodiment, for any first word segment, based on the conversion rule corresponding to its entity category, it is converted into a first query element, including: if the entity category of the first word segment is a data operator class, then the operator corresponding to the first word segment is determined as the first query element.

[0015] In another specific embodiment, for any first word segment, based on the conversion rules corresponding to its entity category, it is converted into a first query element, including: if the entity category of the first word segment is an intent class, then the function name corresponding to the first word segment is determined as the first query element.

[0016] In one embodiment, by performing syntactic analysis on the multiple word segments to obtain a combination of elements based on the multiple query elements, the method includes: performing syntactic analysis on the multiple word segments to obtain a number of word segmentation phrases; and performing combination processing on the multiple query elements according to the number of word segmentation phrases to obtain the combination of elements.

[0017] In one embodiment, semantic analysis is performed on the combination of several elements to obtain several query objects, including: for any first element combination, processing it into a corresponding query object based on the semantic processing rules corresponding to the entity category it involves.

[0018] In a specific embodiment, for any combination of first elements, based on the semantic processing rules corresponding to the entity categories involved, it is processed into a corresponding first query object, including: if the entity categories involved in the first element combination include a metric unit but do not include an intent class, then obtain the default function name corresponding to the query element corresponding to the metric unit; based on the default function name and the first element combination, form the first query object.

[0019] In one embodiment, constructing a data query script based on the plurality of query objects includes: determining query keywords corresponding to each query object; and forming the data query script based on the query keywords and each query object.

[0020] In a specific embodiment, determining the query keywords corresponding to each query object includes: for each query object, determining the query keywords corresponding to the query object based on the entity categories involved and the pre-established mapping relationship between entity categories and query keywords.

[0021] In one embodiment, after constructing the data query script, the method further includes: using the data query script to perform the query operation on the target data to obtain query content; and generating a corresponding chart based on the query content as the query result.

[0022] According to a second aspect, a query request processing apparatus is provided, comprising: a text acquisition unit configured to acquire a query request for target data, wherein the query request is in the form of natural language text; an entity recognition unit configured to perform entity recognition on the natural language text to obtain multiple word segments and entity categories corresponding to each word segment; a conversion unit configured to convert the multiple word segments into multiple query elements according to the entity categories, wherein the multiple query elements are related to the metadata of the target data; a syntax analysis unit configured to perform syntax analysis on the multiple word segments to obtain a plurality of element combinations formed based on the multiple query elements; a semantic analysis unit configured to perform semantic analysis on the plurality of element combinations to obtain a plurality of query objects; and a script construction unit configured to construct a data query script based on the plurality of query objects for executing a query operation on the target data to obtain query results corresponding to the query request.

[0023] According to a third aspect, a computer-readable storage medium is provided having a computer program stored thereon, which, when executed in a computer, causes the computer to perform the method of the first aspect.

[0024] According to a fourth aspect, a computing device is provided, including a memory and a processor, wherein the memory stores executable code, and the processor, when executing the executable code, implements the method of the first aspect.

[0025] By employing the methods and apparatus provided in the embodiments of this specification, core steps such as entity recognition, syntax analysis, semantic analysis, and script conversion are performed to translate natural language text query requests into data query scripts in a completely controllable and interpretable manner. The data query scripts are then used to execute data queries, thereby ensuring the accuracy of the data query results. At the same time, the threshold for data analysis is effectively lowered, enabling non-data technicians without programming skills to perform self-service data retrieval and analysis, thus allowing a large number of highly flexible data needs to be met instantly. Attached Figure Description

[0026] To more clearly illustrate the technical solutions of the embodiments of the present invention, the drawings used in the following description of the embodiments will be briefly introduced. Obviously, the drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0027] Figure 1 A flowchart illustrating an implementation of processing a query request according to one embodiment is shown;

[0028] Figure 2 A flowchart illustrating a method for processing a query request according to one embodiment is shown;

[0029] Figure 3 This diagram illustrates an example of how a query request is processed.

[0030] Figure 4 This diagram illustrates the interactive interface of a sample data analysis tool.

[0031] Figure 5 An implementation architecture diagram of data analysis according to one embodiment is shown;

[0032] Figure 6 A structural diagram of a query request processing apparatus according to one embodiment is shown. Detailed Implementation

[0033] The solution provided in this specification will now be described with reference to the accompanying drawings.

[0034] As mentioned earlier, data analysis needs (or simply data requirements) in many fields are characterized by large volume and high flexibility. However, traditional data analysis products (such as reporting tools) are mainly geared towards technical / data personnel with programming skills, rather than front-line business personnel with a large number of data analysis needs. This results in a workflow that can only follow the pattern of: business personnel submitting requirements → data personnel scheduling → requirements being delivered to business personnel. Consequently, data support suffers from severe time lags, making it difficult to achieve a response time of minutes or hours.

[0035] Based on this, a data analysis tool is proposed to support users (such as frontline business personnel) in initiating query requests in natural language. This tool translates the natural language into a data query script before executing the query. Currently, deep learning algorithms are proposed to directly translate natural language into data query scripts. However, DP algorithms are probabilistic. Due to the significant differences between natural language and query programming languages, DL algorithms can only achieve simple semantic queries with low accuracy. For example, the mainstream seq2seq (Sequence to Sequence) algorithm only supports about 80% accuracy under single-sheet layer aggregation, which cannot support the various complex data analysis requirements in real-world enterprise scenarios. It has low accuracy and narrow coverage, while complete accuracy is required in actual data retrieval. In addition, DP algorithms are black boxes; the prediction results are uncontrollable, errors are unexplainable, and rich training samples are required, resulting in very long training times and frequent retraining, causing users to wait. Therefore, the solution of using DP algorithms for natural language translation is difficult to implement on a large scale.

[0036] Furthermore, the inventors of this application propose a solution, see [link to solution]. Figure 1Through core steps such as entity recognition, syntax analysis, semantic analysis, and query script conversion, natural language is translated into query programming language in a controllable and interpretable manner, enabling non-data technicians to retrieve and analyze data independently, and obtain data analysis results with high timeliness and high accuracy.

[0037] The implementation steps of the above solution are described below with reference to specific embodiments. Figure 2 The flowchart illustrates a method for processing a query request according to one embodiment. The execution entity of the method can be any device, platform, or device cluster with computing and processing capabilities, such as the aforementioned data analysis tool. Figure 2 As shown, the method includes the following steps:

[0038] Step S210: Obtain a query request for the target data, wherein the query request is in the form of natural language text; Step S220: Perform entity recognition on the natural language text to obtain multiple word segments and entity categories corresponding to each word segment; Step S230: Based on the entity categories, convert the multiple word segments into multiple query elements, wherein the multiple query elements are related to the metadata of the target data; Step S240: Perform syntactic analysis on the multiple word segments to obtain several element combinations based on the multiple query elements; Step S250: Perform semantic analysis on the several element combinations to obtain several query objects; Step S260: Based on the several query objects, construct a data query script to execute the query operation on the target data and obtain query results corresponding to the query request.

[0039] The steps above are explained in detail below:

[0040] First, in step S210, a query request for the target data is obtained, and the query request is in the form of natural language text. It should be noted that the target data can also be called candidate data, alternative data, or backup data, and its corresponding storage methods are various, such as storing it in a database, an Excel spreadsheet, or a search engine, etc. Furthermore, natural language generally refers to a language that evolves naturally with culture; for example, Chinese, English, and Japanese are all natural languages. The following explanation mainly uses Chinese natural language as an example.

[0041] In this step, a query request initiated by the user based on their terminal is received. In one embodiment, natural language text entered by the user through an input box on their terminal interface can be obtained as the query request. In another embodiment, a speech segment entered by the user based on their terminal can be obtained, and speech recognition technology can be used to convert the speech segment into corresponding natural language text as the query request.

[0042] Based on an example, see Figure 3 in which the obtained natural language text is shown as "Payment amount in Shanghai this week for those whose gender is not male". According to another example, the natural language text corresponding to the query request may be: Top ten payment amounts this month.

[0043] As described above, a query request in the form of natural language text can be obtained.

[0044] Next, in step S220, entity recognition is performed on the above natural language text to obtain multiple word segments and the entity category corresponding to each word segment. It should be understood that the useful word segments obtained are usually words with specific meanings and can also be referred to as entities.

[0045] In a typical embodiment, multiple dictionaries corresponding to multiple entity categories can be obtained in advance. By matching the above natural language text with the multiple dictionaries, each word segment and its entity category can be obtained. It should be understood that the multiple entity categories and multiple dictionaries can be set and adjusted according to actual needs. Further, in a specific embodiment, based on the above multiple dictionaries, a dictionary-based word segmentation algorithm, such as the forward maximum matching algorithm, the reverse maximum matching algorithm, or the full binary maximum matching algorithm, etc., can be used to determine each word segment included in the natural language text, and the corresponding entity category can be determined according to the dictionary to which each word segment belongs.

[0046] On the other hand, in an embodiment, the word segment included in the natural language text can be determined while determining the entity category corresponding to the word segment. In another embodiment, multiple word segments included in the natural language text can be determined first, and then the entity category corresponding to each word segment among the multiple word segments can be determined. On the other hand, in an embodiment, the determination of word segments can adopt a statistics-based word segmentation algorithm, for example, a probability statistics algorithm based on mutual information, an N-Gram algorithm, or a Chinese word segmentation decision algorithm based on combination degree, etc. In an embodiment, based on the mapping relationship established in advance between word segments and entity categories, the entity category corresponding to each word segment in the natural language text can be determined.

[0047] It should be noted that for word segments for which the entity category cannot be determined, such as "de", "le", etc., they can be determined as meaningless word segments or stop words and discarded, so as to use the remaining word segments as the above multiple word segments.

[0048] According to an example, Figure 2The example shows the entity recognition results for the natural language text "Payment amount for gender not being male in Shanghai this week". The resulting word segments include "this week", "Shanghai", "gender", "not being", "male" and "payment amount". The corresponding entity categories are "Time", "Dim_value", "Dim_Name", "Operate", "Dim_value" and "Measure". These letter notation entity categories can also be represented as time, dimension value, dimension name, operator, dimension value and measure unit.

[0049] From the above, we can obtain multiple word segments contained in the natural language text, and the entity category corresponding to each word segment. Then, in step S230, according to the entity category, the above multiple word segments are converted into multiple query elements, which are related to the metadata of the target data.

[0050] It should be noted that metadata typically refers to data that defines the data structure. In a typical scenario, the target data is stored in a database. Accordingly, the database's metadata refers to the data that defines the structure of various data objects in the database, such as table names, column names (field names), etc. Furthermore, the aforementioned query elements may also be related to the data content of the target data; for example, the database's data content includes records or field values ​​in the tables.

[0051] Furthermore, the query elements related to the metadata or data content in the target data can be metadata, such as a user table in a database, or data content, such as the field value "male" under the gender field; or, they can be operators applied to the metadata or data content, such as not equal to (op.NE), summation (op.SUM), etc. In this step, for any first word among the above multiple word segments, it is converted into the first query element based on the conversion rules corresponding to its entity category.

[0052] In one embodiment, if the entity category of the first word segment is a dimension name or a metric unit, then the field in the target data that matches the first word segment is located, and a first query element is formed based on the name of the field and the name of the table in which the field is located. In one specific embodiment, matching can mean being exactly the same. In another specific embodiment, matching can also mean being exactly the same as the alias of the first word segment and the field. For example, assuming the first word is "payment amount", then "payment amount" can be determined to be an alias of "payment amount", and "payment amount" can be determined as the field that matches the first word segment.

[0053] Based on an example, suppose the first word is Figure 2 The entity category for "Gender" shown is the dimension name. Figure 2This is denoted as Dim_name. From this, we can determine the matching field 'sex' in the target data and the table 'u' where 'sex' resides, forming the first query element 'u.sex'. According to another example, assuming the first word segmentation is... Figure 2 The "Payment Amount" shown in the figure has an entity category of metric unit ( Figure 2 The term is denoted as Measure. From this, we can determine the matching field amt and the table p where the field amt is located, thus forming the first query element p.amt.

[0054] In another embodiment, if the entity category of the first word segment is a dimension value, then the field value in the target data that matches the first word segment is located, and a first query element is formed based on the name of the field containing the field value and the name of the table containing the field. In one specific embodiment, matching can mean being exactly the same. In another specific embodiment, matching can also mean being exactly the same as an alias of the first word segment and the field value. For example, assuming the first word is Shanghai, then Shanghai can be determined to be an alias of Shanghai City, and Shanghai City can be determined as the field value that matches the first word segment.

[0055] Based on an example, suppose the first word is Figure 2 The entity category shown as "male" is a dimension value ( Figure 2 This is denoted as Dim_value. From this, we can determine the field value "male" that matches the target data. Based on this field value "male," and the corresponding field name "sex" and table name "u," we form the first query element u.sex = male. According to another example, assuming the first word segmentation is... Figure 2 The entity category "Shanghai" shown in the image is a dimension value ( Figure 2 The value is denoted as Dim_value. Thus, the field value "Shanghai" that matches the target data can be determined. Based on the field value "Shanghai", the corresponding field name city and table name c, the first query element c.city = Shanghai is formed.

[0056] In another embodiment, if the entity category of the first word segment is time-related, then the first word segment undergoes time rendering processing; in other words, the first word segment is converted into time data conforming to a preset format and used as the first query element. According to an example, assume the first word segment is... Figure 2 The entity category shown as "This Week" is time-based. Figure 2 The time period is denoted as Time. Therefore, time rendering processing can be performed on it to obtain the first query element: 2020.5.21-2020.5.27.

[0057] In another embodiment, if the entity category of the first word segment is a data operator class, then the operator corresponding to the first word segment is determined as the first query element. In a specific embodiment, the operator corresponding to the first word segment is determined according to a pre-established mapping relationship between word segments and operators. As an example, assume the first word is... Figure 2 The entity category shown as "not" is the data operator class. Figure 2 The operator 'Operate' can be used as the first query element, and its corresponding operator '<>' can be used as the first query element.

[0058] In another embodiment, if the entity category of the first segment is an intent class, then the function name corresponding to the first segment is determined as the first query element. In a specific embodiment, the function name corresponding to the first segment is determined according to a pre-established mapping relationship between segmentation and function name. For example, assuming the first segment is "average" and its entity category is an intent class (e.g., it can be denoted as intent), then its corresponding function name "Average" can be used as the first query element.

[0059] The above examples, using entity categories from word segmentation as dimension names, measurement units, dimension values, time categories, data operator categories, or intent categories, illustrate the transformation methods for query elements. It should be understood that entity categories can also include other categories, and the classification and naming of categories, as well as the corresponding transformation rules, can all be adjusted according to actual needs or business feedback.

[0060] From the above, multiple query elements corresponding to multiple word segments can be identified. Then, in step S240, by performing syntactic analysis on these multiple word segments, several element combinations based on these multiple query elements are obtained. It should be noted that syntactic analysis, also known as parsing, is the process of analyzing natural language by following formal grammatical rules, where grammatical rules apply to words and phrases. Syntactic analysis mainly assigns semantic structure to the text. In addition, "several" in the text refers to one or more.

[0061] In this step, multiple word segments can be analyzed syntactically to obtain several word segments. It should be noted that syntactic analysis can be implemented using existing methods, such as constructing a syntax tree; furthermore, each resulting word segment may contain two or more words, or it may contain a single word. Based on an example, Figure 2 The word segmentation phrases shown include: “this week”, “Shanghai”, “gender is not male” and “payment amount”, among which the phrase “gender is not male” is composed of three word segments: “gender”, “not male”, and “male”.

[0062] Furthermore, based on the aforementioned word segmentation groups, multiple query elements are combined to obtain several element combinations. Specifically, the query elements corresponding to each word segment can be combined according to the combination method of each word segment in each word segmentation group. For example, regarding... Figure 2 The word segmentation phrase "gender is not male" shown can be combined with the query elements u.sex, <>, and u.sex=male corresponding to the segmentations "gender", "not", and "male" to obtain the corresponding element combination: u.sex<>male. According to another example... Figure 2 The text also shows the word segmentation phrases "this week", "Shanghai" and "payment amount", from which the corresponding element combinations can be determined as: 2020.5.21-2020.5.27, c.city = Shanghai, p.amt.

[0063] As described above, through syntactic analysis, several element combinations can be formed based on multiple query elements. Next, in step S250, semantic analysis is performed on these element combinations to obtain several query objects. It should be understood that semantic analysis is the process of understanding the meaning of query elements, and the result of this understanding is reflected in the corresponding query objects. Alternatively, query objects can be understood as query components in a programming language; by applying query operations based on these components, the required data within the target data can be accurately located.

[0064] In this step, for any combination of the first elements among the aforementioned query elements, it can be processed into a corresponding query object based on the semantic processing rules corresponding to the entity categories it involves. It should be understood that the semantic processing rules can be set and adjusted by staff according to actual application needs.

[0065] In one embodiment, the entity categories involved in the first element combination include metric units and intent classes. In this case, the first element combination can be directly identified as the corresponding first query object. For example, the first element combination is Average(p.amt), and the entity categories corresponding to its corresponding word segments "average value" and "payment amount" are intent class and metric unit, respectively. In this case, Average(p.amt) can be directly identified as the corresponding query object.

[0066] In another embodiment, the entity categories involved in the first element combination include metric units but not intent classes. In this case, the default function name corresponding to the query element corresponding to the metric unit can be obtained, thereby forming a first query object based on the default function name and the first element combination. According to an example, the first element combination is p.amt, and the entity categories involved do not include intent classes. In this case, the default function name SUM corresponding to p.amt can be obtained, thereby forming a first query object SUM(p.amt).

[0067] In another embodiment, the entity categories involved in the first element combination include, and only include, time-related categories. In this case, the time field in the table name can be determined based on the table name involved in the query element of the corresponding metric unit among the above multiple query elements. Then, based on the table name, the time field name, and the first element combination, a time selection object is formed as the first query object. According to an example, the first element combination is 2020.5.21-2020.5.27. In this case, the time field name pay_date can be determined based on the table name p corresponding to p.amt, thereby forming a time selection object p.pay_date between 2020.5.21 and 2020.5.27, which serves as the first query object.

[0068] In another embodiment, the entity categories involved in the first element combination include dimension values. In this case, the first element combination can be directly determined as the corresponding first query object. According to an example, for... Figure 2 The element combination shown, c.city = Shanghai and u.sex <> male, can be directly used to determine the corresponding query objects as c.city = Shanghai and u.sex <> male.

[0069] Based on the above, several query objects can be obtained through semantic analysis. Then, in step S260, a data query script is constructed based on the several query objects to execute query operations on the target data and obtain query results corresponding to the query request. It should be understood that the scripting language of the data query script corresponds to the storage method of the target data. For example, if the target data is stored in a database, the scripting language can be SQL; or if the target data is stored in an Excel spreadsheet, the scripting language can be Python.

[0070] In this step, the query keywords corresponding to each of the aforementioned query objects in the scripting language can be determined first. In one embodiment, for each query object, the query keywords corresponding to that query object are determined based on its involved entity category and the pre-established mapping relationship between entity categories and query keywords. It should be understood that the mapping relationship can be set and adjusted by staff based on experience and actual feedback. For example, assuming the scripting language is SQL, this mapping relationship can include the contents shown in Table 1 below.

[0071] Table 1

[0072]

[0073]

[0074] Based on the mapping relationship in Table 1, in one example, such as Figure 2 shown, the query object "p.pay_date between 2020.5.21 and 2020.5.27" involves time, and thus it can be determined that the corresponding SQL keywords include Where and Group by; the query object "c.city = Shanghai" involves dimension values, and thus it can be determined that the corresponding SQL keywords include Where; the query object "u.sex <> male" involves dimension values, and thus it can be determined that the corresponding SQL keywords include Where; the query object "SUM(p.amt)" involves measurement units, and thus it can be determined that the corresponding SQL keywords include Select.

[0075] As above, the query keywords corresponding to each query object can be determined. Further, based on this query keyword and each query object, the above data query script can be formed. It should be understood that the query script language has its syntax specifications. Thus, in one embodiment, according to its syntax specifications, the determined query keywords and each query object can be concatenated in a predetermined order to obtain a data query script. In another embodiment, a template of query script statements pre-written according to the syntax specifications can be obtained. This template includes mandatory query keywords and optional query keywords. Thus, according to the correspondence between each query object and the query keyword, as well as the filling specifications of the query keyword, etc., the content involved in each query object is filled into this template to obtain a data query script corresponding to the above natural language text.

[0076] According to an example, assume that the SQL statement template includes:

[0077] Select (mandatory) as (optional) from (mandatory)

[0078] Join (optional) on (optional) = (optional)

[0079] Where (optional)

[0080] Group by (optional)

[0081] Further, based on Figure 2 the SQL keywords corresponding to each query object shown in, fill the SQL statement template to obtain the following SQL script:

[0082] Select SUM(p.amt) as payment amount from p

[0083] Join u on u.user_id = p.user_id

[0084] Join c on c.city = p.city

[0085] Where p.pay_date between'2020.5.21'and'2020.5.27'and u.sex<>'male'and c.city='Shanghai City'Group by p.pay_date

[0086] The above can be achieved by first determining the query keywords corresponding to each query object, and then constructing a corresponding data query script based on each query object and its corresponding query keywords. In another embodiment, based on a pre-defined query script language template, the query keywords corresponding to the query objects can be determined simultaneously, and the query objects can be used to populate the SQL template to obtain the aforementioned data query script. On the other hand, in one embodiment, analysis statements corresponding to the data analysis intermediate language can be constructed based on several query objects first, and then these analysis statements can be converted into corresponding query script statements to form the aforementioned data query script. It should be noted that the syntax rules of the intermediate language, as well as its conversion relationship with query objects and query script statements, can be designed according to actual needs.

[0087] Based on the above, a data query script can be constructed based on several query objects, thereby translating the above natural language text into a data query script.

[0088] According to another embodiment, after step S260 above, the method may further include: performing a query operation on the target data using the constructed data query script to obtain query content. Further, in one specific embodiment, the query content can be displayed to the user as a query result. In another specific embodiment, a corresponding chart can be generated based on the query content, and then this chart can be displayed to the user as a query result. According to one example, Figure 4 The results are displayed in a pie chart format, corresponding to the natural language query text "Transaction amounts of women in various cities yesterday." This allows the query results to be presented intuitively to the user.

[0089] In summary, the query request processing method disclosed in the embodiments of this specification, through core steps such as entity recognition, syntax analysis, semantic analysis, and script conversion, transforms the query request in natural language text form into a data query script in a completely controllable and interpretable manner. The data query script is then used to execute the data query, thereby ensuring the accuracy of the data query results. Furthermore, it effectively lowers the threshold for data analysis, enabling non-data technicians without programming skills to perform self-service data retrieval and analysis, thus allowing a large number of highly flexible data needs to be met instantly.

[0090] To facilitate a comprehensive understanding of the data analysis scheme proposed by the inventors, the following description, using an example, outlines each step of the scheme's implementation. Figure 5 This diagram illustrates an implementation architecture diagram for data analysis according to one embodiment, such as... Figure 5 As shown, the implementation process involves the use of multiple modules, including a dictionary capability module, an intelligent suggestion module, a natural language translation module, a query module, a chart recommendation module, and a feedback self-learning module. The dictionary capability module has sub-modules such as word search, dictionary construction, and lifecycle management, and is used as a support module for the intelligent suggestion module and the natural language translation module.

[0091] Furthermore, the intelligent suggestion module has functions such as completion, recommendation, and sorting, which can assist users in completing natural language query requests. The natural language translation module obtains the natural language text "today's offline transaction count" input by the user from the intelligent suggestion module, and then performs entity recognition, syntactic analysis, and semantic analysis on this text to obtain several query objects, which are then sent to the query module. The query module generates a data query script based on the received query objects, submits the data query script to the target data storage system, assembles the results, and outputs them to the chart recommendation module. The chart recommendation module infers the appropriate chart format based on the query results, or generates the corresponding chart based on the user's selection of multiple modes, and finally displays it to the user, for example, informing the user in text form that "today's offline transaction count is 550 million." Additionally, Figure 5 The feedback self-learning module shown can collect data from each of the above stages for statistical analysis and optimization of each module.

[0092] The above combination Figure 5 This section provides a comprehensive overview of the data analysis solution.

[0093] According to another embodiment, this specification also discloses a query request processing apparatus. Figure 6 This diagram illustrates a structural arrangement of a query request processing apparatus according to one embodiment. Figure 6 As shown, the device 600 includes the following components:

[0094] The text acquisition unit 610 is configured to acquire a query request for target data, wherein the query request is in the form of natural language text; the entity recognition unit 620 is configured to perform entity recognition on the natural language text to obtain multiple word segments and entity categories corresponding to each word segment; the conversion unit 630 is configured to convert the multiple word segments into multiple query elements according to the entity categories, wherein the multiple query elements are related to the metadata of the target data; the syntax analysis unit 640 is configured to perform syntax analysis on the multiple word segments to obtain several element combinations based on the multiple query elements; the semantic analysis unit 650 is configured to perform semantic analysis on the several element combinations to obtain several query objects; and the script construction unit 660 is configured to construct a data query script based on the several query objects to execute query operations on the target data and obtain query results corresponding to the query request.

[0095] In one embodiment, the natural language text is obtained by converting user-input speech segments.

[0096] In one embodiment, the entity recognition unit 620 is specifically configured to: acquire multiple pre-built dictionaries corresponding to multiple entity categories; and obtain each word segment and its entity category by matching the natural language text with the multiple dictionaries.

[0097] In one embodiment, the conversion unit 630 is specifically configured to convert any first word segment into a first query element based on the conversion rules corresponding to its entity category.

[0098] Furthermore, in a specific embodiment, the conversion unit 630 is further configured to: if the entity category of the first word segment is a dimension name or a metric unit, then form the first query element based on the field name in the target data that matches the first word segment.

[0099] In another specific embodiment, the conversion unit 630 is further configured to: if the entity category of the first word segment is a dimension value, then form the first query element based on the field value in the target data that matches the first word segment.

[0100] In another specific embodiment, the conversion unit 630 is further configured to: if the entity category of the first word segment is time-related, then convert the first word segment into time data conforming to a preset format, and use it as the first query element.

[0101] In another specific embodiment, the conversion unit 630 is further configured to: if the entity category of the first word segment is a data operator category, then determine the operator corresponding to the first word segment as the first query element.

[0102] In another specific embodiment, the conversion unit 630 is further configured to: if the entity category of the first word segment is an intent class, then determine the function name corresponding to the first word segment as the first query element.

[0103] In one embodiment, the syntax analysis unit 640 is specifically configured to: perform syntax analysis on the multiple word segments to obtain several word segmentation groups; and perform combination processing on the multiple query elements based on the several word segmentation groups to obtain the combination of the several elements.

[0104] In one embodiment, the semantic analysis unit 650 is specifically configured to: for any combination of first elements, process it into a corresponding query object based on the semantic processing rules corresponding to the entity categories involved.

[0105] In a specific embodiment, the semantic analysis unit 650 is further configured to: if the entity category involved in the first element combination includes a metric unit but does not include an intent class, then obtain the default function name corresponding to the query element corresponding to the metric unit; and form the first query object based on the default function name and the first element combination.

[0106] In one embodiment, the script building unit 660 is specifically configured to: determine the query keywords corresponding to each query object; and form the data query script based on the query keywords and each query object.

[0107] In a specific embodiment, the script construction unit 660 is further configured to: for each query object, determine the query keywords corresponding to the query object based on the entity category it involves and the pre-established mapping relationship between entity categories and query keywords.

[0108] In one embodiment, the device 600 further includes a query unit 670, configured to perform the query operation on the target data using the data query script to obtain query content; and generate a corresponding chart based on the query content as the query result.

[0109] In summary, the query request processing apparatus disclosed in the embodiments of this specification, through core steps such as entity recognition, syntax analysis, semantic analysis, and script conversion, can controllably and interpretably translate query requests in natural language text form into data query scripts step by step. The data query scripts are then used to execute data queries, thereby ensuring the accuracy of the data query results. Furthermore, it effectively lowers the threshold for data analysis, enabling non-data technicians without programming skills to perform self-service data retrieval and analysis, thus allowing a large number of highly flexible data needs to be met instantly.

[0110] According to another embodiment, a computer-readable storage medium is also provided, on which a computer program is stored, which, when executed in a computer, causes the computer to perform a combination Figure 2 The method described.

[0111] According to another embodiment, a computing device is also provided, including a memory and a processor, wherein the memory stores executable code, and when the processor executes the executable code, it implements a combination... Figure 2 The method described.

[0112] Those skilled in the art will recognize that, in one or more of the examples above, the functions described in this invention can be implemented using hardware, software, firmware, or any combination thereof. When implemented in software, these functions can be stored in a computer-readable medium or transmitted as one or more instructions or code on a computer-readable medium.

[0113] The specific embodiments described above further illustrate the purpose, technical solution, and beneficial effects of the present invention. It should be understood that the above description is only a specific embodiment of the present invention and is not intended to limit the scope of protection of the present invention. Any modifications, equivalent substitutions, improvements, etc., made on the basis of the technical solution of the present invention should be included within the scope of protection of the present invention.

Claims

1. A method for processing a query request, comprising: obtaining a query request for target data, the query request being in the form of natural language text; performing entity recognition on the natural language text to obtain an entity category corresponding to each of a plurality of tokens in the natural language text excluding stop words; converting the plurality of tokens into a plurality of query elements according to the entity category corresponding to each of the plurality of tokens, the plurality of query elements being related to metadata of the target data; obtaining a plurality of element combinations based on the plurality of query elements by performing syntax analysis on the plurality of tokens; for any first element combination, processing the first element combination into a corresponding query object based on a semantic processing rule corresponding to an entity category involved in the first element combination, to obtain a plurality of query objects corresponding to the plurality of element combinations; constructing a data query script based on the plurality of query objects, the data query script being used to perform a query operation on the target data to obtain a query result corresponding to the query request.

2. The method of claim 1, wherein, The entity category is selected from the group consisting of dimension name, dimension value, measurement unit, time category, data operator category, and intent category.

3. The method of claim 1, wherein, The converting of the plurality of tokens into the plurality of query elements comprises: if an entity category of any first token is a dimension name or a measurement unit, forming a corresponding first query element based on a field name in the target data matching the first token.

4. The method of claim 1, wherein, The converting of the plurality of tokens into the plurality of query elements comprises: if an entity category of any first token is a dimension value, forming a corresponding first query element based on a field value in the target data matching the first token.

5. The method of claim 1, wherein, The converting of the plurality of tokens into the plurality of query elements comprises: if an entity category of any first token is a time category, converting the first token into time data in a preset format as a corresponding first query element.

6. The method of claim 1, wherein, The converting of the plurality of tokens into the plurality of query elements comprises: if an entity category of any first token is a data operator category, determining an operator corresponding to the first token as a corresponding first query element.

7. The method of claim 1, wherein, The converting of the plurality of tokens into the plurality of query elements comprises: if an entity category of any first token is an intent category, determining a function name corresponding to the first token as a corresponding first query element.

8. The method of claim 1, wherein, The obtaining of the plurality of element combinations based on the plurality of query elements by performing syntax analysis on the plurality of tokens comprises: performing syntax analysis on the plurality of tokens to obtain a plurality of token groups; combining the plurality of query elements according to the plurality of token groups to obtain the plurality of element combinations.

9. The method of claim 1, wherein, For any first element combination, processing the first element combination into a corresponding query object based on a semantic processing rule corresponding to an entity category involved in the first element combination, comprises: if the entity category involved in the first element combination includes a measurement unit and does not include an intent category, obtaining a default function name corresponding to a query element corresponding to the measurement unit; forming the query object based on the default function name and the first element combination.

10. The method of claim 1, wherein, The constructing of the data query script based on the plurality of query objects comprises: determining a corresponding query keyword for each query object; Form the data query script based on the query keywords and the query objects.

11. The method of claim 10, wherein, Determine the query keywords corresponding to the query objects, including: Determine the query keywords corresponding to the query objects based on the entity categories involved by the query objects and the mapping relationship between the entity categories and the query keywords.

12. A processing apparatus for query request, comprising: a text obtaining unit configured to obtain a query request for target data, the query request being in the form of natural language text; an entity identifying unit configured to perform entity identification on the natural language text to obtain an entity category corresponding to each of a plurality of tokens in the natural language text except stop words; a converting unit configured to convert the plurality of tokens into a plurality of query elements according to the entity category corresponding to each of the tokens, the plurality of query elements being related to metadata of the target data; a syntax analyzing unit configured to obtain a plurality of element combinations formed based on the plurality of query elements by performing syntax analysis on the plurality of tokens; a semantic analyzing unit configured to process, for any first element combination, the first element combination into a corresponding query object based on a semantic processing rule corresponding to the entity category involved by the first element combination, to obtain a plurality of query objects corresponding to the plurality of element combinations; a script constructing unit configured to construct a data query script based on the plurality of query objects, the data query script being used to perform a query operation on the target data to obtain a query result corresponding to the query request.

13. A computing device comprising a memory and a processor, wherein, The memory stores executable code, and the processor executes the executable code to implement the method in any one of claims 1-11.

Citation Information

Patent Citations

  • Method and device for outputting structured query statements

    CN107451153A

  • Predictive system for generating clinical queries

    CN111798941A