Method and device for automatically completing query content
Through the automatic completion method of natural language query content with word-grained content, using dictionary trees and entity categories to filter candidate words, the problem of irrelevant completion in the existing technology is solved, and more accurate completion effect is achieved and user experience is improved.
Patent Information
- Application Number
- CN202210675071.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-01-19
- Publication Date
- 2025-04-08
- Estimated Expiration
- 2042-01-19
AI Technical Summary
Existing natural language query completion methods usually take sentences as granularity, resulting in the prompt content that when the user enters some content, the prompt content is not relevant enough and cannot accurately complete the user's natural language query content.
The automatic completion method of query content with word granularity is adopted. By obtaining the natural language query content input by the user, dividing it into several query words, and using a pre-constructed dictionary tree to query candidate words for each query word, filtering the target candidate words based on entity categories, and finally determining the complete content.
Improve the accuracy of the complete content, enhance the user experience, and ensure that the complete content is highly correlated with the user's natural language query content.
Smart Images

Figure CN114969242B_ABST
Abstract
Description
[0001] This application is a divisional application of the invention patent application with application number 202210058334.9 filed on January 19, 2022, and entitled “Method and device for automatic completion of query content”. Technical Field
[0002] One or more embodiments of the present specification relate to the field of data analysis, and more particularly, to a method and device for automatically completing query content. Background Art
[0003] Natural language query (NLQ) refers to the use of natural language to query and analyze data. The data here can be stored in a database, Excel spreadsheet or search engine.
[0004] When users use natural language to query data, in order to improve user input efficiency, when users enter partial content, they will usually be intelligently prompted with the content they may want to enter later, that is, the user's natural language query content will be completed.
[0005] Traditional completion methods usually complete at the sentence level, that is, the prompt content is usually a whole sentence. However, when the user has entered part of the content, he or she usually hopes to be able to prompt words related to the user's natural language query content, rather than an irrelevant sentence. Therefore, it is necessary to provide a completion solution to more accurately complete the user's natural language query content. Summary of the invention
[0006] One or more embodiments of the present specification describe a method and device for automatic completion of query content, which can complete the content at a word granularity, thereby improving the accuracy of the completed content and further improving the user experience.
[0007] In a first aspect, a method for automatically completing a query content is provided, comprising:
[0008] Obtain the natural language query content currently input by the user for the target data;
[0009] Segmenting the natural language query content to obtain a number of query words;
[0010] Taking the query words as current query words, querying a plurality of dictionary trees corresponding to different entity categories to obtain candidate words corresponding to a plurality of entity categories for each query word; the plurality of dictionary trees are pre-constructed according to a data query for the target data;
[0011] Selecting target candidate words from the candidate words based at least on the entity categories corresponding to the candidate words of the query words;
[0012] Determine the completion content of the natural language query content according to the target candidate words.
[0013] In a second aspect, a device for automatically completing query content is provided, comprising:
[0014] An acquisition unit, used to acquire natural language query content currently input by the user for target data;
[0015] A segmentation unit, used to segment the natural language query content to obtain a number of query words;
[0016] A query unit, configured to use the query words as current query words, query a plurality of dictionary trees corresponding to different entity categories, so as to obtain candidate words corresponding to a plurality of entity categories for each query word; the plurality of dictionary trees are pre-constructed according to a data query for the target data;
[0017] A selection unit, configured to select target candidate words from the candidate words based at least on the entity categories corresponding to the candidate words of the query words;
[0018] A determination unit is used to determine the completion content of the natural language query content according to the target candidate words.
[0019] According to a third aspect, a computer storage medium is provided, on which a computer program is stored. When the computer program is executed in a computer, the computer is caused to execute the method of the first aspect.
[0020] According to a fourth aspect, a computing device is provided, including a memory and a processor, wherein the memory stores executable code, and when the processor executes the executable code, the method of the first aspect is implemented.
[0021] The method and device for automatic completion of query content provided by one or more embodiments of the present specification obtains candidate words with corresponding entity categories for each query word obtained based on natural language query content by querying the dictionary tree. Then, based on the corresponding entity category, each candidate word is screened to obtain the candidate word as the completion content. In other words, the present solution can obtain candidate words as the completion content based on the entity category. Since there are conventional combinations between entity categories, the present solution selects candidate words based on entity categories, which can solve the problem that the completion content is irrelevant to the natural language query content. In addition, the present solution uses candidate words as the completion content, that is, the natural language query content can be completed at the word granularity, thereby improving the accuracy of the completion content, and further improving the user experience. BRIEF DESCRIPTION OF THE DRAWINGS
[0022] In order to more clearly illustrate the technical solutions of the embodiments of this specification, the drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this specification. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.
[0023] Figure 1 A schematic diagram of an implementation scenario disclosed in an embodiment of this specification;
[0024] Figure 2 A flowchart of a method for automatically completing query content according to an embodiment is shown;
[0025] Figure 3a A schematic diagram of a prefix tree according to an embodiment is shown;
[0026] Figure 3b A schematic diagram of a suffix tree according to an embodiment is shown;
[0027] Figure 4a A schematic diagram of a state machine according to an embodiment is shown;
[0028] Figure 4b A state machine schematic diagram according to another embodiment is shown;
[0029] Figure 5 A schematic diagram of a device for automatically completing query content according to an embodiment is shown. DETAILED DESCRIPTION
[0030] The solution provided in this specification is described below in conjunction with the accompanying drawings.
[0031] In the field of data analysis, data query is usually involved, that is, reading data from a database, Excel spreadsheet or search engine.
[0032] In traditional technologies, data queries are usually performed based on specific query languages, such as reading data from a database based on SQL statements. However, this increases the threshold for using data. To this end, the following two improvement solutions are proposed:
[0033] The first one is a method based on Natural Language Processing (NLP). However, this method cannot guarantee that the read data is completely accurate, that is, this method is probabilistically accurate.
[0034] The second method is based on seq2SQL, which reads data by directly translating natural language into SQL statements. However, this method only supports about 80% accuracy under single-table layer aggregation, and cannot support various complex data analysis needs in real scenarios within the enterprise. In other words, this method has low accuracy and narrow coverage.
[0035] Since both of the above solutions have certain defects, a further improvement is to directly use natural language to query data. When users use natural language to query data, in order to improve user input efficiency, it is usually necessary to complete the user's natural language query content.
[0036] At present, the completion method used in search engines usually completes at the sentence granularity, that is, the prompt content is usually a whole sentence. However, when the user has entered part of the content, he usually hopes to be able to prompt words related to the user's natural language query content, rather than an irrelevant sentence. For this reason, the inventor of the present application proposes to complete at the word granularity, that is, to complete the user's natural language query content in a more fine-grained manner, thereby improving the accuracy of the completed content and thus improving the user experience.
[0037] Figure 1 A schematic diagram of an implementation scenario disclosed in one embodiment of this specification. Figure 1 In the example, we can first obtain the natural language query content for the target data currently input by the user. Then we can segment the natural language query content to obtain several query words: W1, W2, ..., W N , where N is the number of query words. Take several query words as current query words, query several dictionary trees corresponding to different entity categories to obtain candidate words for each query word: W 11 , W 12 , W 21 , W 22 , W 23 …、W N1 and W N2 , and the entity categories corresponding to each candidate word can be: C2, C1, C1, C2, C1…, C2 and C2. Finally, based on the entity categories corresponding to each candidate word of each query word, each target candidate word can be selected from each candidate word: W 11 , W 22 , W N1 and W N2 . Determine the completion content of the natural language query content according to each target candidate word.
[0038] In one example, each target candidate word may be selected from each candidate word based on a state machine of a regular expression, which will be described in detail later.
[0039] The scheme provided in the embodiments of this specification is described in detail below.
[0040] Figure 2 A flowchart of a method for automatically completing query content according to an embodiment is shown. The method can be executed by any device, equipment, platform, or device cluster with computing and processing capabilities. Figure 2 As shown, the method may at least include the following steps.
[0041] Step 202: Obtain the natural language query content currently input by the user for the target data.
[0042] The entity categories can be divided into two types, one of which is a public category, which can include at least one of the following: time, operator, unit, function, and intent, etc. The other is a private category, which can include at least one of the following: dimension, dimension value, and measurement, etc. In one example, the private category can be determined based on the key value of the key-value pair.
[0043] In an example, the entity words corresponding to time may be, for example, "XX year", "XX month", "XX day", "last N days", "last few days", "last N years", "last year" and "this year", etc. The entity words corresponding to operators may be, for example, "greater than", "less than", "equal to", "exceed" and "above", etc. The entity words corresponding to units may be, for example, "how old", "several" and "several people", etc. The entity words corresponding to functions may be, for example, "maximum value", "minimum value" and "average value", etc. The entity words corresponding to dimensions may be, for example, "city", "sales amount" and "class", etc. The above-mentioned dimension values are the values of the dimensions. Taking the dimension "city" as an example, the corresponding dimension values may be, for example, "Beijing" or "Shanghai", etc.
[0044] Specifically, the natural language query content currently input by the user may be obtained based on the position of the cursor. For example, all the content in the input box up to the position of the cursor may be used as the natural language query content.
[0045] Step 204, segment the natural language query content to obtain a number of query words.
[0046] In one example, before segmenting the natural language query content, entity recognition may be performed on it to obtain basic entity categories of the natural language query content.
[0047] For example, if the natural language query currently entered by the user is "payments in various cities yesterday", then through entity recognition, the basic entity categories can be obtained: time and dimension. Among them, the word corresponding to time is "yesterday", and the word corresponding to dimension is "city".
[0048] After entity recognition, "Yesterday's payments in various cities" can be segmented to obtain query terms: "yesterday", "payments in various cities", "city payment", "city payment", "payment" and "pay", etc.
[0049] Step 206 , using several query words as current query words, searching several dictionary trees corresponding to different entity categories to obtain candidate words corresponding to multiple entity categories for each query word.
[0050] The above-mentioned dictionary trees may be pre-built according to data queries for target data. The data queries here are also called historical queries, and the corresponding historical natural language query content may include entity words corresponding to the above-mentioned common categories and / or entity words corresponding to private categories.
[0051] Taking the first dictionary tree corresponding to the first entity category (any of the above public categories, or any of the above private categories) in the above-mentioned several dictionary trees as an example, the first dictionary tree may include multiple branches, each of which represents an entity word corresponding to the first entity category in the historical natural language query content. In addition, each inter-node path in each branch corresponds to at least part of the characters in the represented entity word, and the value of the leaf node is the represented entity word. The value of the branch node is a combination of the characters corresponding to the inter-node paths from the root node to the branch node.
[0052] The query process for the above-mentioned first dictionary tree can specifically include: matching the current query term with each branch in the first dictionary tree word by word in turn; if the character covered by any first branch contains the current query term, then the value of the leaf node of the first branch is used as a candidate word of the first entity category of the current query term.
[0053] Taking a branch in the first dictionary tree as an example, the above character-by-character matching may specifically include: character-by-character matching of each character in the current query term with each character corresponding to each path between nodes in the branch. If each character corresponding to each path between nodes in the branch contains each character in the current query term, it is determined that the match is successful, otherwise the match fails.
[0054] In one example, the first dictionary tree may include a prefix tree and a suffix tree. The prefix tree may be constructed based on at least part of the characters from the beginning of each entity word corresponding to the first entity category in the historical natural language query content. The suffix tree may be constructed based on at least part of the characters from the end of each entity word corresponding to the first entity category in the historical natural language query content.
[0055] Figure 3a A schematic diagram of a prefix tree according to an embodiment is shown. Figure 3a Among them, the prefix tree may include multiple branches. Among them, the entity word represented by the leftmost branch is: "Payment amount", and its corresponding entity category is: Dimension. In addition, the characters corresponding to the paths between the nodes in this branch are respectively: "支", "付", "金", and "额" (that is, the paths between the nodes in this branch respectively correspond to all the characters in the represented entity word), and the value of the leaf node is: "Payment amount". The values of the 3 branch nodes are respectively: "支", "支付", "支付金". Similarly, the entity word represented by the second leftmost branch is: "Transaction volume", and its corresponding entity category is: Dimension. In addition, the characters corresponding to the paths between the nodes in this branch are respectively: "交", "易", "笔", and "数", and the value of the leaf node is: "Transaction volume". The values of the 3 branch nodes are respectively: "交", "交易", "交易笔".
[0056] It can be seen from this that Figure 3a the entity categories of the entity words represented by the branches in it are the same, that is, they are all the entity categories of this prefix tree.
[0057] Figure 3b Show a schematic diagram of a suffix tree according to an embodiment. Figure 3b Among them, the suffix tree may include multiple branches. Among them, the entity word represented by the leftmost branch is: "Payment amount", and its corresponding entity category is: Dimension. In addition, the characters corresponding to the paths between the nodes in this branch are respectively: "付", "金", and "额" (that is, the paths between the nodes in this branch respectively correspond to some of the characters in the represented entity word), and the value of the leaf node is: "Payment amount". The values of the 2 branch nodes are respectively: "付", "付金". Similarly, the entity word represented by the second leftmost branch is: "Payment amount", and its corresponding entity category is: Dimension. In addition, the characters corresponding to the paths between the nodes in this branch are respectively: "金" and "额", and the value of the leaf node is: "Payment amount". The value of 1 branch node is: "金".
[0058] It can be seen from this that Figure 3b the entity categories of the entity words represented by the branches in it are the same, that is, they are all the entity categories of this suffix tree. In addition, the entity categories of the above prefix tree and suffix tree are also the same. Similarly, the above several dictionary trees may also include prefix trees and suffix trees corresponding to other entity categories.
[0059] It should be noted that when the first dictionary tree includes a prefix tree and a suffix tree, the query process for the first dictionary tree may specifically include: using the current query word as a prefix word, querying the prefix tree, and obtaining the first entity word of the first entity category of the current query word, and using the current query word as a suffix word, querying the suffix tree, and obtaining the second entity word of the first entity category of the current query word. The first entity word and the second entity word constitute the candidate words of the first entity category of the current query word.
[0060] The query process for the prefix tree and the suffix tree is similar, and the detailed query process can refer to the description of the query process for the first dictionary tree, except that the first dictionary tree is replaced by the prefix tree or the suffix tree.
[0061] by Figure 3a Taking the prefix tree shown in the figure as an example, if the current query word is: "payment", then the candidate words obtained by the query can be: "payment amount", and its corresponding entity category is: dimension. Figure 3b Taking the suffix tree shown as an example, if the current query word is: "amount", then the candidate words obtained by the query may be: "payment amount", and its corresponding entity category is: dimension.
[0062] In the above example where the natural language query content is "payments in various cities yesterday", the candidate words obtained may be, for example, "payment amount", "number of payments", "number of payees" and "payment date", etc.
[0063] In addition, in practical applications, there may be some words that may correspond to multiple entity categories at the same time. For example, the word "Beijing" can correspond to both the entity category: dimension and the entity category: dimension value. We usually call such words confusing words.
[0064] It should be noted that when each candidate word of each query word includes a confusing word, multiple entity categories corresponding to the confusing word may be displayed to the user, and then the final entity category of the confusing word is determined according to the user's selection instruction.
[0065] Step 208 , selecting target candidate words from the candidate words based at least on the entity categories corresponding to the candidate words of the query words.
[0066] Specifically, each candidate word may be deduplicated first, and then, for any first candidate word among the deduplicated candidate words, an entity category sequence is formed based on the basic entity category and the target entity category of the first candidate word. The entity category sequence is verified using a regular expression, and if the verification passes, the first candidate word is used as a target candidate word.
[0067] Taking the aforementioned natural language query content of "yesterday's cities" as an example, as mentioned above, the basic entity categories obtained after entity recognition are: time and dimension. Assuming that the first candidate word mentioned above is: "payment amount" and the corresponding entity category is: dimension, then the entity category sequence formed can be: {time, dimension, dimension}.
[0068] In addition, the above regular expression is a pattern used to describe a set of string features, which is used to match a specific string. The pattern description is performed through special characters + ordinary characters to achieve the purpose of text matching.
[0069] The special characters mentioned above may include but are not limited to “\”, “.”, “*”, and “{}”, etc., and the common characters mentioned above may be English characters representing various entity categories.
[0070] In one example, the above-mentioned use of regular expressions to verify the entity category sequence may include: inputting the entity category sequence into the state machine corresponding to the regular expression and performing state migration; the state migration includes: comparing the current entity category in the entity category sequence with the labeled entity category corresponding to the migration edge of the current state, if they are consistent, migrating to the next state and updating the current entity category, otherwise ending. After the state migration ends, if the state of the state machine is a matching state, the verification passes, otherwise the verification fails.
[0071] Figure 4a A state machine diagram according to one embodiment is shown. Figure 4a In the example, the state machine can be converted based on the regular expression "a(bb)+a", where a and b represent two different entity categories. Figure 4a S0-S4 in the figure are the five states of the state machine, and S4 is the matching state. In addition, the one-way arrow from each state represents the transition edge of the state, and the characters above or below the one-way arrow represent the calibrated entity category of the corresponding transition edge. For example, the calibrated entity category of the transition edge of state S0 is: "a".
[0072] The following combination Figure 4a , the above state transition process is explained.
[0073] Assuming that the entity category sequence (hereinafter referred to as the sequence) is: abbbba, then first take the first a in the sequence as the current entity category, and take state S0 as the current state. Since the first a matches the labeled entity category of the migration edge of state S0: "a", it migrates to the next state S1, that is, state S1 is taken as the updated current state, and the first b in the sequence is taken as the updated current entity category, and then the first b is matched with the labeled entity category of the migration edge of state S1: "b", and so on, until the migration end condition is met. This migration end condition includes but is not limited to a match failure or all entity categories in the sequence are matched.
[0074] In this example, after all entity categories in the sequence are matched, state S4 can be reached, so that the above sequence verification passes.
[0075] It should be understood that Figure 4a This is just an exemplary description. In actual applications, there may be multiple state transition edges. For example, the state machine described in the embodiment of this specification may also be as follows: Figure 4b shown.
[0076] In the above example where the natural language query content is "payments in various cities yesterday", the selected target candidate words may be, for example, "payment amount", "number of payments" and "number of people who paid".
[0077] It should be noted that the regular expression described in this specification can be written based on the conventional combination of entity categories. Therefore, the target candidate words screened based on the regular expression are more closely related to the user's natural language query content, thereby solving the problem that the completion content is irrelevant to the natural language query content, thereby saving computing resources.
[0078] Step 210: Determine the completion content of the natural language query content according to each target candidate word.
[0079] In one example, each target candidate word may be sorted according to a sorting algorithm, and then each sorted target candidate word is determined as the completion content of the natural language query content.
[0080] The above-mentioned sorting algorithm may include any one of the following: longest match algorithm, state priority algorithm, dictionary cardinality algorithm, word combination heat algorithm, custom priority algorithm and word frequency algorithm.
[0081] In addition, it should be noted that the completion content of this solution can change as the cursor moves. For example, when it is detected that the cursor is located in the middle of the natural language query content, the content of the natural language query up to the middle position is used as the updated natural language query content. The updated natural language query content is completed. Thus, the completion method of this solution is more flexible.
[0082] Among them, the method for completing the updated natural language query content can also be implemented through steps 202 - 210, which will not be elaborated in this specification.
[0083] For example, assume that the natural language query content currently input by the user is: "Payment pens in each city". Then, first, the natural language query content can be completed. After that, when the cursor moves between "payment" and "pens", then "Payment in each city" is completed.
[0084] In summary, the method for automatically completing query content provided by the embodiments of this specification can obtain candidate words as completion content based on entity categories. Since there are regular combination methods between entity categories, the method of selecting candidate words based on entity categories in this solution can solve the problem that the completion content is not relevant to the natural language query content. In addition, in this solution, the candidate words are used as the completion content, that is, the natural language query content can be completed at the word granularity, thereby improving the accuracy of the completion content and further improving the user experience.
[0085] Corresponding to the above method for automatically completing query content, an embodiment of this specification also provides an apparatus for automatically completing query content, as Figure 5 shown. The apparatus may include:
[0086] An obtaining unit 502, configured to obtain the natural language query content input by the user currently for target data.
[0087] A splitting unit 504, configured to split the natural language query content to obtain a number of query words.
[0088] A query unit 506, configured to use the number of query words as the current query words, query a number of dictionary trees corresponding to different entity categories to obtain candidate words corresponding to each query word for multiple entity categories, and the number of dictionary trees are pre - constructed according to data queries for target data.
[0089] Among them, the above entity categories include at least one of the following: time, operator, unit, function, intention, dimension, dimension value, and metric, etc.
[0090] Optionally, the plurality of dictionary trees include a first dictionary tree corresponding to the first entity category, the first dictionary tree including a prefix tree and a suffix tree. The prefix tree is constructed based on at least part of the characters of each entity word of the first entity category starting from the beginning, and the suffix tree is constructed based on at least part of the characters of each entity word of the first entity category ending at the end;
[0091] The query unit 506 is specifically used for:
[0092] Taking the current query word as a prefix word, querying the prefix tree, and obtaining the first entity word of the first entity category of the current query word; taking the current query word as a suffix word, querying the suffix tree, and obtaining the second entity word of the first entity category of the current query word;
[0093] The first entity word and the second entity word constitute candidate words of the first entity category of the current query word.
[0094] Optionally, the plurality of dictionary trees include a first dictionary tree corresponding to a first entity category, the first dictionary tree includes a plurality of branches, each inter-node path in each branch corresponds to at least part of the characters in the represented entity word, and the value of the leaf node is the represented entity word;
[0095] The query unit 506 is specifically used for:
[0096] The current query word is matched word by word with each branch in the first dictionary tree in turn. If the word covered by any first branch contains the current query word, the value of the leaf node of the first branch is used as a candidate word of the first entity category of the current query word.
[0097] The selection unit 508 is configured to select target candidate words from the candidate words based at least on the entity categories corresponding to the candidate words of the query words.
[0098] The determination unit 510 is used to determine the completion content of the natural language query content according to each target candidate word.
[0099] Optionally, the device further comprises:
[0100] The recognition unit 512 is used to perform entity recognition on the natural language query content to obtain the corresponding basic entity category.
[0101] The selection unit 508 includes:
[0102] The forming module 5082 is used to form an entity category sequence for any first candidate word among the candidate words based on the basic entity category and the target entity category of the first candidate word.
[0103] The verification module 5084 is used to verify the entity category sequence using a regular expression. If the verification passes, the first candidate word is used as a target candidate word.
[0104] The verification module 5084 is specifically used for:
[0105] Inputting the entity category sequence into the state machine corresponding to the regular expression and performing state migration, the state migration includes: comparing the current entity category in the entity category sequence with the labeled entity category corresponding to the migration edge of the current state, if they are consistent, migrating to the next state and updating the current entity category; otherwise ending;
[0106] After the state transition is completed, if the state of the state machine is a matching state, the verification passes, otherwise the verification fails.
[0107] Optionally, the device further comprises:
[0108] The sorting unit 514 is used to sort the target candidate words according to the sorting algorithm.
[0109] The determining unit 510 is specifically configured to:
[0110] Determine the ranked target candidate words as the completion content of the natural language query content;
[0111] The above-mentioned sorting algorithms include any one of the following: longest match algorithm, state priority algorithm, dictionary cardinality algorithm, word combination heat algorithm, custom priority algorithm and word frequency algorithm.
[0112] Optionally, the device further includes: a completion unit 516;
[0113] The acquisition unit 502 is further configured to, when it is detected that the cursor is located at the middle position of the natural language query content, use the content up to the middle position in the natural language query content as the updated natural language query content;
[0114] The completion unit 516 is used to complete the updated natural language query content.
[0115] The functions of the functional modules of the device in the above-mentioned embodiment of this specification can be implemented through the steps of the above-mentioned method embodiment. Therefore, the specific working process of the device provided by one embodiment of this specification will not be repeated here.
[0116] An apparatus for automatically completing query content provided by an embodiment of the present specification can provide accuracy of completed content.
[0117] According to another embodiment, there is also provided a computer-readable storage medium having a computer program stored thereon, which, when executed in a computer, causes the computer to execute a combination of Figure 2 The method described.
[0118] According to another embodiment of the present invention, a computing device is provided, including a memory and a processor, wherein the memory stores executable code, and when the processor executes the executable code, the Figure 2 The method described.
[0119] Each embodiment in this specification is described in a progressive manner, and the same or similar parts between the embodiments can be referred to each other, and each embodiment focuses on the differences from other embodiments. In particular, for the device embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiment.
[0120] The steps of the method or algorithm described in conjunction with the disclosure of this specification can be implemented in hardware or by a processor executing software instructions. The software instructions can be composed of corresponding software modules, and the software modules can be stored in RAM memory, flash memory, ROM memory, EPROM memory, EEPROM memory, register, hard disk, mobile hard disk, CD-ROM or any other form of storage medium known in the art. An exemplary storage medium is coupled to the processor so that the processor can read information from the storage medium and write information to the storage medium. Of course, the storage medium can also be a component of the processor. The processor and the storage medium can be located in an ASIC. In addition, the ASIC can be located in a server. Of course, the processor and the storage medium can also be present in the server as discrete components.
[0121] Those skilled in the art will appreciate that in one or more of the above examples, the functions described in the present invention may be implemented in hardware, software, firmware, or any combination thereof. When implemented using software, the functions may be stored in a computer-readable medium or transmitted as one or more instructions or codes on a computer-readable medium. Computer-readable media include computer storage media and communication media, wherein communication media include any media that facilitates the transmission of a computer program from one place to another. The storage medium may be any available medium that a general or special-purpose computer can access.
[0122] The above is a description of a specific embodiment of the specification. Other embodiments are within the scope of the appended claims. In some cases, the actions or steps recorded in the claims can be performed in an order different from that in the embodiments and still achieve the desired results. In addition, the processes depicted in the drawings do not necessarily require the specific order or continuous order shown to achieve the desired results. In some embodiments, multitasking and parallel processing are also possible or may be advantageous.
[0123] The specific implementation methods described above further illustrate the purpose, technical solutions and beneficial effects of this specification. It should be understood that the above description is only the specific implementation method of this specification and is not intended to limit the protection scope of this specification. Any modifications, equivalent substitutions, improvements, etc. made on the basis of the technical solutions of this specification should be included in the protection scope of this specification.
Claims
1. A method for automatically completing query content, comprising: Obtain the natural language query content currently input by the user for the target data; Segmenting the natural language query content to obtain a number of query words; The plurality of query words are respectively used as current query words, and multiple dictionary trees corresponding to multiple entity categories are queried for the current query words to obtain candidate words corresponding to the multiple entity categories for the current query words; the multiple dictionary trees are pre-built according to historical natural language queries for the target data; At least based on the entity categories corresponding to the candidate words of each query word, select each target candidate word from the candidate words; According to the target candidate words, the completion content of the natural language query content is determined, and the completion content is used to prompt the user for content that may be desired to input later.
2. The method according to claim 1, wherein: The multiple dictionary trees include a first dictionary tree corresponding to a first entity category; the first dictionary tree includes a prefix tree and a suffix tree; the prefix tree is constructed based on at least part of the characters of each entity word of the first entity category starting from the beginning; The suffix tree is constructed based on at least part of the characters up to the end of each entity word of the first entity category; The query corresponds to a plurality of dictionary trees of a plurality of entity categories, respectively, including: Taking the current query word as a prefix word, querying the prefix tree, and obtaining a first entity word of a first entity category of the current query word; and taking the current query word as a suffix word, querying the suffix tree, and obtaining a second entity word of the first entity category of the current query word; The first entity word and the second entity word constitute candidate words of the first entity category of the current query word.
3. The method according to claim 1, wherein: The multiple dictionary trees include a first dictionary tree corresponding to a first entity category, the first dictionary tree includes multiple branches, each node path in each branch corresponds to at least part of the characters in the represented entity word, and the value of the leaf node is the represented entity word; The query corresponds to a plurality of dictionary trees of a plurality of entity categories, respectively, including: The current query word is matched with each branch in the first dictionary tree word by word in turn. If the word covered by any first branch contains the current query word, the value of the leaf node of the first branch is used as a candidate word of the first entity category of the current query word.
4. The method according to claim 1, wherein: Before segmenting the natural language query content, the method further includes: Performing entity recognition on the natural language query content to obtain corresponding basic entity categories; The step of selecting a target candidate word from the candidate words includes: For any first candidate word among the candidate words, forming an entity category sequence based on the basic entity category and the target entity category of the first candidate word; The entity category sequence is verified using a regular expression, and if the verification passes, the first candidate word is used as a target candidate word.
5. The method according to claim 4, wherein: The verifying the entity category sequence includes: Input the entity category sequence into the state machine corresponding to the regular expression, and perform state migration; the state migration includes: comparing the current entity category in the entity category sequence with the labeled entity category corresponding to the migration edge of the current state, if they are consistent, migrate to the next state and update the current entity category; otherwise end; After the state migration is completed, if the state of the state machine is a matching state, the verification passes, otherwise the verification fails.
6. The method according to claim 1, wherein: Before determining each target candidate word as a completion content of the natural language query content, the method further includes: Sorting the target candidate words according to a sorting algorithm; Determine the sorted target candidate words as the completion content of the natural language query content; The sorting algorithm includes any one of the following: longest match algorithm, state priority algorithm, dictionary cardinality algorithm, word combination heat algorithm, custom priority algorithm and word usage frequency algorithm.
7. The method according to claim 1, further comprising: When it is detected that the cursor is located at the middle position of the natural language query content, the content up to the middle position in the natural language query content is used as the updated natural language query content; The updated natural language query content is completed.
8. The method according to claim 1, wherein: The entity category includes at least one of: time, operator, unit, function, intent, dimension, dimension value, and measure.
9. A device for automatically completing query content, comprising: An acquisition unit, used to acquire natural language query content currently input by the user for target data; A segmentation unit, used to segment the natural language query content to obtain a number of query words; A query unit, configured to use the plurality of query words as current query words respectively, and query a plurality of dictionary trees corresponding to a plurality of entity categories respectively for the current query words, so as to obtain candidate words corresponding to the plurality of entity categories for the current query words; the plurality of dictionary trees are pre-constructed according to historical natural language queries for the target data; A selection unit, configured to select target candidate words from the candidate words based at least on the entity categories corresponding to the candidate words of the query words; The determination unit is used to determine the completion content of the natural language query content according to the target candidate words, and the completion content is used to prompt the user for the content that he may want to input later.
10. The device according to claim 9, wherein: The multiple dictionary trees include a first dictionary tree corresponding to a first entity category; the first dictionary tree includes a prefix tree and a suffix tree; the prefix tree is constructed based on at least part of the characters of each entity word of the first entity category starting from the beginning; the suffix tree is constructed based on at least part of the characters of each entity word of the first entity category ending at the end; The query unit is specifically used for: Taking the current query word as a prefix word, querying the prefix tree, and obtaining a first entity word of a first entity category of the current query word; and taking the current query word as a suffix word, querying the suffix tree, and obtaining a second entity word of the first entity category of the current query word; The first entity word and the second entity word constitute candidate words of the first entity category of the current query word.
11. The device according to claim 9, wherein: The multiple dictionary trees include a first dictionary tree corresponding to a first entity category, the first dictionary tree includes multiple branches, each node path in each branch corresponds to at least part of the characters in the represented entity word, and the value of the leaf node is the represented entity word; The query unit is specifically used for: The current query word is matched with each branch in the first dictionary tree word by word in turn. If the word covered by any first branch contains the current query word, the value of the leaf node of the first branch is used as a candidate word of the first entity category of the current query word.
12. The apparatus according to claim 9, further comprising: An identification unit, configured to perform entity identification on the natural language query content to obtain a corresponding basic entity category; The selection unit comprises: A forming module, configured to form an entity category sequence for any first candidate word among the candidate words based on the basic entity category and the target entity category of the first candidate word; The verification module is used to verify the entity category sequence using a regular expression, and if the verification passes, the first candidate word is used as a target candidate word.
13. The device according to claim 12, wherein: The verification module is specifically used for: Input the entity category sequence into the state machine corresponding to the regular expression, and perform state migration; the state migration includes: comparing the current entity category in the entity category sequence with the labeled entity category corresponding to the migration edge of the current state, if they are consistent, migrate to the next state and update the current entity category; otherwise end; After the state migration is completed, if the state of the state machine is a matching state, the verification passes, otherwise the verification fails.
14. The apparatus according to claim 9, further comprising: A sorting unit, used to sort the target candidate words according to a sorting algorithm; The determining unit is specifically used for: Determine the sorted target candidate words as the completion content of the natural language query content; The sorting algorithm includes any one of the following: longest match algorithm, state priority algorithm, dictionary cardinality algorithm, word combination heat algorithm, custom priority algorithm and word usage frequency algorithm.
15. The apparatus according to claim 9, further comprising: Complete the unit; The acquisition unit is further configured to, when detecting that the cursor is located at a middle position of the natural language query content, use the content of the natural language query content up to the middle position as the updated natural language query content; The completion unit is used to complete the updated natural language query content.
16. The device according to claim 9, wherein: The entity category includes at least one of: time, operator, unit, function, intent, dimension, dimension value, and measure.
17. A computer-readable storage medium having a computer program stored thereon, wherein: When the computer program is executed in a computer, the computer is caused to execute the method according to any one of claims 1 to 8.
18. A computing device comprising a memory and a processor, wherein: The memory stores executable codes, and when the processor executes the executable codes, the method according to any one of claims 1 to 8 is implemented.
Citation Information
Patent Citations
Query method and device, text processing method and device, electronic equipment and storage medium
CN111063447A