Data query method, device and program product
By analyzing natural query statements to generate structured information and performing query tasks, the problem of low query accuracy caused by inaccurate recognition of natural query language in the prior art is solved, and higher query accuracy is achieved.
Patent Information
- Application Number
- CN202411696792.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-22
- Publication Date
- 2025-03-28
AI Technical Summary
When existing data query systems face complex, fuzzy or ambiguity query statements, their recognition of natural query language is not accurate enough, resulting in the generated structured query statements that cannot accurately reflect the user's real query needs, thus affecting the accuracy of the query.
A data query method is proposed to generate structured information by analyzing the natural query statements entered by the user, including query intention information and query word information. If this information meets the preset query conditions, a structure query statement is generated and a query task is executed to obtain the query results.
By accurately capturing the user's real query needs, query errors caused by natural language ambiguity are reduced and the accuracy of the query is enhanced.
Smart Images

Figure CN119719333A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of data processing technology, and in particular to a data query method, device and program product. Background Art
[0002] In the era of information explosion, data has become an important basis for decision-making in enterprises and organizations. In order to extract valuable information from massive data, the query system plays a vital role. However, traditional query systems usually require users to have a certain technical background and be able to write structured query statements. In order to lower the threshold for data query, some systems have begun to support natural language-based query interfaces. These systems attempt to convert natural query statements entered by users into structured information, and then generate structured query statements to perform data query tasks. However, when faced with complex, ambiguous or ambiguous query statements, current data query systems are not accurate enough in recognizing natural query language, resulting in the generated structured query statements being unable to accurately reflect the user's actual query needs, thereby affecting the accuracy of the query.
[0003] The above contents are only used to assist in understanding the technical solution of the present application and do not constitute an admission that the above contents are prior art. Summary of the invention
[0004] The main purpose of this application is to provide a data query method, device and program product, aiming to solve the technical problem of low accuracy of data query.
[0005] To achieve the above purpose, the present application proposes a data query method, which includes: Generate structured information based on the natural query sentence input by the user, wherein the structured information includes query intent information and query term information; If the query intention information and the query term information both meet the preset query conditions, generating a structured query statement based on the structured information; A query task is executed based on the structured query statement to obtain a query result.
[0006] In one embodiment, the query intent information includes an intent tag, and the step of generating structured information based on a natural query sentence input by a user includes: Determining a vector representation of the natural query sentence; Input the vector representation into a preset intent recognition model, wherein the intent recognition model is used to determine the degree of association between the input vector representation and the intent label, and determine the intent label corresponding to the vector representation according to the degree of association; Obtain the intent label output by the intent recognition model.
[0007] In one embodiment, the query term information includes entity words and relationship triples corresponding to the entity words, and the step of generating structured information based on the natural query sentence input by the user further includes: Splitting the natural query into word sequences; Inputting the word sequence into a preset entity recognition model, wherein the entity recognition model is used to determine a sequence label of the word sequence, so as to determine the entity words in the natural query sentence according to the sequence label; The entity words output by the entity recognition model are obtained, and based on the entity words, the relationship triples between entities are determined, where the relationship triples include two entity words and a logical relationship between the two entity words.
[0008] In one embodiment, the query term information further includes a semantic tag and a semantic structure diagram, and the step of generating structured information based on the natural query sentence input by the user further includes: Based on the query terms in the natural query sentence, determining semantic tags corresponding to the query terms; Based on the relationship triples, the query terms and semantic labels corresponding to the query terms, a semantic structure graph of the natural query sentence is determined.
[0009] In one embodiment, after the step of determining the semantic tag corresponding to the query term based on the query term in the natural query sentence, the method further includes: Based on the semantic tag, determining whether there is a pronoun in the query term; If there is a pronoun in the query term, the antecedent corresponding to the pronoun is determined based on the historical conversation record, and the pronoun is replaced with the corresponding antecedent.
[0010] In one embodiment, if both the query intent information and the query term information satisfy the preset query condition, before the step of generating a structured query statement based on the structured information, the step further includes: Determine the number of the intent tags corresponding to the natural query statement; If the number of the intent tags is less than or equal to the preset tag threshold, it is determined that the query intent information meets the preset query condition; Obtaining the confidence parameter of the entity word output by the entity recognition model; If the confidence parameter of the entity word is greater than or equal to a preset confidence threshold, and the number of the antecedent words corresponding to the pronoun is less than or equal to a preset number threshold, it is determined that the query term information meets the preset query condition.
[0011] In one embodiment, the method further comprises: If the query intention information does not meet the preset query condition, or the query term information does not meet the preset query condition, output query confirmation information; A natural query sentence re-entered by the user based on the query confirmation information is obtained, and the step of generating structured information based on the natural query sentence input by the user is performed.
[0012] In one embodiment, after the step of executing the query task based on the structured query statement to obtain the query result, the step further includes: Determine a visualization chart template based on the intent tag; A visualization report is generated based on the query result and the visualization chart template.
[0013] In addition, to achieve the above objectives, the present application also proposes a data query device, which includes: a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the computer program is configured to implement the steps of the data query method described above.
[0014] In addition, to achieve the above-mentioned purpose, the present application also provides a computer program product, which includes a computer program, and when the computer program is executed by a processor, the steps of the data query method described above are implemented.
[0015] The present application provides a data query method, which generates structured information based on a natural query statement input by a user, wherein the structured information includes query intent information and query word information. If both the query intent information and the query word information meet the preset query conditions, a structured query statement is generated based on the structured information; then the query task is executed based on the structured query statement to obtain the query result. The above method extracts the query intent information and the query word information by parsing the natural query statement input by the user, accurately captures the user's real query needs, and executes the data query task when the information meets the preset query conditions, thereby reducing query errors caused by the ambiguity of natural language and enhancing the accuracy of the query. BRIEF DESCRIPTION OF THE DRAWINGS
[0016] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present application and, together with the description, serve to explain the principles of the present application.
[0017] In order to more clearly illustrate the technical solutions in the embodiments of the present application or the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, for ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative labor.
[0018] Figure 1 A flowchart of the first embodiment of the data query method of this application is provided; Figure 2 A flowchart of the second embodiment of the data query method of this application is provided; Figure 3 A flowchart of the third embodiment of the data query method of this application is provided; Figure 4 A flowchart of the fourth embodiment of the data query method of this application is provided; Figure 5 A flowchart of the fifth embodiment of the data query method of this application is provided; Figure 6 A flowchart of the sixth embodiment of the data query method of this application is provided; Figure 7 A flowchart of the seventh embodiment of the data query method of this application is provided; Figure 8 A flowchart of the eighth embodiment of the data query method of the present application is provided; Fig. 9 A brief flowchart of the data query method in the embodiment of the present application; Fig.10 This is a schematic diagram of the data query system architecture involved in the data query method in the embodiment of the present application; Fig.11 A timing diagram of a data query system involved in a data query method in an embodiment of the present application; Fig.12 Schematic diagram of the device structure of the hardware operating environment involved in the data query method in the embodiment of the present application.
[0019] The purpose, features and advantages of this application will be further described in conjunction with the embodiments and with reference to the accompanying drawings. DETAILED DESCRIPTION
[0020] It should be understood that the specific embodiments described herein are only used to explain the technical solutions of the present application and are not used to limit the present application.
[0021] In order to better understand the technical solution of the present application, a detailed description will be given below in conjunction with the accompanying drawings and specific implementation methods.
[0022] In the era of information explosion, data has become an important basis for decision-making in enterprises and organizations. In order to extract valuable information from massive data, the query system plays a vital role. However, traditional query systems usually require users to have a certain technical background and be able to write structured query statements. In order to lower the threshold for data query, some systems have begun to support natural language-based query interfaces. These systems attempt to convert the natural query statements entered by users into structured information, and then generate structured query statements to perform data query tasks. However, when faced with complex, ambiguous or ambiguous query statements, the current data query system does not accurately recognize natural query language, resulting in the generated structured query statements being unable to accurately reflect the user's actual query needs, thereby affecting the accuracy of the query results.
[0023] In view of the above problems, the present application proposes a data query method, which generates structured information based on the natural query statement input by the user, wherein the structured information includes query intent information and query word information. If the query intent information and the query word information both meet the preset query conditions, a structured query statement is generated based on the structured information, and then the query task is executed based on the structured query statement to obtain the query result. The above method extracts the query intent information and the query word information by parsing the natural query statement input by the user, accurately captures the user's real query needs, and executes the data query task when this information meets the preset query conditions, thereby reducing query errors caused by the ambiguity of natural language and enhancing the accuracy of the query.
[0024] It should be noted that the execution subject of this embodiment can be a computing service device with data processing, network communication and program running functions, such as a tablet computer, a personal computer, a mobile phone, etc., or an electronic device capable of realizing the above functions, etc. The following takes a data query system as an example to illustrate this embodiment and the following embodiments.
[0025] Based on this, the first embodiment proposed in this application provides a data query method, referring to Figure 1 In this embodiment, the data query method includes steps S10 to S30: Step S10, generating structured information based on the natural query sentence input by the user, wherein the structured information includes query intent information and query term information.
[0026] It should be noted that natural language query statements are query requests entered by users in natural language through the front-end user interface, such as "I want to find the products with the highest sales in 2023". Structured information refers to computer-understandable format information parsed from natural query statements, which usually includes the query intent, i.e. the operations that users want to perform, such as "search", "sort", etc. Structured information also includes specific query terms, i.e. the specific data or conditions mentioned by users, such as "2023", "sales", etc.
[0027] Exemplarily, a user inputs a natural language query statement through an interface, such as "I want to find the product with the highest sales last year". The user input is preprocessed, including removing irrelevant characters such as punctuation marks, spaces, etc., converting to a unified format such as lowercase processing, etc. Natural language processing (NLP) is used to parse the user input. For example, the sentence input by the user is split into independent words or phrases, such as "I / want / to / find / the / product / with / the / highest / sales / last / year", and each word is labeled with its part of speech, such as noun, verb, adjective, etc., which helps to understand the function and role of the word in the sentence, and identify and label the named entities in the sentence, such as the time "last year" and the product name "product".
[0028] Optionally, the intent of the user query is identified based on the parsed words and part-of-speech information combined with a predefined intent library. The intent library is a predefined and constructed collection that contains various intents or operations related to the user query. These intents are usually expressed in natural language, but they are standardized and structured in the intent library so that the computer can understand and process them. The intent library includes intent names to identify and distinguish different intents; it can also include a detailed description of the intent, and some attribute information related to the intent or phrases, such as time, place, value, etc., to further refine the user's query needs.
[0029] Exemplarily, a large number of natural language query statements are collected from various sources such as user query logs, online forums, social media, etc. The collected query statements are preprocessed, including removing irrelevant characters, word segmentation, part-of-speech tagging, etc., and the intent of each query statement is identified through manual annotation or machine learning algorithms. The identified intents are summarized and sorted to form a standardized intent set, and the summarized intent set is stored in the intent library, which is regularly updated and maintained.
[0030] Optionally, key information related to the query, such as time, value, product name, etc., is extracted from the parsed words, and the identified intent and extracted word information are represented in the form of key-value pairs and combined into structured information, where the key represents the intent or attribute name, and the value represents the corresponding word or value, so that subsequent steps can easily process and use this information.
[0031] Step S20: If the query intention information and the query term information both meet the preset query conditions, a structured query statement is generated based on the structured information.
[0032] It should be noted that the preset query conditions are used to determine whether the user input is legal or meets specific rules or conditions, and to check whether the intentions and words in the structured information meet the preset query conditions such as format, data type, logical relationship, etc. Structured query statements are generated based on structured information and are used for query statements executed by databases or search engines, such as SQL (Structured Query Language) statements.
[0033] Optionally, according to a preset query template, the structured information is filled into the template to generate a query statement.
[0034] Exemplarily, different templates are first designed according to specific query scenarios and database structures. When generating a structured query statement, the most appropriate template is first selected from the template library according to the user's query intent. Then, based on the user's natural query term information, the natural query statement is converted into a data type, the format is adjusted, and other operations are performed. The specific query value is filled into the corresponding position of the template to generate a query statement that meets the grammatical requirements of the database.
[0035] Optionally, the logical structure and parameters of the query statement are dynamically constructed according to the specific content of the structured information.
[0036] Exemplarily, based on the result of intent recognition, the query type is determined, such as SELECT query, INSERT query, UPDATE query, etc., and based on the entity and part-of-speech tagging results in the user query, the database field to be queried is determined, and based on the comparison words in the user query, such as greater than, less than, equal to, etc. and values, the query condition is constructed. The query type, query field, query condition, etc. constructed above are spliced into a complete query statement.
[0037] Step S30, executing a query task based on the structured query statement to obtain a query result.
[0038] Submit the structured query statement to the database or search engine for execution, receive the query results returned by the database or search engine, and format the query results to conform to the user's expected display method.
[0039] In this embodiment, the natural language input by the user is preprocessed and parsed by NLP to identify the query intention and query terms. By matching with the predefined intention library, the user's query intention is determined, and relevant key information is extracted. According to this structured information, a structured query statement that meets the database query requirements is generated, improving the accuracy and efficiency of the query, enabling the user to interact with the database in the form of natural language, and at the same time ensuring the accuracy and reliability of the query results.
[0040] Based on the first embodiment of this application, in the second embodiment of this application, the same or similar content as in the above-mentioned first embodiment can be referred to the above introduction and will not be repeated hereinafter. On this basis, the query intention information includes intention tags, please refer to Figure 2 , step S10 includes steps S11 to S13: Step S11, determining the vector representation of the natural query statement.
[0041] Convert the natural language text into a mathematical vector form for computer processing. Exemplarily, perform word segmentation, stop word removal, stemming, etc. on the natural query statement to extract key information. According to the preprocessed text, extract features that can represent the text content, such as the bag-of-words model, TF-IDF (Term Frequency-Inverse Document Frequency), word embeddings such as Word2Vec, BERT (Bidirectional Encoder Representations from Transformers), etc., and convert the extracted features into vector form.
[0042] Optionally, based on the bag-of-words model, each word in the text is regarded as a feature, and the number of times each word appears in the text is counted to construct a sparse vector.
[0043] Exemplarily, first use a word segmentation tool such as jieba to split the natural query statement into individual words or phrases, and remove stop words, that is, those words that contribute little to the text meaning but appear frequently, such as "de", "shi", etc. Traverse all the segmented text, count the number of times each word appears, construct a bag-of-words containing all non-repeated words and their occurrence times, and for each text, generate a sparse vector according to the words in the bag-of-words and their occurrence times. The dimension of the vector is equal to the number of words in the bag-of-words, and the value of each dimension corresponds to the number of times the word appears in the text.
[0044] Optionally, based on TF-IDF, on the basis of the bag-of-words model, consider the importance of the word, that is, the term frequency-inverse document frequency, and perform weighted processing on the word.
[0045] Exemplarily, after splitting the natural query into single words or phrases and removing stop words, for each text, calculate the term frequency (TF) of each word, that is, the number of times the word appears in the text divided by the total number of words in the text. Traverse all texts and calculate the inverse document frequency (IDF) of each word, that is, the number of all texts divided by the number of texts containing the word, then take the logarithm, multiply the TF value of each word by the IDF value, and get the TF-IDF value of the word. Based on the TF-IDF value, generate a vector for each text. The dimension of the vector is equal to the number of words in the bag of words, and the value of each dimension corresponds to the TF-IDF value of the word.
[0046] Optionally, based on the vector representation of word embeddings, words are converted into dense vectors to capture the semantic relationship between words.
[0047] For example, the natural query sentences are first segmented and preprocessed by removing stop words. A large amount of unlabeled text data is used to train the word embedding model. During the training process, the word embedding model will learn the vector representation of each word, and these vectors can capture the semantic relationship between words. For each text, each word in the text is replaced with its vector representation learned in the word embedding model. Among them, average pooling, weighted average pooling, maximum pooling and other methods can be used to combine the vectors of all words in the text into a vector representation of a fixed dimension.
[0048] Step S12, inputting the vector representation into a preset intention recognition model, wherein the intention recognition model is used to determine the degree of association between the input vector representation and the intention label, and determining the intention label corresponding to the vector representation according to the degree of association.
[0049] Step S13, obtaining the intent label output by the intent recognition model.
[0050] It should be noted that the intent recognition model is a trained machine learning or deep learning model used to identify the intent of a user query. The intent label represents the identifier of the user's query intent and can be a string or a numeric code.
[0051] Optionally, according to the application scenario and data characteristics, select a suitable intent recognition model, such as support vector machine (SVM), naive Bayes (NB), convolutional neural network (CNN), recurrent neural network (RNN), etc., use labeled training data, that is, query statements with known intent and their corresponding intent labels to train the model, input the vector representation of the query statement to be recognized into the trained model, and the model outputs the predicted intent label.
[0052] Optionally, the intent recognition model processes the input query sentence vector representation and outputs one or more intent labels. According to the output of the model, the intent label is parsed. If the model outputs a probability distribution, the label with the highest probability can be selected as the final intent label.
[0053] Optionally, a query statement is allowed to have multiple intent labels, and the intent recognition model can output a label set, or organize the intent labels into a hierarchy and output a path or subtree to represent the intent of the query statement.
[0054] For example, suppose a user enters a query: "I want to find a smartphone priced between 500 and 1,000 yuan." First, the query is preprocessed, including word segmentation, stop word removal, etc. The preprocessed query is then converted into a vector representation and input into the intent recognition model. The intent recognition model searches and matches the intent labels in the hierarchy based on the input vector representation, and finally outputs a path or subtree to represent the recognized intent, such as "user intent -> search intent -> product search -> search by price range".
[0055] Optionally, determine the vector representation of the natural query sentence, use the vector representation as the input sequence data of the intent recognition model, and map the vector representation to the output node of the intent label through the classification layer of the intent recognition model, wherein each intent label corresponds to an output node. Obtain the output value of the output node, the output value represents the degree of association between the vector representation and the corresponding intent label, and if the output value of the output node is greater than a preset threshold, obtain the corresponding intent label output by the intent recognition model.
[0056] Exemplarily, a pre-trained intent recognition model is loaded, and the vector representation is used as the input of the intent recognition model. After the natural query statement is tokenized into a series of words or subword units, these words or subword units are converted into vector form, and each word or subword unit is mapped to a vector space of fixed dimension, so that the entire query statement can be represented as a two-dimensional array or matrix, in which each row is a vector representation of a word. This two-dimensional array or matrix is input into the intent recognition model, and in the last layer of the intent recognition model, such as the fully connected layer or the softmax layer, each intent label has a corresponding output node. The intent recognition model maps the input sequence to these output nodes by calculating the similarity or probability distribution between the input sequence and each intent label. For each output node, the intent recognition model outputs a value indicating the degree of association between the input sequence and the intent label. These values are normalized so that the sum of the probabilities of all intent labels is equal to 1. Then, these values are compared with a preset threshold. If the output value of a certain intent label is greater than or equal to this threshold, then the label is considered to be the intent predicted by the intent recognition model.
[0057] In this embodiment, key query terms are extracted through preprocessing steps such as word segmentation, stop word removal, and stem extraction, and then the text is converted into mathematical vectors. These vectors can capture word frequency, inverse document frequency, and semantic relationships between words, providing rich features for the intent recognition model. Then, these vectors are input into the pre-trained intent recognition model, and a label representing the user's query intent is output. The user's natural language query is effectively converted into a computer-processable form, which improves the accuracy of intent recognition and can process complex query statements containing multiple intents, thereby improving the data query system's ability to understand user needs.
[0058] Based on the above embodiments of the present application, in the third embodiment of the present application, the same or similar contents as those in the above embodiments can be referred to the above introduction, and no further description will be given later. On this basis, the query term information includes entity words and relationship triples corresponding to the entity words, please refer to Figure 3 , step S10 includes steps S14 to S16: Step S14, splitting the natural query sentence into word sequences.
[0059] Step S15, inputting the word sequence into a preset entity recognition model, wherein the entity recognition model is used to determine a sequence label of the word sequence, so as to determine the entity words in the natural query sentence according to the sequence label.
[0060] It should be noted that the entity recognition model is used to identify entity words with specific meanings from the text of natural query sentences, such as names of people, places, organization names, time, numbers, etc.
[0061] Optionally, select a suitable entity recognition model, such as Conditional Random Fields (CRF), Hidden Markov Model (HMM), Long Short-Term Memory (LSTM) combined with attention mechanism, etc., and use the labeled training data, i.e. the text of known entity words and their corresponding entity labels, to train the model. Input the natural query sentence to be recognized into the trained model, and the model outputs the predicted entity words and their labels.
[0062] Alternatively, entity words in the text are identified based on manually defined rules and patterns, which is applicable to text in specific fields or specific formats. For example, suppose there is a simple rule set for identifying entity words in email addresses, namely usernames and domain names. It can be set that if the text contains the "@" symbol, the strings before and after it are regarded as usernames and domain names, respectively.
[0063] Optionally, the word sequence is used as input sequence data of the entity recognition model, and a sequence label is assigned to the word sequence through the entity recognition model, and the sequence label represents the entity type of the word sequence.
[0064] Exemplarily, the word sequence is converted into a format acceptable to the entity recognition model, such as a word embedding vector sequence, and these word embedding vector sequences are passed as input to the entity recognition model. The entity recognition model analyzes the input word sequence word by word and predicts the entity type corresponding to each word. The entity recognition model obtains a sequence label set, where each label corresponds to a word in the input sequence and represents the entity type to which the word belongs. The entity type to be found is found from the sequence label set, and the corresponding word is output to obtain the entity word.
[0065] Step S16, obtaining the entity words output by the entity recognition model, and determining the relationship triples between entities based on the entity words, wherein the relationship triples include two entity words and the logical relationship between the two entity words.
[0066] It should be noted that a relation triple is a structure consisting of two entity words and the logical relationship between them. After identifying the entity words, the logical relationship between the entity words is extracted from the text using relation extraction technology, and the identified entity words and logical relationships are combined into a relation triple.
[0067] Optionally, for content with relatively fixed relationship types and relatively consistent text formats, relationships in the text can be quickly identified through well-defined templates to simplify the relationship extraction process. For content with diverse relationship types and variable text formats, the accuracy and generalization of relationship extraction can be improved by training with a large amount of labeled data. For example, models such as SVM, CNN, RNN, etc. can be trained based on labeled relationship triples to learn the features and patterns of relationship extraction. For content with unknown relationship types or difficult to obtain labeled data, unlabeled data or external knowledge bases such as knowledge graphs can be used to mine relationships in the text based on unsupervised learning or remote supervision methods.
[0068] In this embodiment, entity recognition models such as conditional random fields, hidden Markov models, or long short-term memory networks are used to extract entity words with specific meanings, such as names of people and places. Based on these entity words, the relationship extraction technology is used to further determine the logical relationship between entities to form relationship triples, which can accurately extract key information from user queries and understand the complex relationship between entities, thereby providing rich contextual information for subsequent query processing and information retrieval. This method not only improves the accuracy of queries, but also enhances the data query system's in-depth understanding of user intent, making the response more in line with the user's actual needs.
[0069] Based on the above embodiments of the present application, in the fourth embodiment of the present application, the same or similar contents as those in the above embodiments can be referred to the above introduction, and no further description will be given later. On this basis, the query word information also includes semantic tags and semantic structure diagrams, please refer to Figure 4 , step S10 includes steps S17-S18: Step S17: determining a semantic tag corresponding to the query term based on the query term in the natural query sentence.
[0070] It should be noted that semantic tags are labels with specific meanings assigned to query terms, which are used to represent the semantic role or category of the term in a specific context. The purpose of determining semantic tags is to map the query terms input by the user to predefined semantic tags in order to better understand the intent and context of the query.
[0071] Exemplarily, a set of semantic tags is first defined. These tags should cover various semantic categories that may appear in the query, such as names of people, places, time, actions, attributes, etc. A semantic tag classification model is trained using the labeled data, i.e., query terms and their corresponding semantic tags. The query terms entered by the user are input into the trained model, and the model outputs the semantic label corresponding to each term.
[0072] Optionally, models such as CNN, RNN or Transformer are used for semantic label classification to automatically learn feature representations of text and map these feature representations to predefined semantic labels. These models can learn the deep semantic information of text from a large amount of unlabeled and labeled data, thereby improving the accuracy and generalization ability of semantic label classification.
[0073] Exemplarily, an annotated data set containing query terms and their corresponding semantic labels is collected, and the collected data is preprocessed, including word segmentation, stop word removal, stem extraction, word vector representation, etc. Next, select a suitable model based on the task requirements and data characteristics. For example, for text feature extraction, CNN, RNN, and Transformer can be selected; for short texts or content that requires fast feature extraction, CNN, which is good at processing local features, can be used, and RNN can be used to process sequence data to capture the temporal dependencies in the text. According to the selected model, define its network structure, including input layer, hidden layer, and output layer, etc., set the model's hyperparameters, such as learning rate, batch size, number of iterations, etc., input the preprocessed data into the model, and update the model parameters through the back propagation algorithm and optimization algorithm. During the model training process, the model will automatically learn the feature representation of the text, such as word vectors, sentence vectors, or higher-level text representations. After the model training is completed, the new query terms are input into the model, and the feature representation is mapped to the predefined semantic label through a fully connected layer or a softmax layer, where each node in the output layer represents a semantic label, and the output value of the node represents the probability that the query term belongs to the label.
[0074] Step S18, determining a semantic structure graph of the natural query sentence based on the relationship triples, the query terms and the semantic labels corresponding to the query terms.
[0075] It should be noted that the semantic structure diagram is a graphical representation method of entities, attributes, relationships and their hierarchical structures in a query statement, which can more intuitively understand the semantic content and structure of the query.
[0076] Exemplarily, the query terms are taken as nodes, and attributes are assigned to the nodes according to their corresponding semantic labels. Based on the relationship triples, the logical relationship between entity words is represented as the edge between nodes, and the direction of the edge can represent the direction of the relationship, such as from subject to object. The nodes and edges are combined into a semantic structure diagram to clearly display the entities, attributes, relationships and their hierarchical structures in the query statement. By constructing a semantic structure diagram, the semantic content and structure of the query can be understood more intuitively, which is helpful for subsequent query processing and result generation.
[0077] To better understand the solution provided in this example, this example is further explained in combination with specific application scenarios.
[0078] Suppose the natural query sentence entered by the user is: "Find which users over 30 years old have purchased mobile phone A." Among them, "age" is marked as an attribute label, "over 30 years old" is marked as an attribute value label, "user" is marked as an entity label, "purchase" is marked as an action label, and "iPhone" is marked as a product label. After that, nodes are created based on semantic labels: "age" (attribute), "over 30 years old" (attribute value), "user" (entity), "purchase" (action), "iPhone" (product). Then edges are created: "age" node points to "over 30 years old" node (indicating attribute-attribute value relationship), "user" node points to "purchase" node (indicating subject-action relationship), and "purchase" node points to "iPhone" node (indicating action-object relationship). Finally, the nodes and edges are combined into a semantic structure graph.
[0079] In this embodiment, by defining a semantic tag set and training a semantic tag classification model, query terms are mapped to predefined semantic categories, such as names of people, places, etc. Then, using relationship triples and semantic tags, a semantic structure graph is constructed, which graphically displays the entities, attributes, and relationships in the query statement, thereby improving the accuracy of semantic analysis of the query statement, making query processing more intuitive and structured, and helping to improve the relevance and accuracy of query results, thereby better meeting the query needs of users.
[0080] Based on the above embodiments of the present application, in the fifth embodiment of the present application, the same or similar contents as those in the above embodiments can be referred to the above introduction, and will not be described in detail later. Figure 5 After step S17, the data query method further includes steps S19 to S101: Step S19: determining whether there is a pronoun in the query term based on the semantic tag.
[0081] Step S101: If there is a pronoun in the query term, determine the antecedent corresponding to the pronoun based on the historical conversation record, and replace the pronoun with the corresponding antecedent.
[0082] It should be noted that pronouns refer to words used in natural query sentences that are used to replace the nouns or noun phrases mentioned above, including personal pronouns such as "he", "she", "it", demonstrative pronouns such as "this", "that", etc. The antecedent refers to the noun or noun phrase replaced by the pronoun. According to the historical conversation records, the antecedent corresponding to the pronoun in the query term is determined so that the pronoun can be replaced with a specific noun to make the query clearer.
[0083] Exemplarily, the query words are traversed to check whether the semantic label of each word belongs to the category of pronouns. Words with semantic labels as pronouns are marked for subsequent processing. In the historical conversation records, nouns or noun phrases that are semantically related to the pronouns and have a higher position are searched as antecedent candidates. According to the semantic labels of the antecedent candidates and the semantic labels of the pronouns, as well as the contextual relationship between them, semantic matching is performed, and the candidate with the highest semantic matching degree is selected as the antecedent corresponding to the pronoun.
[0084] The purpose of semantic matching is to determine the semantic relevance between a pronoun and its candidate antecedents. Through semantic matching, we can select the one that is most relevant to the pronoun from multiple candidate antecedents, thereby accurately replacing the pronoun with its corresponding antecedent.
[0085] Specifically, from the historical conversation records, a series of possible antecedent candidates are extracted according to the position and context of the pronoun. These candidates are usually nouns or noun phrases that appear before the pronoun. Features are extracted for the pronoun and each candidate antecedent. Features may include the semantic label, part of speech, positional relationship in the context, syntactic structure, etc. of the word. For example, if the pronoun is "he" and a candidate antecedent is "Zhang San", then the features that can be extracted include: the semantic label of "he" is a pronoun, the semantic label of "Zhang San" is a name, their positional relationship in the sentence, such as "Zhang San" appears before "he", and whether they are in the same sentence or paragraph, etc. Then, a semantic similarity algorithm is used to calculate the semantic similarity between the pronoun and each candidate antecedent. According to the results of the semantic similarity calculation, the candidate antecedent with the highest semantic similarity is selected as the antecedent corresponding to the pronoun.
[0086] Optionally, use a pre-trained word vector model such as Word2Vec, BERT, etc. to convert the pronoun and the candidate antecedent into word vectors, then calculate the cosine similarity between them, and select the candidate antecedent with the highest cosine similarity as the antecedent corresponding to the pronoun; or according to the positional relationship between the pronoun and the candidate antecedent in the semantic structure diagram, select the candidate antecedent with the most similar positional relationship as the antecedent corresponding to the pronoun.
[0087] In this embodiment, the pronouns in the query statement are identified through semantic tags, and then the antecedents corresponding to these pronouns are determined in the historical conversation records, and the pronouns are replaced with specific nouns to improve the clarity of the query, reduce ambiguity, and enhance the coherence of the context, so that the natural language processing data query system can more accurately understand and execute the user's intentions.
[0088] Based on the above embodiments of the present application, in the sixth embodiment of the present application, the same or similar contents as those in the above embodiments can be referred to the above introduction, and will not be described in detail later. Figure 6 Before step S20, the data query method further includes steps S40 to S70: Step S40, determining the number of the intent tags corresponding to the natural query statement.
[0089] Step S50: If the number of the intention tags is less than or equal to the preset tag threshold, it is determined that the query intention information meets the preset query condition.
[0090] It should be noted that in the field of natural language processing and semantic understanding, intent labels are used to identify the intent implied in user queries or statements. When there are multiple intent labels, this may mean that the user's query contains multiple different intentions or needs, or that the data query system cannot accurately identify the exact intent of the user's query, so it will assign multiple possible intent labels to cover all potential intents. In addition, the user's query may contain redundant or conflicting intent. When there are too many intent labels, it will be more difficult for the data query system to accurately judge the user's true intent, which may lead to misunderstandings or incorrect responses. Therefore, setting a threshold to limit the number of intent labels can help improve the accuracy of the data query system's understanding of user intent.
[0091] Step S60, obtaining the confidence parameter of the entity word output by the entity recognition model.
[0092] Step S70: If the confidence parameter of the entity word is greater than or equal to a preset confidence threshold, and the number of the antecedent words corresponding to the pronoun is less than or equal to a preset number threshold, it is determined that the query term information meets the preset query condition.
[0093] It should be noted that the confidence parameter is an indicator to measure the certainty of the model's recognition results. When the confidence parameter is low, it means that the model has failed to accurately capture the key information in the user's query and has low certainty in the recognition results. When there are a large number of antecedents in the historical session records, the referential relationship between the pronoun and the antecedent may become vague, making it difficult for the data query system to accurately determine the specific noun replaced by the pronoun. In order to ensure the accuracy and readability of the query results, by setting the confidence threshold, you can filter out those recognition results that the model considers to be highly uncertain and may be erroneous, thereby improving the accuracy of the query results, and setting a threshold for the number of antecedents to reduce referential ambiguity and make the query results clearer and easier to understand.
[0094] Exemplarily, when the entity recognition model receives an input natural query sentence, it first processes the sentence, such as splitting the complete sentence into a single word sequence through steps such as word segmentation and embedding representation, and then predicts each possible entity based on the weights and architecture trained inside the entity recognition model. For each predicted entity word, the entity recognition model calculates a confidence score. This score is usually obtained by normalizing the output of the last layer of the entity recognition model, such as the softmax layer or the sigmoid layer. For example, in the softmax layer, the scores of all possible entity types add up to 1, and the value of each score represents the probability that the model believes that the input word belongs to the corresponding entity type. While predicting the entity words, the entity recognition model also outputs the confidence scores of these entity words as an important indicator for evaluating the reliability of the model's prediction results.
[0095] In this embodiment, the number of recognized intents is controlled by setting an intent label threshold, reducing the data query system's misjudgment of the user's true intent, and introducing entity word confidence parameters and antecedent word number thresholds to ensure the certainty of the recognition results and reduce the ambiguity of pronouns. This can improve the accuracy of the data query system's understanding and response to user queries, while reducing possible misunderstandings and errors, ensuring accurate query results.
[0096] Based on the above embodiments of the present application, in the seventh embodiment of the present application, the same or similar contents as those in the above embodiments can be referred to the above introduction, and will not be described in detail later. Figure 7 , the data query method further includes steps S80 to S90: Step S80: If the query intention information does not satisfy the preset query condition, or the query term information does not satisfy the preset query condition, a query confirmation message is output.
[0097] Step S90, obtaining a natural query sentence re-entered by the user based on the query confirmation information, and executing the step of generating structured information based on the natural query sentence input by the user.
[0098] The natural language query input by the user is parsed to extract the query intent information and query word information. Then, this information is compared with the preset query conditions to determine whether it meets the requirements. When the natural language query input by the user does not meet the query conditions, the query confirmation information is displayed to the user. After seeing the query confirmation information, the user will adjust their input according to the feedback given by the data query system. Then, the data query system receives and processes this statement again.
[0099] Optionally, the user enters a natural language query through a user interface such as a text box, voice input, etc. The data query system receives the query entered by the user and prepares to send it to the NLP engine for processing. The NLP engine parses the user query and identifies the structured information such as entities, intents, and relationships therein. The NLP engine detects whether the structured information meets the query conditions. If the structured information does not meet the query conditions, interactive feedback and suggestions are generated, including asking the user to clarify ambiguous questions, providing possible explanations or options for the user to choose, etc.
[0100] For example, the data query system can display feedback and suggestions to the user through user interface modules such as pop-up windows, drop-down menus, text prompts, etc., and the user interacts based on the feedback and suggestions, such as selecting options, entering clarifying information, etc. For example, if the user enters a vague query: "show sales", the data query system will output a prompt: "Do you mean to show sales trends by month? Or show sales distribution by region?" Through question interaction, the data query system can further determine the user's query intention to obtain more accurate query results.
[0101] In this embodiment, when the user's query does not meet the preset conditions, the data query system will output query confirmation information to guide the user to adjust the input. The data query system effectively communicates with the user through the questions and options provided by the user interface module to clarify the ambiguity in the query and ensure that the structured information finally generated can accurately reflect the user's intention. This method not only improves the accuracy of query processing, but also enhances the user experience, making the query results more in line with the actual needs of the user.
[0102] Based on the above embodiments of the present application, in the eighth embodiment of the present application, the same or similar contents as those in the above embodiments can be referred to the above introduction, and will not be described in detail later. Figure 8 After step S30, the data query method further includes steps S100 to S110: Step S100: determining a visualization chart template based on the intention tag.
[0103] Step S110: generating a visualization report based on the query result and the visualization chart template.
[0104] The data query system first parses the user query and extracts the intent label. Then, based on the mapping relationship between the intent label and the visualization chart template, the corresponding chart template is selected. For example, if the intent label is "sales trend analysis", a line chart template may be selected.
[0105] Optionally, the data query system can set up a mapping table from intent labels to visualization chart templates, and directly search for corresponding templates based on the intent labels queried by the user. Then, according to the selected visualization chart template, the data points are mapped to the corresponding positions of the chart. At the same time, the data query system will also add elements such as titles, labels, and descriptions to improve the readability and comprehensibility of the report. Finally, the data query system outputs the generated visualization report to the user. Among them, the user is allowed to customize the style and layout of the visualization report according to needs, such as selecting colors, fonts, margins, etc.
[0106] For example, if a user queries "show the sales trend of the past year", the data query system first extracts the intent label "sales trend analysis" and selects the line chart template as the visualization chart template. Then, the data query system executes the query task and obtains the sales data of the past year. Finally, the data query system maps the data to the line chart and adds elements such as title, label, and description to generate a visualization report. Users can intuitively understand the sales trend of the past year by viewing the report and make decisions accordingly.
[0107] In this embodiment, the user query is parsed to determine the intent tags, and the appropriate chart template is selected based on these tags. The query results are then mapped to the chart, which can present complex data to the user in an intuitive chart form, allowing the user to quickly understand the query results.
[0108] For example, to help understand the implementation process of the data query method obtained by combining this embodiment with the above-mentioned embodiment 1, please refer to Fig. 9 , Fig. 9A brief flow chart of a data query method is provided. Specifically, a user inputs his query requirements through an interface, and these requirements are expressed in the form of natural language. After receiving the natural language query input by the user, the data query system first parses it. The parsing process includes identifying key information such as keywords, entities, and intents in the query. In the process of parsing the natural language query, the data query system checks whether the query is ambiguous. Among them, the ambiguity may come from the polysemy of vocabulary, the diversity of grammar, or the uncertainty of context. If the query is detected to be ambiguous, the data query system will provide interactive feedback to the user. The feedback may include asking the user questions to clarify the ambiguity, providing possible explanations or options for the user to choose, etc. The user confirms the query intent or modifies the query to eliminate the ambiguity based on the interactive feedback provided by the data query system. When it is detected that the query is not ambiguous, or after the user confirms or modifies the query, the data query system generates a structured statement query according to the user's intent. These structured query statements are used to accurately retrieve data from the database. The data query system submits the generated structured statement query to the database for execution to obtain the required data. The database returns the corresponding data results based on the structured statement query. The data query system generates corresponding charts or reports based on the acquired data. These charts or reports are designed to help users intuitively understand the data and analysis results.
[0109] For example, please refer to Fig.10 , Fig.10A schematic diagram of the architecture of a data query system involved in the data query method in the above-mentioned embodiment is provided. Specifically, the data query system includes: a user interface (UI, User Interface) module, which serves as an interface for the user to interact with the data query system, and is responsible for receiving the query input by the user and displaying the query results. The user inputs the query through the interface, and the data query system displays the parsing results, feedback / suggestions, and the final visual chart or report through the interface. A natural language processing (NLP) engine is used to parse the query input by the user and extract structured information. The NLP engine analyzes the vocabulary, grammar, and context in the query to understand the user's true intention, and outputs the parsing results, including structured information such as entities, attributes, and relationships in the query. An SQL generator is used to generate a corresponding SQL query statement based on the parsing result provided by the NLP engine. The SQL generator converts the structured information in the parsing result into an SQL statement that can be recognized by the database. A data processing module connects to the database, executes the query statement, and returns the query result. Clean, convert, aggregate, and other operations are performed on the data as needed. The visualization generation module selects appropriate chart types such as line charts, bar charts, pie charts, etc. and layout styles according to the type and characteristics of the data, and then generates visualization charts or reports. The feedback and suggestion module generates corresponding feedback or suggestions when the NLP engine or SQL generator encounters problems and displays them to the user through the user interface. The user can adjust the query or provide more information based on the feedback or suggestions.
[0110] For example, please refer to Fig.11 , Fig.11 A timing diagram of a data query system involved in the data query method in the above-mentioned embodiment is provided. Specifically, a user inputs a natural language query to a user interface (UI) module, and the user interface (UI) module sends the query statement to an NLP engine for parsing. If the parsing is ambiguous, feedback is requested from a feedback and suggestion module, and the feedback and suggestion module sends the feedback to the user interface (UI) module to display feedback information to the user. The user confirms or modifies the query through the user interface (UI) module, and the user interface (UI) module re-sends the query statement to the NLP engine. After parsing the query statement, the NLP engine sends structured information to an SQL generator, and the SQL generator generates an SQL statement and sends an SQL query to a data processing module. The data processing module executes the query and sends the queried data to a visualization generation module. The visualization generation module generates a chart or report based on the queried data and sends it to the user interface (UI) module to display the query result to the user.
[0111] It should be noted that the above examples are only used to understand the present application and do not constitute a limitation on the data query method of the present application. More simple transformations based on this technical concept are all within the scope of protection of the present application.
[0112] The present application provides a data query device, which includes: at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor can execute the data query method in the above-mentioned embodiment 1.
[0113] Reference below Fig.12 , which shows a schematic diagram of the structure of a data query device suitable for implementing the embodiment of the present application. The data query device in the embodiment of the present application may include but is not limited to mobile terminals such as mobile phones, laptops, PADs (Portable Application Description: tablet computers), PMPs (Portable Media Player: portable multimedia players), vehicle-mounted terminals (such as vehicle-mounted navigation terminals), etc., and fixed terminals such as desktop computers, etc. Fig.12 The data query device shown is merely an example and should not bring any limitation to the functions and scope of use of the embodiments of the present application.
[0114] like Fig.12 As shown, the data query device may include a processing device 1001 (such as a central processing unit, a graphics processor, etc.), which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM: Read Only Memory) 1002 or a program loaded from a storage device 1003 to a random access memory (RAM: Random Access Memory) 1004. In RAM1004, various programs and data required for the operation of the data query device are also stored. The processing device 1001, ROM1002 and RAM1004 are connected to each other through a bus 1005. An input / output (I / O) interface 1006 is also connected to the bus. Generally, the following systems can be connected to the I / O interface 1006: an input device 1007 including, for example, a touch screen, a touch pad, a keyboard, a mouse, an image sensor, a microphone, etc.; an output device 1008 including, for example, a liquid crystal display (LCD: Liquid Crystal Display), a speaker, a vibrator, etc.; a storage device 1003 including, for example, a magnetic tape, a hard disk, etc.; and a communication device 1009. The communication device 1009 can allow the data query device to communicate with other devices wirelessly or by wire to exchange data. Although the data query device with various systems is shown in the figure, it should be understood that it is not required to implement or have all the systems shown. More or fewer systems can be implemented or have alternatively.
[0115] In particular, according to the embodiments disclosed in the present application, the process described above with reference to the flowchart can be implemented as a computer software program. For example, the embodiments disclosed in the present application include a computer program product, which includes a computer program carried on a computer-readable medium, and the computer program includes a program code for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from a network through a communication device, or installed from a storage device 1003, or installed from a ROM 1002. When the computer program is executed by the processing device 1001, the above-mentioned functions defined in the method of the embodiment disclosed in the present application are executed.
[0116] The data query device provided by the present application adopts the data query method in the above embodiment to solve the technical problem of low accuracy of data query. Compared with the prior art, the beneficial effects of the data query device provided by the present application are the same as the beneficial effects of the data query method provided by the above embodiment, and other technical features in the data query device are the same as the features disclosed in the method of the previous embodiment, which will not be repeated here.
[0117] It should be understood that the various parts disclosed in this application can be implemented by hardware, software, firmware or a combination thereof. In the description of the above embodiments, specific features, structures, materials or characteristics can be combined in any one or more embodiments or examples in a suitable manner.
[0118] The above is only a specific implementation of the present application, but the protection scope of the present application is not limited thereto. Any person skilled in the art who is familiar with the present technical field can easily think of changes or substitutions within the technical scope disclosed in the present application, which should be included in the protection scope of the present application. Therefore, the protection scope of the present application should be based on the protection scope of the claims.
[0119] The present application also provides a computer program product, including a computer program, which implements the steps of the above-mentioned data query method when executed by a processor.
[0120] The computer program product provided by the present application can solve the technical problem of low accuracy of data query. Compared with the prior art, the beneficial effects of the computer program product provided by the present application are the same as the beneficial effects of the data query method provided by the above embodiment, which will not be repeated here.
[0121] The above descriptions are only some embodiments of the present application, and are not intended to limit the patent scope of the present application. All equivalent structural changes made using the contents of the present application specification and drawings under the technical concept of the present application, or direct / indirect applications in other related technical fields are included in the patent protection scope of the present application.
Claims
1. A data query method, characterized in that: The method comprises: Generate structured information based on the natural query sentence input by the user, wherein the structured information includes query intent information and query term information; If the query intention information and the query term information both meet the preset query conditions, generating a structured query statement based on the structured information; A query task is executed based on the structured query statement to obtain a query result.
2. The data query method according to claim 1, characterized in that: The query intent information includes an intent tag, and the step of generating structured information based on a natural query sentence input by a user includes: Determining a vector representation of the natural query sentence; Input the vector representation into a preset intent recognition model, wherein the intent recognition model is used to determine the degree of association between the input vector representation and the intent label, and determine the intent label corresponding to the vector representation according to the degree of association; Obtain the intent label output by the intent recognition model.
3. The data query method according to claim 1, characterized in that: The query term information includes entity words and relationship triples corresponding to the entity words, and the step of generating structured information based on the natural query sentence input by the user also includes: Splitting the natural query into word sequences; Inputting the word sequence into a preset entity recognition model, wherein the entity recognition model is used to determine a sequence label of the word sequence, so as to determine the entity words in the natural query sentence according to the sequence label; The entity words output by the entity recognition model are obtained, and based on the entity words, the relationship triples between entities are determined, where the relationship triples include two entity words and a logical relationship between the two entity words.
4. The data query method according to claim 3, characterized in that: The query term information also includes semantic tags and semantic structure diagrams, and the step of generating structured information based on the natural query sentence input by the user also includes: Based on the query terms in the natural query sentence, determining semantic tags corresponding to the query terms; Based on the relationship triples, the query terms and semantic labels corresponding to the query terms, a semantic structure graph of the natural query sentence is determined.
5. The data query method according to claim 4, characterized in that: After the step of determining the semantic tag corresponding to the query term based on the query term in the natural query sentence, the method further includes: Based on the semantic tag, determining whether there is a pronoun in the query term; If there is a pronoun in the query term, the antecedent corresponding to the pronoun is determined based on the historical conversation record, and the pronoun is replaced with the corresponding antecedent.
6. The data query method according to claim 5, characterized in that: If both the query intention information and the query term information satisfy the preset query condition, before the step of generating a structured query statement based on the structured information, the method further includes: Determine the number of the intent tags corresponding to the natural query statement; If the number of the intent tags is less than or equal to the preset tag threshold, it is determined that the query intent information meets the preset query condition; Obtaining the confidence parameter of the entity word output by the entity recognition model; If the confidence parameter of the entity word is greater than or equal to a preset confidence threshold, and the number of the antecedent words corresponding to the pronoun is less than or equal to a preset number threshold, it is determined that the query term information meets the preset query condition.
7. The data query method according to claim 1, characterized in that: The method further comprises: If the query intention information does not meet the preset query condition, or the query term information does not meet the preset query condition, output query confirmation information; A natural query sentence re-entered by the user based on the query confirmation information is obtained, and the step of generating structured information based on the natural query sentence input by the user is performed.
8. The data query method according to claim 2, characterized in that: After the step of executing the query task based on the structured query statement to obtain the query result, the method further includes: Determine a visualization chart template based on the intent tag; A visualization report is generated based on the query result and the visualization chart template.
9. A data query device, characterized in that: The device comprises: a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the computer program is configured to implement the steps of the data query method according to any one of claims 1 to 8.
10. A computer program product, characterized in that The computer program product comprises a computer program, and when the computer program is executed by a processor, the steps of the data query method according to any one of claims 1 to 8 are implemented.
Citation Information
Cited By
Task planning evaluation method and device, electronic equipment and storage medium
CN120470022A
Intelligent query control method based on natural language interaction and electronic equipment
CN121919344A