SQL statement generation method, device, storage medium and electronic device
Through speech recognition and semantic analysis technology, SQL statements are generated, which solves the problems of complex and high cost in traditional SQL code writing process, and achieves the effect of simplifying the generation process and improving efficiency.
Patent Information
- Application Number
- CN202110203994.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-02-23
- Publication Date
- 2025-02-21
- Estimated Expiration
- 2041-02-23
AI Technical Summary
Traditional SQL code writing requires manual writing, which has high learning costs and long development cycles, making it difficult to simplify the generation process.
By receiving the user's voice commands, converting them into text information, performing semantic analysis, extracting core vocabulary and dependency information, and generating corresponding SQL statements.
It realizes the generation of SQL statements based on speech, simplifies the generation process of SQL statements, improves the generation efficiency and accuracy, and reduces development costs.
Smart Images

Figure CN113779062B_ABST
Abstract
Description
Technical Field
[0001] The present disclosure relates to the field of speech processing, and in particular to a method, device, storage medium and electronic device for generating SQL statements. Background Art
[0002] SQL language is a common database query and programming language. Users can write corresponding SQL codes according to their own business needs to achieve the purpose of calling database data.
[0003] However, the traditional SQL code writing process requires corresponding developers to write it manually, which has high initial learning costs and a long development cycle.
[0004] It should be noted that the information disclosed in the above background technology section is only used to enhance the understanding of the background of the present disclosure, and therefore may include information that does not constitute the prior art known to ordinary technicians in the field. Summary of the invention
[0005] The purpose of the present disclosure is to provide a method, device, storage medium and electronic device for generating SQL statements, aiming to realize the generation of SQL statements based on voice and simplify the generation process of SQL statements.
[0006] Other features and advantages of the present disclosure will become apparent from the following detailed description, or may be learned in part by the practice of the present disclosure.
[0007] According to one aspect of an embodiment of the present disclosure, a method for generating an SQL statement is provided, comprising: receiving a user's voice instruction and converting the voice instruction into text information; performing semantic analysis on the text information to obtain dependency information between a core vocabulary and associated vocabulary related thereto; extracting a target component and component content corresponding to the target component based on the core vocabulary and the dependency information; and generating an SQL statement corresponding to the voice instruction according to the target component and the component content.
[0008] According to some embodiments of the present disclosure, based on the aforementioned scheme, before performing semantic analysis on the text information, the method also includes: performing pre-word segmentation on the text information to extract corpus feature vocabulary; selecting a target corpus that matches the corpus feature vocabulary from each preset basic corpus; and performing word segmentation on the text information based on the target corpus to obtain multiple words as word segmentation text information.
[0009] According to some embodiments of the present disclosure, based on the aforementioned scheme, the text information is subjected to semantic analysis to obtain dependency information between core vocabulary and related associated vocabulary, including: performing part-of-speech tagging on the vocabulary in the word segmentation text information; performing semantic analysis based on the number of vocabulary with predicate part of speech in the word segmentation text information after part-of-speech tagging to determine the core vocabulary and the dependency information.
[0010] According to some embodiments of the present disclosure, based on the aforementioned scheme, the semantic analysis is performed according to the number of words with predicate part of speech in the segmented text information after part of speech tagging to determine the core vocabulary and the dependency information, including: performing dependency syntactic analysis on the segmented text information to obtain first dependency information; and calculating the number N of words with predicate part of speech in the segmented text information, where N is a positive integer; when N=1, configuring the words with predicate part of speech as the core vocabulary, and configuring the first dependency information as the dependency information; when N>1, performing semantic role tagging on the segmented text information to obtain the core vocabulary, and extracting the dependency information from the first dependency information based on the core vocabulary.
[0011] According to some embodiments of the present disclosure, based on the aforementioned scheme, when N=1, the method further includes: performing semantic role labeling on the word segmentation text information to obtain a first core vocabulary; when the vocabulary with the predicate part of speech matches the first core vocabulary, configuring the vocabulary with the predicate part of speech as the core vocabulary.
[0012] According to some embodiments of the present disclosure, based on the aforementioned scheme, the extracting of the target component and the component content corresponding to the target component based on the core vocabulary and the dependency information includes: constructing first mapping information between keywords and components according to the type of SQL statement in advance, and constructing second mapping information between keywords and sentence content according to the content of the SQL statement; matching the core vocabulary and the associated vocabulary with the keywords to determine the first keyword corresponding to the core vocabulary and the second keyword corresponding to the associated vocabulary; extracting multiple components corresponding to the first keyword as the target component using the first mapping information; extracting sentence content corresponding to the second keyword using the second mapping information, and combining the sentence content based on the dependency information to determine the component content.
[0013] According to some embodiments of the present disclosure, based on the aforementioned scheme, before generating the SQL statement corresponding to the voice instruction according to the target component and the component content, the method also includes: in response to the user's add instruction, obtaining the target component and / or component content corresponding to the add instruction for generating the SQL statement.
[0014] According to some embodiments of the present disclosure, based on the aforementioned scheme, after extracting the target component and the component content corresponding to the target component based on the core vocabulary and the dependency information, the method also includes: comparing the target component corresponding to the component content with the extracted target component; when the comparison result is missing, generating missing prompt information based on the missing target component.
[0015] According to some embodiments of the present disclosure, based on the aforementioned scheme, after performing semantic analysis on the text information, the method further includes: determining execution information corresponding to the voice instruction; executing the SQL statement according to the execution information to obtain an execution result corresponding to the voice instruction.
[0016] According to some embodiments of the present disclosure, based on the aforementioned scheme, the method also includes: constructing third mapping information between sentence patterns and core vocabulary in advance according to the results of semantic analysis; performing sentence pattern recognition on the text information; and when the recognition result includes a target sentence pattern matching the sentence pattern, using the third mapping information to determine the core vocabulary to generate the SQL statement.
[0017] According to a second aspect of an embodiment of the present disclosure, a device for generating an SQL statement is provided, comprising: a receiving module for receiving a user's voice instruction and converting the voice instruction into text information; an analyzing module for performing semantic analysis on the text information to obtain dependency information between a core vocabulary and associated vocabulary related thereto; an extracting module for extracting a target component and component content corresponding to the target component based on the core vocabulary and the dependency information; and a generating module for generating an SQL statement corresponding to the voice instruction based on the target component and the component content.
[0018] According to a third aspect of the embodiments of the present disclosure, a computer-readable storage medium is provided, on which a computer program is stored. When the program is executed by a processor, the method for generating an SQL statement as in the above embodiment is implemented.
[0019] According to a fourth aspect of an embodiment of the present disclosure, an electronic device is provided, characterized in that it includes: one or more processors; a storage device for storing one or more programs, when the one or more programs are executed by the one or more processors, the one or more processors implement the SQL statement generation method as in the above-mentioned embodiment.
[0020] The exemplary embodiments of the present disclosure may have some or all of the following beneficial effects:
[0021] In the technical solutions provided in some embodiments of the present disclosure, firstly, corresponding SQL statements can be generated according to the user's voice instructions, which simplifies the process of generating SQL statements and provides a new technical solution for the intelligent writing of SQL codes; secondly, after semantic analysis is performed on the text information converted from the voice instructions, the dependency information between the core vocabulary and the related vocabulary is extracted, and the redundant information in the voice instructions can be discarded, and SQL statements can be generated only based on the extracted important information, thereby improving the efficiency and accuracy of SQL statement generation; thirdly, the type of SQL statement can be not set in advance, but the target component can be extracted according to the result of semantic analysis, and then the component content corresponding to the target component can be extracted, thereby improving the practicality and extensiveness of the SQL statement generation method.
[0022] It is to be understood that the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the present disclosure. BRIEF DESCRIPTION OF THE DRAWINGS
[0023] The drawings herein are incorporated into the specification and constitute a part of the specification, showing embodiments consistent with the present disclosure, and together with the specification, are used to explain the principles of the present disclosure. Obviously, the drawings described below are only some embodiments of the present disclosure, and for ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work. In the drawings:
[0024] Figure 1 A schematic diagram schematically illustrates a flow chart of a method for generating a SQL statement in an exemplary embodiment of the present disclosure;
[0025] Figure 2 A schematic diagram schematically illustrates a dependency parsing result in an exemplary embodiment of the present disclosure;
[0026] Figure 3 A schematic diagram schematically illustrates a flow chart of another SQL statement generation method in an exemplary embodiment of the present disclosure;
[0027] Figure 4 A schematic diagram schematically shows the composition of a SQL statement generating device in an exemplary embodiment of the present disclosure;
[0028] Figure 5 A schematic diagram schematically illustrates a computer-readable storage medium in an exemplary embodiment of the present disclosure;
[0029] Figure 6 The structure diagram of a computer system of an electronic device in an exemplary embodiment of the present disclosure is schematically shown. DETAILED DESCRIPTION
[0030] Example embodiments will now be described more fully with reference to the accompanying drawings. However, example embodiments can be implemented in a variety of forms and should not be construed as limited to the examples set forth herein; rather, these embodiments are provided so that this disclosure will be more comprehensive and complete and will fully convey the concept of the example embodiments to those skilled in the art.
[0031] In addition, the described features, structures or characteristics may be combined in one or more embodiments in any suitable manner. In the following description, many specific details are provided to provide a full understanding of the embodiments of the present disclosure. However, those skilled in the art will appreciate that the technical solutions of the present disclosure may be practiced without one or more of the specific details, or other methods, components, devices, steps, etc. may be adopted. In other cases, known methods, devices, implementations or operations are not shown or described in detail to avoid blurring the various aspects of the present disclosure.
[0032] The block diagrams shown in the accompanying drawings are merely functional entities and do not necessarily correspond to physically independent entities. That is, these functional entities may be implemented in software form, or in one or more hardware modules or integrated circuits, or in different networks and / or processor devices and / or microcontroller devices.
[0033] The flowcharts shown in the accompanying drawings are only exemplary and do not necessarily include all the contents and operations / steps, nor must they be executed in the order described. For example, some operations / steps can be decomposed, and some operations / steps can be combined or partially combined, so the actual execution order may change according to actual conditions.
[0034] The implementation details of the technical solution of the embodiment of the present disclosure are elaborated in detail below.
[0035] Figure 1 The following is a schematic diagram showing a flow chart of a method for generating a SQL statement in an exemplary embodiment of the present disclosure. Figure 1 As shown, the SQL statement generation method includes steps S1 to S4:
[0036] Step S1, receiving a user's voice command and converting the voice command into text information;
[0037] Step S2, performing semantic analysis on the text information to obtain dependency relationship information between core words and associated words related thereto;
[0038] Step S3, extracting a target component and component content corresponding to the target component based on the core vocabulary and the dependency information;
[0039] Step S4: Generate an SQL statement corresponding to the voice instruction according to the target component and the component content.
[0040] In the technical solutions provided in some embodiments of the present disclosure, firstly, corresponding SQL statements can be generated according to the user's voice instructions, which simplifies the process of generating SQL statements and provides a new technical solution for the intelligent writing of SQL codes; secondly, after semantic analysis is performed on the text information converted from the voice instructions, the dependency information between the core vocabulary and the related vocabulary is extracted, and the redundant information in the voice instructions can be discarded, and SQL statements can be generated only based on the extracted important information, thereby improving the efficiency and accuracy of SQL statement generation; thirdly, the type of SQL statement can be not set in advance, but the target component can be extracted according to the result of semantic analysis, and then the component content corresponding to the target component can be extracted, thereby improving the practicality and extensiveness of the SQL statement generation method.
[0041] Below, each step of the SQL statement generation method in this example implementation will be described in more detail with reference to the accompanying drawings and embodiments.
[0042] Step S1, receiving a user's voice command and converting the voice command into text information.
[0043] In one embodiment of the present disclosure, it is first necessary to receive the user's voice input as a voice command, and then use a voice recognition tool to convert the voice command into text information. The voice recognition tool can be iFlytek, Alibaba Cloud, etc. Since voice recognition can be implemented using existing technologies, the present disclosure will not elaborate on it here.
[0044] Preferably, when identifying as text data, it can be identified in conjunction with a corpus. The corpus can be a dedicated corpus built in conjunction with business needs as a basic corpus, or it can be a basic corpus obtained by adding, deleting and modifying an existing dedicated corpus according to its own needs. Since the corpus is used to assist in identification, the user's proper nouns in the business field can be identified, and the recognition effect is more accurate.
[0045] After the text information is recognized by the speech recognition tool, the server sends the recognized text information to the terminal for the user to view. The user can modify the recognition result and use the modified text information for subsequent semantic analysis.
[0046] Step S2, performing semantic analysis on the text information to obtain dependency relationship information between core words and associated words related thereto.
[0047] In one embodiment of the present disclosure, before semantic analysis is performed on the text information, the process further includes: step S20, segmenting the text information to obtain segmented text information, so as to facilitate subsequent semantic analysis. Specifically, the specific process of step S20 is as follows:
[0048] Step S201, performing pre-segmentation processing on the text information to extract corpus feature words;
[0049] Step S202, selecting a target corpus that matches the corpus feature vocabulary from each preset basic corpus;
[0050] Step S203: performing word segmentation processing on the text information based on the target corpus to obtain a plurality of words as word segmentation text information.
[0051] In steps S201 and S202, due to different business requirements, the created special corpus is also different, so it is necessary to extract the corpus feature words in the text information, and then select the target corpus for word segmentation. Pre-segmentation is similar to word segmentation, but the purpose is to extract corpus feature words.
[0052] For example, making a company performance report and collecting statistics on product information are different businesses, and the corresponding basic corpora are different. Take the user's voice command "I want to make a report on the total performance of a branch company in the first quarter" as an example, where "report" can be extracted as a corpus feature word. Based on this feature word, the basic corpus corresponding to the performance report can be selected for word segmentation processing.
[0053] In step S203, word segmentation refers to dividing a Chinese character sequence into individual words. Word segmentation is the process of recombining a continuous character sequence into a word sequence according to certain specifications. The word segmentation method can be a word segmentation method based on string matching, a word segmentation method based on understanding, and a word segmentation method based on statistics, and then combined with the selected target corpus to complete the word segmentation processing of the text information. The above process can be completed using word segmentation tools, such as Jieba word segmentation, SnowNLP, THULAC and other word segmentation tools.
[0054] Preferably, filtering of stop words and special symbols can be added on the basis of the existing word segmentation method to further improve the accuracy of word segmentation.
[0055] In one embodiment of the present disclosure, semantic analysis is performed on the text information to obtain dependency relationship information between core words and associated words related thereto, including the following steps:
[0056] Step S21, performing part-of-speech tagging on the words in the word segmentation text information.
[0057] In step S21, part-of-speech tagging refers to the process of tagging a correct part of speech for each word in the word segmentation result, that is, the process of determining the part of speech of each word, such as noun, verb, adjective, adverb, preposition, quantifier or other parts of speech.
[0058] The word segmentation text information includes multiple vocabulary segments after word segmentation processing. The word segmentation text information is tagged with the above method to obtain the word segmentation information. The word segmentation text information can be tagged with the word segmentation information. The word segmentation ...
[0059] Step S22, performing semantic analysis according to the number of words with predicate part of speech in the word segmentation text information after part of speech tagging, so as to determine the core words and the dependency relationship information.
[0060] In step S22, the following steps are specifically included:
[0061] Step S221, performing dependency syntactic analysis on the segmented text information to obtain first dependency relationship information; and
[0062] Step S222, calculating the number N of words with predicate part of speech in the segmented text information, where N is a positive integer;
[0063] Step S223, when N=1, configuring the vocabulary with the predicate part of speech as the core vocabulary, and configuring the first dependency information as the dependency information;
[0064] Step S224, when N>1, semantic role labeling is performed on the segmented text information to obtain the core vocabulary, and the dependency information is extracted from the first dependency information based on the core vocabulary.
[0065] In step S221, it is necessary to perform dependency syntactic analysis on the word segmentation text information. Syntactic analysis is one of the key underlying technologies in natural language processing. Syntactic analysis that aims to obtain local components is called dependency analysis. Dependency syntactic analysis can identify the syntactic components contained in a sentence and the relationship between these components. In other words, by analyzing the syntax of a sentence, the noun components in the sentence and the description fields of the noun can be extracted.
[0066] Specifically, a graph-based dependency parsing method can be used to transform the syntactic analysis problem into the problem of finding the maximum spanning tree from a completely directed graph. First, the weight of each dependency subtree is calculated, and then the weights of these subtrees are added together to obtain the weight of the entire dependency tree to find the maximum spanning tree. Of course, other dependency parsing methods can also be used, such as PCFG (probabilistic context-free grammar), dictionary-based PCFG, and splicing syntax trees based on greedy decision actions, to obtain the first dependency relationship information, that is, the corresponding relationship between words.
[0067] Figure 2 A schematic diagram schematically shows a dependency syntactic analysis result in an exemplary embodiment of the present disclosure. For example, taking the sentence "I want to make a report on the total performance of a branch company in the first quarter" as an example, "want" is the core word of the entire sentence, and corresponds to the root node in the tree. "I" and "requirement" are dependent words under the core word, that is, the corresponding leaf nodes under the root node. By analogy, the final dependency arc effect diagram is as follows: Figure 2 shown.
[0068] In step S222, the number of words with predicate part of speech in the word segmentation text information is calculated. After marking the part of speech of each word in the word segmentation text, the habit of each word can be obtained, and the words with predicate part of speech are counted to obtain the N value, where N is a positive integer.
[0069] It should be noted that the present disclosure does not specifically limit the execution order of step S221 and step S222, which may be executed simultaneously or in a sequential order.
[0070] In step S223, it is the case that N=1. Since there is only one predicate in the text information, this predicate is determined as the core word. The other words in the text information are all related words related to the core word, so the primary relationship between the words obtained in step S221 can be used as dependency information.
[0071] In step S224, it is the case that N>1. At this time, it is necessary to first select a core word from multiple predicates, then select associated words related to the core word, and finally extract corresponding dependency information from the first dependency information according to the core word and the associated words.
[0072] Let’s take the sentence “I want to make a report about the total performance of a branch company in the first quarter” as an example. There are two predicates in the sentence, which means there are two combinations of subject-verb relationships, namely “want, make” and “make, report”. However, from the perspective of part of speech, “want, make” are both verbs. It can be seen that “want” and “make a report about the total performance of a company in the first quarter” are subject-verb relationships, while “make, report” are a combination of verbs and nouns. Therefore, “make” is the predicate that this article really needs to focus on, and the part after the predicate is the key part of describing the report. Therefore, when multiple predicates are included in the word segmentation text information, it is necessary to further analyze the argument information associated with multiple predicates, and then determine the core vocabulary and dependency relationship information.
[0073] First, semantic role labeling is performed on the segmented text information to obtain the core vocabulary. Semantic role labeling is a kind of shallow semantic analysis. It takes sentences as units and does not conduct in-depth analysis of the given information contained in the sentences, but only analyzes the predicate-argument structure of the sentences. Arguments refer to nouns that are paired with predicates. Each verb has its own argument structure. The task of semantic role labeling is to focus on the predicate of the sentence, study the relationship between each component in the sentence and the predicate, and use semantic roles to describe the relationship between them.
[0074] The specific process is as follows: vectorize the text data after word segmentation, then use the deep learning model to extract feature vectors, and finally determine the core vocabulary based on the feature extraction results. For example, you can first use the ERNIE pre-trained model to vectorize the text data after word segmentation to obtain word vectors, then pass the results into the BiGRU model or BiLSTM model for feature extraction, and finally pass the feature extraction results as input to the CRF for calculation, output the label sequence with the highest probability through the CRF layer, and then determine the core vocabulary, so that the extraction results are more accurate.
[0075] Then, the associated words related to the core words can be determined according to the first dependency information. It should be noted that the words related to the core words are associated words, and the words related to these associated words are also associated words. For example, in the above example, the associated words related to "production" are "reports", and the associated words related to "reports" are "total", "performance", "a branch", "first quarter", etc. These words are selected as associated words.
[0076] Finally, dependency information is extracted based on the dependency relationship between the core words and the associated words. The dependency information can be stored as a data dictionary, indicating the dependency relationship between two words. For example, the dependency information can be (a branch, the first quarter), (performance, a branch), (total, performance).
[0077] In one embodiment of the present disclosure, when N=1, the method further includes: performing semantic role labeling on the word segmentation text information to obtain a first core vocabulary; when the vocabulary with the predicate part of speech matches the first core vocabulary, configuring the vocabulary with the predicate part of speech as the core vocabulary.
[0078] When there is only one predicate in the text information, in order to further verify the accuracy of the core vocabulary, the semantic role labeling of the word text information can be performed to identify the first core vocabulary, and then the first core vocabulary is compared with the predicate vocabulary. Only when the two are exactly the same, subsequent operations are performed to ensure the accuracy of SQL statement generation.
[0079] Step S3, extracting a target component and component content corresponding to the target component based on the core vocabulary and the dependency information.
[0080] In one embodiment of the present disclosure, the step of extracting a target component and component content corresponding to the target component based on the core vocabulary and the dependency information includes:
[0081] Step S31, constructing first mapping information of keywords and components according to the type of SQL statement in advance, and constructing second mapping information of keywords and statement content according to the content of the SQL statement;
[0082] Step S32, matching the core vocabulary and the associated vocabulary with the keyword to determine a first keyword corresponding to the core vocabulary and a second keyword corresponding to the associated vocabulary;
[0083] Step S33, extracting a plurality of components corresponding to the first keyword as the target components by using the first mapping information;
[0084] Step S34: extracting sentence contents corresponding to the second keyword using the second mapping information, and combining the sentence contents based on the dependency information to determine the component contents.
[0085] In step S31, first mapping information is pre-constructed according to the type of SQL statement. Specifically, the type of SQL statement may be a query SELECT, delete DELETE, modify UPDATE, add INSERT and other instructions, and different instructions correspond to different components of SQL statements. For example, in a query task, the required SQL statement components include SELECT, FROM, and WHERE, and in an add task, the required SQL statement components include INSERT and VALUES. Based on this, a mapping relationship between keywords and components in different types of SQL statements is pre-constructed so that after determining the keywords, the corresponding target components can be extracted according to the mapping relationship.
[0086] When constructing keywords, you can use the keyword aggregation method to bind multiple words to the same keyword. For example, if the keyword is "query", and the user's voice command does not necessarily include the word "query" every time, we can know through semantics that sentences such as "I want to check..." and "Please find..." all express the meaning of query. At the same time, you can aggregate "check", "find" and other words that have essentially the same meaning as "query" and bind them to "query", which can further improve the success rate of keyword matching in the command, and thus improve the efficiency of generating SQL statements.
[0087] It should be noted that not only words with the same meaning can be used to construct a mapping relationship, but also necessary steps can be associated together. For example, if the word "make" is to be made, a "search" step is required, and only after the search can it be made.
[0088] In addition, it is also necessary to construct the second mapping information between keywords and statement contents in advance according to the contents of the SQL statements. Specifically, some words in the user's instructions can be directly converted into the contents of the SQL statements. For example, if the user's instruction information includes "first quarter", the corresponding SQL statement is "January OR February OR March". For example, the SQL statement corresponding to "sum" is the SUM function. Constructing these mapping relationships in advance can improve the accuracy of generating SQL statements.
[0089] Similar to constructing the first mapping information, when constructing keywords, a method of aggregating keywords may also be used.
[0090] In step S34, after extracting the sentence content corresponding to the second keyword, it is also necessary to combine the sentence content based on the dependency information. For example, the sentence content corresponding to the second keyword "first quarter" can be extracted according to the second mapping information, and the content corresponding to the WHERE component is determined to be (a branch company, first quarter) according to the dependency information, so the sentence content is combined to obtain "a branch company AND January OR February OR March" as the component content corresponding to the WHERE component.
[0091] In one embodiment of the present disclosure, before generating the SQL statement corresponding to the voice instruction according to the target component and the component content, the method further includes: in response to an add instruction of the user, obtaining the target component and / or component content corresponding to the add instruction for generating the SQL statement.
[0092] Specifically, in order to further ensure the accuracy of the generated SQL statement, the method provided by the present disclosure supports the corresponding user's adding instructions to autonomously add the target component and the corresponding component content according to the needs. It should be noted that the adding instruction can also be a modification instruction, a deletion instruction, etc., which changes the target component and / or the component content, and can be executed before or after semantic recognition.
[0093] For example, when generating, adding, deleting or modifying some SQL statements, the accuracy of the database table name and column name is required to be high. Therefore, the user can manually select or modify the recognition results to further improve the accuracy of the generated statements.
[0094] In one embodiment of the present disclosure, after extracting the target component and the component content corresponding to the target component based on the core vocabulary and the dependency information, the method further includes: comparing the target component corresponding to the component content with the extracted target component; when the comparison result is missing, generating missing prompt information according to the missing target component.
[0095] According to semantic analysis, the corresponding target components can be extracted, and then the target content corresponding to the target components can be obtained. In order to avoid the failure of SQL statement generation due to the lack of key information, the method provided by the present invention can pre-judge the recognition results. When important information is missing, missing prompt information can be sent to the user.
[0096] For example, when the target components extracted according to the user's voice command include A, B, and C, and only the component contents a and b corresponding to A and B are recognized, the SQL statement cannot be generated due to the lack of the component content corresponding to C. At this time, a missing prompt message will be generated to remind the user that the component content corresponding to C is needed.
[0097] Step S4: Generate an SQL statement corresponding to the voice instruction according to the target component and the component content.
[0098] In one embodiment of the present disclosure, a SQL statement can be generated by filling the component content corresponding to the target component into the corresponding target component position according to the grammatical rules of the SQL statement.
[0099] Take the SELECT statement as an example. The SELECT statement is used to select data from the database and store the results in a result table. Its basic statement includes the name of the data table header and the name of the specified data table in the database. Its basic statement is as follows:
[0100] SELECT column_name1,column_name2
[0101] FROM table_name
[0102] WHERE column_name1operator value
[0103] This statement means to extract the data with the table headers column_name1 and column_name2 from the table named table_name. The content after WHERE indicates that the data extracted from column_name1 must meet certain conditions. SQL statements can be generated based on the basic syntax of the SELECT statement.
[0104] Taking the above voice command "I want to make a report on the total performance of a branch company in the first quarter" as an example, combined with the results of semantic analysis, the following SELECT statement can be generated:
[0105] SELECT SUM(performance)
[0106] FROM COMPANY
[0107] WHERE a branch AND January OR February OR March
[0108] Figure 3 A schematic diagram schematically shows another method for generating SQL statements in an exemplary embodiment of the present disclosure. Figure 3 As shown, the steps of the SQL statement generation method disclosed in the present invention are as follows: step S301, receiving the user's voice input; step S302, selecting the target corpus; step S303, using the target corpus to perform voice recognition on the voice input; step S304, determining the core vocabulary; step S305, determining the dependency data; step S306, extracting multiple target components; step S307, extracting the component contents corresponding to the multiple target components; step S308, generating an SQL statement according to the extracted results.
[0109] In one embodiment of the present disclosure, after the semantic analysis of the text information, the method further includes: determining execution information corresponding to the voice instruction; and executing the SQL statement according to the execution information to obtain an execution result corresponding to the voice instruction.
[0110] Specifically, the user's instruction information contains multiple intentions, which may not be directly completed by executing SQL statements. For example, if the user says "query XX information", then executing the SELECT statement can achieve the user's intention, but if the user says "make XX report", then you can only query the relevant information first, and then make a report based on the queried information. The query process may also require executing multiple query statements.
[0111] Therefore, it is necessary to obtain execution information after receiving the user's voice information, and then determine how to use the results of executing SQL statements based on the execution information to obtain the execution results the user wants. Taking the core word "make" extracted by semantic analysis as an example, the execution information includes the first operation and the second operation. The first operation is to execute the automatically generated SELECT statement, and the second operation is to make a report. The specific process is to determine the form of the report based on the identified dependency information, as well as the main header, sub-header content and other information, and then find a suitable report template to fill in the queried data to generate a report, which is the execution result corresponding to the user's voice command.
[0112] In one embodiment of the present disclosure, the method further includes: constructing third mapping information between sentence patterns and core vocabulary in advance based on the results of semantic analysis; performing sentence pattern recognition on the text information; and when the recognition results include a target sentence pattern matching the sentence pattern, using the third mapping information to determine the core vocabulary to generate the SQL statement.
[0113] For example, after semantic analysis of the sentence "I want to make a report on the total performance of a branch company in the first quarter", the core word is determined to be "make", and the associated words for extracting component content are identified from "the total performance of a branch company in the first quarter". Therefore, if the user's voice is "I want to make a report on XX", the core word can be directly determined to be "make", thereby improving the efficiency of generating SQL statements.
[0114] Therefore, the semantic analysis result corresponding to "I want to make a report about XX" can be stored as a sentence pattern, and this sentence pattern can be included in the acquired voice command, or the user can make voice input according to the specified sentence pattern, so that the core vocabulary can be directly extracted without semantic role labeling.
[0115] Based on the above method, using speech recognition technology and semantic analysis technology, the user only needs to input command-style voice information, and the system can automatically write the corresponding SQL code, which simplifies the generation process of SQL statements and provides a way to intelligently write SQL codes. In addition, the present disclosure maps text information and components in SQL statements, further expanding the application scope of natural language processing technology in SQL code writing.
[0116] Figure 4 The following is a schematic diagram showing the composition of a SQL statement generating device in an exemplary embodiment of the present disclosure. Figure 4 As shown, the SQL statement generating device 400 may include a receiving module 401, an analyzing module 402, an extracting module 403 and a generating module 404. Among them:
[0117] The receiving module 401 is used to receive a user's voice command and convert the voice command into text information;
[0118] An analysis module 402 is used to perform semantic analysis on the text information to obtain dependency relationship information between core words and associated words related thereto;
[0119] An extraction module 403, configured to extract a target component and component content corresponding to the target component based on the core vocabulary and the dependency information;
[0120] The generating module 404 is used to generate the SQL statement corresponding to the voice instruction according to the target component and the component content.
[0121] According to some embodiments of the present disclosure, based on the aforementioned scheme, the SQL statement generation device also includes an analysis module (not shown in the figure), which is used to perform pre-segmentation processing on the text information to extract corpus feature vocabulary; select a target corpus that matches the corpus feature vocabulary from each preset basic corpus; and perform segmentation processing on the text information based on the target corpus to obtain multiple words as segmentation text information.
[0122] According to some embodiments of the present disclosure, based on the aforementioned scheme, the analysis module includes a part-of-speech tagging unit and a semantic analysis unit (not shown in the figure), the part-of-speech tagging unit is used to perform part-of-speech tagging on the vocabulary in the segmented text information; the semantic analysis unit is used to perform semantic analysis based on the number of vocabulary with predicate part-of-speech in the segmented text information after part-of-speech tagging, so as to determine the core vocabulary and the dependency information.
[0123] According to some embodiments of the present disclosure, based on the aforementioned scheme, the semantic analysis unit is used to perform dependency syntactic analysis on the word segmentation text information to obtain first dependency relationship information; and calculate the number N of words with predicate part of speech in the word segmentation text information, where N is a positive integer; when N=1, the words with predicate part of speech are configured as the core words, and the first dependency relationship information is configured as the dependency relationship information; when N>1, semantic role labeling is performed on the word segmentation text information to obtain the core words, and the dependency relationship information is extracted from the first dependency relationship information based on the core words.
[0124] According to some embodiments of the present disclosure, based on the aforementioned scheme, the semantic analysis unit is also used to perform semantic role labeling on the word segmentation text information to obtain a first core vocabulary when N=1; when the vocabulary with predicate part of speech matches the first core vocabulary, the vocabulary with predicate part of speech is configured as the core vocabulary.
[0125] According to some embodiments of the present disclosure, based on the aforementioned scheme, the extraction module is used to pre-construct first mapping information between keywords and components according to the type of SQL statement, and to construct second mapping information between keywords and statement content according to the content of the SQL statement; match the core vocabulary and the associated vocabulary with the keyword to determine the first keyword corresponding to the core vocabulary and the second keyword corresponding to the associated vocabulary; use the first mapping information to extract multiple components corresponding to the first keyword as the target component; use the second mapping information to extract the statement content corresponding to the second keyword, and combine the statement content based on the dependency information to determine the component content.
[0126] According to some embodiments of the present disclosure, based on the aforementioned scheme, the extraction module further includes an adding unit for responding to an adding instruction of a user, obtaining a target component and / or component content corresponding to the adding instruction for generating the SQL statement.
[0127] According to some embodiments of the present disclosure, based on the aforementioned scheme, the extraction module also includes a unit for comparing the target component corresponding to the component content with the extracted target component; when the comparison result is missing, generating missing prompt information according to the missing target component.
[0128] According to some embodiments of the present disclosure, based on the aforementioned scheme, the SQL statement generation device also includes an execution module, which is used to determine execution information corresponding to the voice instruction; execute the SQL statement according to the execution information to obtain an execution result corresponding to the voice instruction.
[0129] According to some embodiments of the present disclosure, based on the aforementioned scheme, the SQL statement generation device also includes a recognition module, which is used to pre-construct third mapping information between sentence patterns and core vocabulary based on the results of semantic analysis; perform sentence pattern recognition on the text information; and when the recognition result includes a target sentence pattern that matches the sentence pattern, use the third mapping information to determine the core vocabulary to generate the SQL statement.
[0130] The specific details of each module in the above-mentioned SQL statement generation device 400 have been described in detail in the corresponding SQL statement generation method, so they will not be repeated here.
[0131] It should be noted that, although several modules or units of the device for action execution are mentioned in the above detailed description, this division is not mandatory. In fact, according to the embodiments of the present disclosure, the features and functions of two or more modules or units described above can be embodied in one module or unit. On the contrary, the features and functions of one module or unit described above can be further divided into multiple modules or units to be embodied.
[0132] In an exemplary embodiment of the present disclosure, a storage medium capable of implementing the above method is also provided. Figure 5 A schematic diagram schematically illustrates a computer-readable storage medium in an exemplary embodiment of the present disclosure, such as Figure 5 As shown, a program product 500 for implementing the above method according to an embodiment of the present disclosure is described, which can adopt a portable compact disk read-only memory (CD-ROM) and include program code, and can be run on a terminal device, such as a mobile phone. However, the program product of the present disclosure is not limited thereto. In this document, a readable storage medium can be any tangible medium containing or storing a program, which can be used by or in combination with an instruction execution system, an apparatus or a device.
[0133] In an exemplary embodiment of the present disclosure, an electronic device capable of implementing the above method is also provided. Figure 6 The structure diagram of a computer system of an electronic device in an exemplary embodiment of the present disclosure is schematically shown.
[0134] It should be noted that Figure 6 The computer system 600 of the electronic device shown is only an example and should not bring any limitation to the functions and scope of use of the embodiments of the present disclosure.
[0135] like Figure 6 As shown, the computer system 600 includes a central processing unit (CPU) 601, which can perform various appropriate actions and processes according to the program stored in the read-only memory (ROM) 602 or the program loaded from the storage part 608 to the random access memory (RAM) 603. In the RAM 603, various programs and data required for system operation are also stored. The CPU 601, the ROM 602 and the RAM 603 are connected to each other through a bus 604. An input / output (I / O) interface 605 is also connected to the bus 604.
[0136] The following components are connected to the I / O interface 605: an input section 606 including a keyboard, a mouse, etc.; an output section 607 including a cathode ray tube (CRT), a liquid crystal display (LCD), etc., and a speaker, etc.; a storage section 608 including a hard disk, etc.; and a communication section 609 including a network interface card such as a LAN (Local Area Network) card, a modem, etc. The communication section 609 performs communication processing via a network such as the Internet. A drive 610 is also connected to the I / O interface 605 as needed. A removable medium 611, such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, etc., is installed on the drive 610 as needed so that a computer program read therefrom is installed into the storage section 608 as needed.
[0137] In particular, according to an embodiment of the present disclosure, the process described below with reference to the flowchart can be implemented as a computer software program. For example, an embodiment of the present disclosure includes 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 part 609, and / or installed from a removable medium 611. When the computer program is executed by a central processing unit (CPU) 601, various functions defined in the system of the present disclosure are executed.
[0138] It should be noted that the computer-readable medium shown in the embodiment of the present disclosure may be a computer-readable signal medium or a computer-readable storage medium or any combination of the above two. The computer-readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, or any combination of the above. More specific examples of computer-readable storage media may include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM), a flash memory, an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In the present disclosure, a computer-readable storage medium may be any tangible medium containing or storing a program, which may be used by an instruction execution system, device or device or used in combination with it. In the present disclosure, a computer-readable signal medium may include a data signal propagated in a baseband or as part of a carrier wave, wherein a computer-readable program code is carried. Such propagated data signals may take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. Computer-readable signal media may also be any computer-readable medium other than computer-readable storage media, which may send, propagate, or transmit programs for use by or in conjunction with an instruction execution system, apparatus, or device. The program code contained on the computer-readable medium may be transmitted using any appropriate medium, including but not limited to: wireless, wired, etc., or any suitable combination of the above.
[0139] The flow charts and block diagrams in the accompanying drawings illustrate the possible architecture, functions and operations of the systems, methods and computer program products according to various embodiments of the present disclosure. In this regard, each box in the flow chart or block diagram can represent a module, a program segment, or a part of a code, and the above-mentioned module, program segment, or a part of a code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the box can also occur in a different order from the order marked in the accompanying drawings. For example, two boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram or flow chart, and the combination of the boxes in the block diagram or flow chart can be implemented with a dedicated hardware-based system that performs a specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.
[0140] The units involved in the embodiments described in the present disclosure may be implemented by software or hardware, and the units described may also be arranged in a processor. The names of these units do not, in some cases, constitute limitations on the units themselves.
[0141] As another aspect, the present disclosure further provides a computer-readable medium, which may be included in the electronic device described in the above embodiment; or may exist independently without being assembled into the electronic device. The above computer-readable medium carries one or more programs, and when the above one or more programs are executed by an electronic device, the electronic device implements the method described in the above embodiment.
[0142] It should be noted that, although several modules or units of the device for action execution are mentioned in the above detailed description, this division is not mandatory. In fact, according to the embodiments of the present disclosure, the features and functions of two or more modules or units described above can be embodied in one module or unit. On the contrary, the features and functions of one module or unit described above can be further divided into multiple modules or units to be embodied.
[0143] Through the description of the above implementation, it is easy for those skilled in the art to understand that the example implementation described here can be implemented by software, or by software combined with necessary hardware. Therefore, the technical solution according to the implementation of the present disclosure can be embodied in the form of a software product, which can be stored in a non-volatile storage medium (which can be a CD-ROM, a USB flash drive, a mobile hard disk, etc.) or on a network, including several instructions to enable a computing device (which can be a personal computer, a server, a touch terminal, or a network device, etc.) to execute the method according to the implementation of the present disclosure.
[0144] Those skilled in the art will readily appreciate other embodiments of the present disclosure after considering the specification and practicing the invention disclosed herein. The present disclosure is intended to cover any variations, uses or adaptations of the present disclosure that follow the general principles of the present disclosure and include common knowledge or customary technical means in the art that are not disclosed in the present disclosure.
[0145] It should be understood that the present disclosure is not limited to the exact structures that have been described above and shown in the drawings, and that various modifications and changes may be made without departing from the scope thereof. The scope of the present disclosure is limited only by the appended claims.
Claims
1. A method for generating a SQL statement, characterized in that: include: Receiving a user's voice command and converting the voice command into text information; Performing semantic analysis on the text information to obtain dependency relationship information between core words and associated words related thereto; Preliminarily constructing first mapping information of keywords and components according to the type of SQL statement, and constructing second mapping information of keywords and statement content according to the content of the SQL statement; Matching the core vocabulary and the associated vocabulary with the keyword to determine a first keyword corresponding to the core vocabulary and a second keyword corresponding to the associated vocabulary; extracting a plurality of components corresponding to the first keyword as target components using the first mapping information; extracting sentence contents corresponding to the second keyword using the second mapping information, and combining the sentence contents based on the dependency information to determine component contents; An SQL statement corresponding to the voice instruction is generated according to the target component and the component content.
2. The SQL statement generation method according to claim 1, characterized in that: Before performing semantic analysis on the text information, the method further includes: Performing pre-segmentation processing on the text information to extract corpus feature words; Selecting a target corpus that matches the characteristic vocabulary of the corpus from each preset basic corpus; The text information is segmented based on the target corpus to obtain a plurality of words as segmented text information.
3. The SQL statement generation method according to claim 2, characterized in that: The semantic analysis of the text information to obtain dependency relationship information between the core words and the associated words related thereto includes: Performing part-of-speech tagging on the words in the word segmentation text information; Semantic analysis is performed according to the number of words with predicate parts of speech in the word segmentation text information after part-of-speech tagging to determine the core words and the dependency relationship information.
4. The SQL statement generation method according to claim 3, characterized in that: The performing semantic analysis according to the number of words with predicate part of speech in the word segmentation text information after part of speech tagging to determine the core words and the dependency relationship information includes: Performing dependency syntactic analysis on the segmented text information to obtain first dependency relationship information; and calculating the number N of words with predicate parts of speech in the segmented text information, where N is a positive integer; When N=1, the vocabulary with the predicate part of speech is configured as the core vocabulary, and the first dependency information is configured as the dependency information; When N>1, semantic role labeling is performed on the segmented text information to obtain the core vocabulary, and the dependency information is extracted from the first dependency information based on the core vocabulary.
5. The SQL statement generation method according to claim 4, characterized in that: When N=1, the method further includes: Performing semantic role labeling on the word segmentation text information to obtain a first core vocabulary; When the vocabulary with the predicate part of speech matches the first core vocabulary, the vocabulary with the predicate part of speech is configured as the core vocabulary.
6. The SQL statement generation method according to claim 1, characterized in that: Before generating the SQL statement corresponding to the voice instruction according to the target component and the component content, the method further includes: In response to the user's adding instruction, the target component and / or component content corresponding to the adding instruction is obtained for generating the SQL statement.
7. The SQL statement generation method according to claim 1, characterized in that: After extracting the target component and the component content corresponding to the target component based on the core vocabulary and the dependency information, the method further includes: comparing the target component corresponding to the component content with the extracted target component; When the comparison result is missing, missing prompt information is generated according to the missing target component.
8. The SQL statement generation method according to claim 1, characterized in that: After performing semantic analysis on the text information, the method further includes: Determining execution information corresponding to the voice command; The SQL statement is executed according to the execution information to obtain an execution result corresponding to the voice instruction.
9. The SQL statement generation method according to claim 1, characterized in that: The method further comprises: Constructing third mapping information between sentence patterns and core vocabulary in advance according to the results of semantic analysis; Performing sentence recognition on the text information; When the recognition result includes a target sentence pattern matching the sentence pattern, the core vocabulary is determined using the third mapping information to generate the SQL statement.
10. A device for generating SQL statements, characterized in that: include: A receiving module, used for receiving a user's voice command and converting the voice command into text information; An analysis module, used for performing semantic analysis on the text information to obtain dependency relationship information between core words and associated words related thereto; An extraction module is used to construct first mapping information of keywords and components according to the type of SQL statement in advance, and to construct second mapping information of keywords and statement content according to the content of the SQL statement; match the core vocabulary and the associated vocabulary with the keyword to determine a first keyword corresponding to the core vocabulary and a second keyword corresponding to the associated vocabulary; and extract multiple components corresponding to the first keyword as target components using the first mapping information; extracting sentence contents corresponding to the second keyword using the second mapping information, and combining the sentence contents based on the dependency information to determine component contents; A generation module is used to generate an SQL statement corresponding to the voice instruction according to the target component and the component content.
11. A computer-readable storage medium having a computer program stored thereon, wherein when the program is executed by a processor, the method for generating an SQL statement according to any one of claims 1 to 9 is implemented.
12. An electronic device, characterized in that: include: one or more processors; A storage device, used to store one or more programs, when the one or more programs are executed by the one or more processors, enables the one or more processors to implement the SQL statement generation method according to any one of claims 1 to 9.
Citation Information
Patent Citations
Chinese entity relation extraction method based on keyword and verb dependency
CN109241538A
Voice inquiry method and device and electronic device
CN109542929A
Semantic analysis method and device, electronic equipment and storage medium
CN110688858A
Cited By
Generating structured query language using machine learning
US12511282B1