Question and answer correction method based on sql language, electronic equipment and storage medium
Patent Information
- Application Number
- CN202411390527.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-10-08
- Publication Date
- 2025-01-07
- Estimated Expiration
- 2044-10-08
AI Technical Summary
当用户提出的问题中的语义过少或用户提出的问题有误时,由于问答系统只对问题进行直接语义转换,无法对用户提出的问题进行异常校验,因此问答系统对用户提出的问题的解析就会发生异常,会导致生成的答复语句的意思混乱,无法对用户提出的问题进行准确解答
[0052] The question and answer correction method based on SQL language of the present invention obtains several user question keywords by splitting the user question statements, and then performs SQL language conversion on each user question keyword to obtain the initial SQL index statement, and based on the initial The sql index statement determines the initial index result from the information database. If the initial index result indicates an abnormality in the question and answer index, it means that the initial sql index statement needs to be corrected, and it is determined from several sql index conditions. The abnormal index condition is found, and the corrected index condition corresponding to the abnormal index condition is determined. The corrected index condition is the sql index condition that needs to be corrected when an index exception occurs. Among several sql index conditions, the remaining sql index conditions except the abnormal index condition are Integrate with the modified index conditions to obtain the modified SQL index statement. Finally, determine the modified index result based on the modified SQL index statement. If the modified index result indicates that the question and answer index is normal, a target reply statement is generated. By verifying the results of the SQL index conditions corresponding to the user's question statements, the abnormal index conditions that may cause abnormal index results are determined, and the corrected index conditions are determined based on the abnormal index conditions, and the corrected index conditions are combined with the non-abnormal index conditions. The sql index statement is verified again. If the verification is normal, it means that the sql index statement is corrected to a normal index statement to correct the incorrect natural language questions raised by the user so that the response results are more consistent with the questions raised by the user. To improve the accuracy of user Q&A and user satisfaction.
Smart Images

Figure CN119271698A_ABST
Abstract
Description
Background Art
[0002] The current intelligent question-answering system for users analyzes the questions raised by users, finds the corresponding information data from the database based on the index words obtained from the analysis, and finally generates a reply statement and returns it to the user. When the semantics of the questions raised by users are too few or the questions raised by users are incorrect, since the question-answering system only performs direct semantic conversion on the questions and cannot perform abnormality check on the questions raised by users, the analysis of the questions raised by users by the question-answering system will be abnormal, resulting in confusion in the meaning of the generated reply statement, and failure to accurately answer the questions raised by users. Summary of the invention
[0003] In view of the above technical problems, the technical solution adopted by the present invention is:
[0004] According to one aspect of the present application, a question and answer correction method based on SQL language is provided, comprising the following steps:
[0005] Step S100: In response to receiving a user question sentence, split the user question sentence to obtain a number of user question keywords included in the user question sentence;
[0006] Step S200: convert each user question keyword into SQL language to obtain an initial SQL index statement corresponding to the user question statement; the initial SQL index statement includes a number of SQL index conditions; each SQL index condition corresponds to an index identifier, and the index identifier indicates the index type of the corresponding SQL index condition;
[0007] Step S300: Determine the initial index result from the information database according to the initial SQL index statement;
[0008] Step S400: If the initial index result indicates that the question-answer index is abnormal, then determine the abnormal index condition from a number of SQL index conditions;
[0009] Step S500: according to the index identifier corresponding to the abnormal index condition, determine the modified index condition corresponding to the abnormal index condition from a preset index identifier list; the index identifier list stores mapping relationships between index conditions having similar association relationships with several index conditions;
[0010] Step S600: Integrate the remaining SQL index conditions except the abnormal index condition among the plurality of SQL index conditions with the modified index condition to obtain a modified SQL index statement;
[0011] Step S700, determining a revised index result from the information database according to the revised SQL index statement;
[0012] Step S800: If the modified index result indicates that the question-answer index is normal, a target answer statement is generated and output according to the modified index result and the user's question statement.
[0013] In an exemplary embodiment of the present application, step S100 includes:
[0014] Step S110, performing multiple rounds of rewriting processing on the user's question sentence to obtain a corresponding target question sentence;
[0015] Step S120: semantically analyze the target question sentence to obtain a semantic identifier corresponding to each target question word included in the target question sentence;
[0016] Step S130: traverse each target question word, and if the semantic identifier corresponding to the target question word is a preset key semantic identifier, determine the target question word as the user's question keyword.
[0017] In an exemplary embodiment of the present application, step S200 includes:
[0018] Step S210: according to the semantic identifier corresponding to each user's question keyword, determine the index identifier corresponding to each user's question keyword from a preset semantic identifier mapping table; the semantic identifier mapping table stores mapping relationships between a plurality of semantic identifiers and index identifiers corresponding to the semantic identifiers;
[0019] Step S220: converting several user question keywords into SQL language to obtain SQL index conditions corresponding to each user question keyword;
[0020] Step S230: sort the index identifiers corresponding to the plurality of SQL index conditions according to a preset index statement composition rule; the index statement composition rule includes a composition order of index types in the index statement;
[0021] Step S240: According to the order of the plurality of index identifiers, the SQL index conditions corresponding to each index identifier are integrated to obtain an initial SQL index statement.
[0022] In an exemplary embodiment of the present application, step S220 includes:
[0023] Step S221: Obtain the character length of each keyword in the user's question, and obtain the first character length list B = (B1, B2, ..., B g ,...,B h ), where g = 1, 2, ..., h; h is the number of keywords asked by the user; B g The character length of the keyword asked by the g-th user;
[0024] Step S222, traverse the first character length list B, if B g ≥ B0, the g-th user's question keyword is determined as the target user's question keyword to obtain a number of target user's question keywords; wherein B0 is a preset character length threshold;
[0025] Step S223: rewrite each target user question keyword according to a preset character abbreviation rule to obtain a rewritten user question keyword corresponding to each target user question keyword; the character length of the rewritten user question keyword is shorter than the character length of the target user question keyword corresponding to the rewritten user question keyword;
[0026] Step S224: Obtain the information entropy of each target user's question keyword to obtain a first information entropy list C = (C1, C2, ..., C a ,...,C b ), where a = 1, 2, ..., b; b is the number of keywords asked by the target user; C a The information entropy of the keywords asked by the a-th target user;
[0027] Step S225: Obtain the information entropy of each rewritten user question keyword to obtain a second information entropy list D = (D1, D2, ..., D a ,...,D b ), where D a is the information entropy of the rewritten user's question keywords obtained by rewriting the a-th target user's question keywords;
[0028] Step S226, traverse the first information entropy list C and the second information entropy list D, if |D a -C a |≤d, then the rewritten user question keyword corresponding to the a-th target user question keyword is determined as the SQL index condition corresponding to the a-th target user question keyword; where d is the preset information entropy difference threshold.
[0029] In an exemplary embodiment of the present application, step S222 further includes:
[0030] Step S2221: If B g <B0, then obtain the information entropy R of the keyword asked by the g-th user g ;
[0031] Step S2222: If R g ≥R0, the g-th user question keyword is determined as the SQL index condition; otherwise, step S2223 is executed; wherein R0 is a preset information entropy threshold;
[0032] Step S2223: Delete the keyword asked by the gth user.
[0033] In an exemplary embodiment of the present application, step S300 includes:
[0034] Step S310: Obtain the index identifier corresponding to each SQL index condition in the initial SQL index statement, and obtain an index identifier list T = (T1, T2, ..., T m ,...,T q ), where m = 1, 2, ..., q, q is the number of SQL index conditions, T m The index identifier corresponding to the mth SQL index condition in the initial SQL index statement;
[0035] Step S320: traverse the index identifier list T, through T m Corresponding to the index type, a number of response data having the same data type as the index type are determined from the information database;
[0036] Step S330: According to T m The corresponding sql index condition is traversed through each response data. If there is response data corresponding to the sql index condition, the response data is determined as the index data corresponding to the mth sql index condition, and step S340 is executed; otherwise, a question-answering abnormality flag is generated, and T m and the question-answer anomaly flag are determined as the initial index results;
[0037] Step S340: Integrate a plurality of index data according to a plurality of SQL index conditions in the initial SQL index statement to obtain an integration result;
[0038] Step S350: If an abnormality occurs in the integration result, a question-answer abnormality mark is generated, and the abnormal index data and the question-answer abnormality mark corresponding to the integration result are determined as the initial index result; otherwise, the integration result is determined as the initial index result.
[0039] In an exemplary embodiment of the present application, step S400 includes:
[0040] Step S411: If the initial index result includes a question-answer anomaly indicator, determine whether the initial index result includes index data. If the initial index result includes index data, execute step S412; otherwise, execute step S413;
[0041] Step S412: determining the SQL index conditions corresponding to the plurality of index data included in the initial index result as abnormal index conditions;
[0042] Step S413: Determine, among the plurality of SQL index conditions, the SQL index conditions that have no corresponding relationship with any response data as abnormal index conditions.
[0043] In an exemplary embodiment of the present application, step S800 further includes:
[0044] Step S810: If the modified index result indicates that the question-answer index is abnormal, the modified index condition and the abnormal index condition are deleted, and the remaining SQL index conditions are integrated to obtain the target SQL index statement;
[0045] Step S820: Determine the target index result from the information database according to the target SQL index statement;
[0046] Step S830: Generate a target answer statement according to the target index result and the user's question statement;
[0047] Step S840: convert the abnormal index condition into natural language to obtain an abnormal index statement;
[0048] Step S850: output the target reply statement and the exception index statement.
[0049] According to one aspect of the present application, a non-transitory computer-readable storage medium is provided, in which at least one instruction or at least one program is stored, and the at least one instruction or the at least one program is loaded and executed by a processor to implement the aforementioned SQL language-based question and answer correction method.
[0050] According to one aspect of the present application, an electronic device is provided, including a processor and the aforementioned non-transitory computer-readable storage medium.
[0051] The present invention has at least the following beneficial effects:
[0052] The question and answer correction method based on the SQL language of the present invention obtains several user question keywords by splitting the user question statement, and then converts each user question keyword into SQL language to obtain an initial SQL index statement, and determines the initial index result from the information database based on the initial SQL index statement. If the initial index result indicates that the question and answer index is abnormal, it means that the initial SQL index statement needs to be corrected, then the abnormal index condition is determined from several SQL index conditions, and the corrected index condition corresponding to the abnormal index condition is determined. The corrected index condition is the SQL index condition that needs to be corrected when the index abnormality occurs. The remaining SQL index conditions except the abnormal index condition in the several SQL index conditions are integrated with the corrected index condition to obtain a corrected SQL index statement. Finally, the corrected index result is determined based on the corrected SQL index statement. If the corrected index result indicates that the question and answer index is normal, the target reply statement is generated. By verifying the results of the SQL index conditions corresponding to the user's question statements, the abnormal index conditions that may cause abnormal index results are determined, and the corrected index conditions are determined based on the abnormal index conditions. The corrected SQL index statement composed of the corrected index conditions and the non-abnormal index conditions is verified again. If the verification is normal, it means that the corrected SQL index statement is a normal index statement, so as to correct the incorrect natural language questions raised by the user, so that the answer results are more in line with the questions raised by the user, so as to improve the accuracy of user questions and answers and user satisfaction. BRIEF DESCRIPTION OF THE DRAWINGS
[0053] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the following briefly introduces the drawings required for use in the description of the embodiments. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.
[0054] Figure 1 A flowchart of a question and answer correction method based on SQL language provided in an embodiment of the present invention. DETAILED DESCRIPTION
[0055] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative work are within the scope of protection of the present invention.
[0056] like Figure 1 As shown, the question and answer correction method based on SQL language described in this application includes the following steps:
[0057] Step S100: In response to receiving a user question sentence, split the user question sentence to obtain a number of user question keywords included in the user question sentence;
[0058] User question statements are statements written in natural language proposed by users. Since the data stored in the information database is in computer language, if you want to index it in the information database, you need to convert the natural language. At present, most of the data in the information database is stored in SQL language. Therefore, it is necessary to convert the user question statements in natural language into SQL language statements. Before performing language conversion, you need to split the user question statements to obtain several user question keywords included in the user question statements. User question keywords are keywords in the user question statements that can represent semantic information.
[0059] Further, step S100 includes steps S110 to S130:
[0060] Step S110, performing multiple rounds of rewriting processing on the user's question sentence to obtain a corresponding target question sentence;
[0061] Multiple rounds of rewriting can adopt existing processing methods. Multiple rounds of rewriting are used to semantically supplement user question sentences. If the user question sentence is too simple, such as lacking a subject, if the user question sentence is directly converted into SQL language, the converted SQL statement will also lack corresponding keywords, which will cause abnormalities in subsequent indexes. Therefore, the user question sentence is first rewritten for multiple rounds, and the user question sentence is semantically expanded by connecting the upper and lower sentences of the user's question, and then SQL language conversion is performed, which can improve the accuracy of the user's reply.
[0062] Step S120: semantically analyze the target question sentence to obtain a semantic identifier corresponding to each target question word included in the target question sentence;
[0063] After obtaining the target question sentence, a semantic analysis is performed on the target question sentence, that is, the target question sentence is split into keywords to obtain the target question words included in the target question sentence, wherein the semantic analysis and keyword splitting can adopt the existing analysis methods, and the target question words correspond to semantic identifiers, and the semantic identifiers indicate the semantic type of the corresponding target question words, such as whether the target question word is the subject, predicate, or object of the target question sentence. Through the semantic identifier, it can be determined whether the target question word plays a key role in information indexing.
[0064] Step S130: traverse each target question word, and if the semantic identifier corresponding to the target question word is a preset key semantic identifier, determine the target question word as the user's question keyword.
[0065] The preset key semantic identifier is the semantic identifier of the indispensable semantic type when indexing information. The key semantic identifier can be obtained by performing keyword splitting statistics on several historical natural languages.
[0066] Step S200: convert each user question keyword into SQL language to obtain an initial SQL index statement corresponding to the user question statement; the initial SQL index statement includes a number of SQL index conditions;
[0067] Each sql index condition corresponds to an index identifier, and the index identifier indicates the index type of the corresponding sql index condition.
[0068] By parsing the initial sql index statement, several sql index conditions are obtained. The sql index condition is a conditional statement for information indexing in the information database. Through the sql index condition, the type and location of the information data to be indexed in the information database can be known.
[0069] Further, step S200 includes steps S210 to S240:
[0070] Step S210: According to the semantic identifier corresponding to each keyword in the user's question, determine the index identifier corresponding to each keyword in the user's question from a preset semantic identifier mapping table;
[0071] The semantic identifier mapping table stores mapping relationships between a number of semantic identifiers and index identifiers corresponding to the semantic identifiers. By viewing the semantic identifier mapping table, the mapping relationship between the semantic identifier and the index identifier can be known.
[0072] For example, if the target question sentence is "What time does my flight take off tomorrow?", after semantic analysis of the target question sentence, one of the target question words obtained is "flight", and the semantic identifier corresponding to the target question word is represented as the predicate, and its corresponding index identifier is represented as the flight information type.
[0073] Step S220: converting several user question keywords into SQL language to obtain SQL index conditions corresponding to each user question keyword;
[0074] The sql index condition is a conditional statement with an sql index function obtained after sql language conversion based on the keywords in the user's question.
[0075] Wherein, step S220 includes steps S221 to S226:
[0076] Step S221: Obtain the character length of each keyword in the user's question, and obtain the first character length list B = (B1, B2, ..., B g,...,B h ), where g = 1, 2, ..., h; h is the number of keywords asked by the user; B g The character length of the keyword asked by the g-th user;
[0077] Step S222, traverse the first character length list B, if B g ≥ B0, the g-th user question keyword is determined as the target user question keyword to obtain a number of target user question keywords, and step S223 is executed; otherwise, steps S2221 to S2223 are executed; wherein B0 is a preset character length threshold;
[0078] Step S2221: If B g <B0, then obtain the information entropy R of the keyword asked by the g-th user g ;
[0079] Step S2222: If R g ≥R0, the g-th user question keyword is determined as the SQL index condition; otherwise, step S2223 is executed; wherein R0 is a preset information entropy threshold;
[0080] Step S2223: Delete the keyword asked by the gth user.
[0081] The information entropy of a user's question keyword indicates the amount of information contained in the user's question keyword. The larger the information entropy, the more information is contained in the corresponding user's question keyword, that is, the more important the user's question keyword is when indexing information.
[0082] The character length of the index condition is directly proportional to the index time and the computing power occupied by the index. When indexing information, the longer the character length of the index condition, the greater the computing power occupied by the index and the longer the index time. Therefore, the character length of the index condition becomes a key factor in reducing the index time.
[0083] If the character length of the user's question keyword is less than the character length threshold, and the information entropy of the user's question keyword is also less than the information entropy threshold, it means that the amount of information contained in the user's question keyword is too small and has little impact on the understanding of the entire sentence. Therefore, in order to reduce the amount of data processing, choose to delete the user's question keyword and do not convert it into SQL language.
[0084] Step S223: rewrite each target user's question keyword according to a preset character abbreviation rule to obtain a rewritten user question keyword corresponding to each target user's question keyword;
[0085] The character length of the rewritten user question keyword is shorter than the character length of the target user question keyword corresponding to the rewritten user question keyword. When the character length of the user question keyword is too long, it means that the indexing time of the user question keyword is too long during indexing. Therefore, in order to reduce the processing volume of information indexing, it is necessary to rewrite the user question keyword and shorten its character length.
[0086] Step S224: Obtain the information entropy of each target user's question keyword to obtain a first information entropy list C = (C1, C2, ..., C a ,...,C b ), where a = 1, 2, ..., b; b is the number of keywords asked by the target user; C a The information entropy of the keywords asked by the a-th target user;
[0087] Step S225: Obtain the information entropy of each rewritten user question keyword to obtain a second information entropy list D = (D1, D2, ..., D a ,...,D b ), where D a is the information entropy of the rewritten user's question keywords obtained by rewriting the a-th target user's question keywords;
[0088] Step S226, traverse the first information entropy list C and the second information entropy list D, if |D a -C a |≤d, then the rewritten user question keyword corresponding to the a-th target user question keyword is determined as the SQL index condition corresponding to the a-th target user question keyword; where d is the preset information entropy difference threshold.
[0089] After rewriting the keywords in the user's question, it is also necessary to confirm whether the information entropy before and after the rewriting has changed. If the difference in information entropy before and after the rewriting is less than or equal to the information entropy difference threshold, it means that the amount of information has not been lost too much. Therefore, it is determined as the SQL index condition.
[0090] Step S230: sort the index identifiers corresponding to the plurality of SQL index conditions according to the preset index statement composition rule;
[0091] The index statement composition rule includes the composition order of the index types in the index statement. The index statement composition rule may be a specific statement composition rule determined manually, such as the composition order of the index types being "query time", "flight", and "take-off time".
[0092] Step S240: According to the order of the plurality of index identifiers, the SQL index conditions corresponding to each index identifier are integrated to obtain an initial SQL index statement.
[0093] By integrating several sql index conditions, an initial sql index statement is obtained. The initial sql index statement is an index statement used for information indexing. Since each sql index condition is looking for different data information, such as the sql index conditions are "flight", "tomorrow", and "take-off time", it is impossible to know the original intention of the user's question by only looking at a single sql index condition. Therefore, all sql index conditions are integrated to obtain the initial sql index statement "flight tomorrow's take-off time" (this statement should be written in sql language, and natural language is used for ease of understanding). The original intention of the user's question can be known through the initial sql index statement.
[0094] The integration method of sql index conditions adopts existing sql language writing rules.
[0095] Step S300: Determine the initial index result from the information database according to the initial SQL index statement;
[0096] The initial index result is the result obtained by indexing the information database through the initial SQL index statement.
[0097] Further, step S300 includes steps S310 to S350:
[0098] Step S310: Obtain the index identifier corresponding to each SQL index condition in the initial SQL index statement, and obtain an index identifier list T = (T1, T2, ..., T m ,...,T q ), where m = 1, 2, ..., q, q is the number of SQL index conditions, T m The index identifier corresponding to the mth SQL index condition in the initial SQL index statement;
[0099] Step S320: traverse the index identifier list T, through T m Corresponding to the index type, a number of response data having the same data type as the index type are determined from the information database;
[0100] When information data in the information database is stored in the information database, it will carry the corresponding data type identifier to indicate the data type to which the information data belongs. Therefore, when it is necessary to traverse the information data in the information database, directly according to the index type of each SQL index condition, several information data of the same data type as the index type are found in the information database without traversing each information data in the information database. Therefore, the index processing amount of the information data is reduced and the indexing time is shortened.
[0101] Step S330: According to T mThe corresponding sql index condition is traversed through each response data. If there is response data corresponding to the sql index condition, the response data is determined as the index data corresponding to the mth sql index condition, and step S340 is executed; otherwise, a question-answering abnormality flag is generated, and T m and the question-answer anomaly flag are determined as the initial index results;
[0102] After finding the response data with the same index type as the sql index condition, find the index data corresponding to the sql index condition from several response data according to the specific information of the sql index condition. For example, if the index type of the sql index condition is "flight", then the data type of all the response data found is "flight" type. There are flights of all airlines in this batch of response data. If the sql index condition is "flights of Airline A", then find the response data of "Airline A" from all the response data with the data type of "flight" and determine it as the index data.
[0103] If no response data of "Airline A" is found from all response data with data type "flight", it means that Airline A may not exist, that is, Airline A may be erroneous information entered by the user, then a question and answer exception identifier is generated, and the index identifier and question and answer exception identifier corresponding to the SQL index condition are determined as the initial index result.
[0104] By verifying the initial index results, it is possible to check whether the questions raised by the user are correct. If so, the questions will be corrected instead of directly returning abnormal error information to the user, so as to meet user needs to the greatest extent possible.
[0105] Step S340: Integrate a plurality of index data according to a plurality of SQL index conditions in the initial SQL index statement to obtain an integration result;
[0106] After obtaining the index data corresponding to each SQL index condition, it is necessary to integrate them so that several index data can be combined with each other to achieve the purpose of screening. For example, the SQL index conditions are "Airline A", "Tomorrow", and "Departure Time". However, among all the index data found, when all the index data are integrated, there is no flight information of Airline A taking off tomorrow. Therefore, the integration result is abnormal and needs to be corrected.
[0107] Step S350: If an abnormality occurs in the integration result, a question-answer abnormality mark is generated, and the abnormal index data and the question-answer abnormality mark corresponding to the integration result are determined as the initial index result; otherwise, the integration result is determined as the initial index result.
[0108] Step S400: If the initial index result indicates that the question-answer index is abnormal, then determine the abnormal index condition from a number of SQL index conditions;
[0109] Abnormal index conditions are SQL index conditions where abnormalities occur or incorrect input is made.
[0110] Further, step S400 includes step S411-step S413:
[0111] Step S411: If the initial index result includes a question-answer anomaly indicator, determine whether the initial index result includes index data. If the initial index result includes index data, execute step S412; otherwise, execute step S413;
[0112] If the initial index result does not include the question and answer anomaly mark, the initial index result and the user's question sentence are input into the preset general language model to obtain the target answer sentence and output it.
[0113] Step S412: determining the SQL index conditions corresponding to the plurality of index data included in the initial index result as abnormal index conditions;
[0114] Step S413: Determine, among the plurality of SQL index conditions, the SQL index conditions that have no corresponding relationship with any response data as abnormal index conditions.
[0115] Step S500: According to the index identifier corresponding to the abnormal index condition, determine the modified index condition corresponding to the abnormal index condition from a preset index identifier list;
[0116] The index identification list stores mapping relationships between index conditions that have similar association relationships with several index conditions.
[0117] The revised index condition is an index condition that has a similar correlation with the corresponding abnormal index condition, and is obtained by developers based on statistics of historical index conditions. The developer counts the index conditions that have had index errors during the historical period, and modifies and corrects them to make their indexes normal. The index condition obtained after the modification and correction is the revised index condition, and the revised index condition and the index condition before the modification and correction are stored in the index identification list.
[0118] Step S600: Integrate the remaining SQL index conditions except the abnormal index condition among the plurality of SQL index conditions with the modified index condition to obtain a modified SQL index statement;
[0119] Since the abnormal index condition is a keyword with errors, the other SQL index conditions except the abnormal index condition are integrated with the corrected index condition to obtain a corrected SQL index statement, and then the corrected SQL index statement is verified again.
[0120] Step S700, determining a revised index result from the information database according to the revised SQL index statement;
[0121] Step S800: If the modified index result indicates that the question-answer index is normal, then generate and output a target answer statement based on the modified index result and the user's question statement; otherwise, execute steps S810 to S850;
[0122] If the result of index correction indicates that the Q&A index is normal, it means that the abnormal index condition is indeed an index condition that may cause an index error, and it will be deleted.
[0123] The target reply sentence is to process the modified index result and the user's question sentence through a preset general language model to obtain a target reply sentence in natural language.
[0124] The general language model can adopt the existing language model (general language model), which is used to generate a target answer sentence in natural language from the modified index result of the SQL language according to the user's question sentence, and return the target answer sentence to the user for the user to view.
[0125] Step S810: If the modified index result indicates that the question-answer index is abnormal, the modified index condition and the abnormal index condition are deleted, and the remaining SQL index conditions are integrated to obtain the target SQL index statement;
[0126] Step S820: Determine the target index result from the information database according to the target SQL index statement;
[0127] Step S830: Generate a target answer statement according to the target index result and the user's question statement;
[0128] Step S840: convert the abnormal index condition into natural language to obtain an abnormal index statement;
[0129] Step S850: output the target reply statement and the exception index statement.
[0130] If the corrected index result still indicates that the question and answer index is abnormal, it means that the corrected index condition may also have an index error, so it will also be deleted, and the remaining sql index conditions will be integrated again to obtain the target sql index statement. In order to shorten the data processing time, the target index result will no longer be verified and will be output directly. The abnormal index statement obtained according to the abnormal index condition will also be output together to prompt the user to self-check the user's question statement and verify the correctness of the target answer statement by himself.
[0131] The question and answer correction method based on the SQL language of the present invention obtains several user question keywords by splitting the user question statement, and then converts each user question keyword into SQL language to obtain an initial SQL index statement, and determines the initial index result from the information database based on the initial SQL index statement. If the initial index result indicates that the question and answer index is abnormal, it means that the initial SQL index statement needs to be corrected, then the abnormal index condition is determined from several SQL index conditions, and the corrected index condition corresponding to the abnormal index condition is determined. The corrected index condition is the SQL index condition that needs to be corrected when the index abnormality occurs. The remaining SQL index conditions except the abnormal index condition in the several SQL index conditions are integrated with the corrected index condition to obtain a corrected SQL index statement. Finally, the corrected index result is determined based on the corrected SQL index statement. If the corrected index result indicates that the question and answer index is normal, the target reply statement is generated. By verifying the results of the SQL index conditions corresponding to the user's question statements, the abnormal index conditions that may cause abnormal index results are determined, and the corrected index conditions are determined based on the abnormal index conditions. The corrected SQL index statement composed of the corrected index conditions and the non-abnormal index conditions is verified again. If the verification is normal, it means that the corrected SQL index statement is a normal index statement, so as to correct the incorrect natural language questions raised by the user, so that the answer results are more in line with the questions raised by the user, so as to improve the accuracy of user questions and answers and user satisfaction.
[0132] An embodiment of the present invention further provides a computer program product, which includes program code. When the program product is run on an electronic device, the program code is used to enable the electronic device to execute the steps of the method according to various exemplary embodiments of the present invention described above in this specification.
[0133] In addition, although the steps of the method in the present disclosure are described in a specific order in the drawings, this does not require or imply that the steps must be performed in this specific order, or that all the steps shown must be performed to achieve the desired results. Additionally or alternatively, some steps may be omitted, multiple steps may be combined into one step, and / or one step may be decomposed into multiple steps, etc.
[0134] 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 mobile terminal, or a network device, etc.) to execute the method according to the implementation of the present disclosure.
[0135] In an exemplary embodiment of the present disclosure, an electronic device capable of implementing the above method is also provided.
[0136] It will be appreciated by those skilled in the art that various aspects of the present invention may be implemented as a system, method or program product. Therefore, various aspects of the present invention may be specifically implemented in the following forms, namely: a complete hardware implementation, a complete software implementation (including firmware, microcode, etc.), or a combination of hardware and software, which may be collectively referred to herein as a "circuit", "module" or "system".
[0137] The electronic device according to this embodiment of the present invention is only an example and should not bring any limitation to the functions and scope of use of the embodiments of the present invention.
[0138] The electronic device is presented in the form of a general-purpose computing device. The components of the electronic device may include, but are not limited to: the at least one processor mentioned above, the at least one storage device mentioned above, and a bus connecting different system components (including storage devices and processors).
[0139] The storage stores program codes, which can be executed by the processor, so that the processor executes the steps according to various exemplary embodiments of the present invention described in the above “Exemplary Method” section of this specification.
[0140] The memory may include readable media in the form of volatile memory, such as random access memory (RAM) and / or cache memory, and may further include read only memory (ROM).
[0141] The storage may also include a program / utility having a set (at least one) of program modules, such program modules including but not limited to: an operating system, one or more application programs, other program modules and program data, each of which or some combination may include an implementation of a network environment.
[0142] The bus may represent one or more of several types of bus structures including a memory bus or memory controller, a peripheral bus, an accelerated graphics port, a processor, or a local bus using any of a variety of bus architectures.
[0143] The electronic device may also communicate with one or more external devices (e.g., keyboards, pointing devices, Bluetooth devices, etc.), one or more devices that enable a user to interact with the electronic device, and / or any device that enables the electronic device to communicate with one or more other computing devices (e.g., routers, modems, etc.). Such communication may be performed via an input / output (I / O) interface. Furthermore, the electronic device may also communicate with one or more networks (e.g., local area networks (LANs), wide area networks (WANs), and / or public networks, such as the Internet) via a network adapter.
[0144] 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 terminal device, or a network device, etc.) to execute the method according to the implementation of the present disclosure.
[0145] In an exemplary embodiment of the present disclosure, a computer-readable storage medium is also provided, on which a program product capable of implementing the above method of the present specification is stored. In some possible implementations, various aspects of the present invention can also be implemented in the form of a program product, which includes a program code, and when the program product is run on a terminal device, the program code is used to enable the terminal device to execute the steps according to various exemplary embodiments of the present invention described in the above "Exemplary Method" section of the present specification.
[0146] The program product may use any combination of one or more readable media. The readable medium may be a readable signal medium or a readable storage medium. The 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 (non-exhaustive list) of readable storage media include: an electrical connection with one or more wires, a portable disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above.
[0147] Computer readable signal media may include data signals propagated in baseband or as part of a carrier wave, in which 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. Readable signal media may also be any readable medium other than a readable storage medium, which may send, propagate, or transmit a program for use by or in conjunction with an instruction execution system, apparatus, or device.
[0148] The program code embodied on the readable medium may be transmitted using any appropriate medium, including but not limited to wireless, wired, optical cable, RF, etc., or any suitable combination of the foregoing.
[0149] Program code for performing the operations of the present invention may be written in any combination of one or more programming languages, including object-oriented programming languages such as Java, C++, etc., and conventional procedural programming languages such as "C" or similar programming languages. The program code may be executed entirely on the user computing device, partially on the user device, as a separate software package, partially on the user computing device and partially on a remote computing device, or entirely on a remote computing device or server. In cases involving a remote computing device, the remote computing device may be connected to the user computing device through any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computing device (e.g., through the Internet using an Internet service provider).
[0150] In addition, the above-mentioned figures are only schematic illustrations of the processes included in the method according to an exemplary embodiment of the present invention, and are not intended to be limiting. It is easy to understand that the processes shown in the above-mentioned figures do not indicate or limit the time sequence of these processes. In addition, it is also easy to understand that these processes can be performed synchronously or asynchronously, for example, in multiple modules.
[0151] 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.
[0152] The above is only a specific embodiment of the present invention, but the protection scope of the present invention is not limited thereto. Any changes or substitutions that can be easily thought of by a person skilled in the art within the technical scope disclosed by the present invention should be included in the protection scope of the present invention. Therefore, the protection scope of the present invention shall be subject to the protection scope of the claims.
Claims
1. A question and answer correction method based on SQL language, characterized in that: The method comprises the following steps: Step S100: In response to receiving a user question statement, split the user question statement to obtain a number of user question keywords included in the user question statement; Step S200: performing SQL language conversion on each of the user's question keywords to obtain an initial SQL index statement corresponding to the user's question statement; the initial SQL index statement includes a plurality of SQL index conditions; each of the SQL index conditions corresponds to an index identifier, and the index identifier indicates an index type of the corresponding SQL index condition; Step S300: determining an initial index result from an information database according to the initial SQL index statement; Step S400: If the initial index result indicates that the question-answer index is abnormal, then determine the abnormal index condition from a plurality of SQL index conditions; Step S500: determining a modified index condition corresponding to the abnormal index condition from a preset index identifier list according to the index identifier corresponding to the abnormal index condition; The index identification list stores mapping relationships between index conditions that have similar association relationships with a number of index conditions; Step S600: Integrate the remaining sql index conditions except the abnormal index condition among the plurality of sql index conditions with the modified index condition to obtain a modified sql index statement; Step S700: Determine a modified index result from the information database according to the modified SQL index statement; Step S800: If the modified index result indicates that the question-answer index is normal, a target answer statement is generated and output according to the modified index result and the user question statement.
2. The method according to claim 1, characterized in that The step S100 includes: Step S110, performing multiple rounds of rewriting processing on the user question sentence to obtain a corresponding target question sentence; Step S120: semantically analyze the target question sentence to obtain a semantic identifier corresponding to each target question word included in the target question sentence; Step S130: traverse each of the target question words, and if the semantic identifier corresponding to the target question word is a preset key semantic identifier, determine the target question word as a user question keyword.
3. The method according to claim 2, characterized in that The step S200 includes: Step S210: according to the semantic identifier corresponding to each keyword in the user's question, determine the index identifier corresponding to each keyword in the user's question from a preset semantic identifier mapping table; the semantic identifier mapping table stores mapping relationships between a plurality of semantic identifiers and index identifiers corresponding to the semantic identifiers; Step S220: performing SQL language conversion on a plurality of the user question keywords to obtain a SQL index condition corresponding to each of the user question keywords; Step S230: sort the index identifiers corresponding to the plurality of SQL index conditions according to a preset index statement composition rule; the index statement composition rule includes a composition order of index types in the index statement; Step S240: According to the order of the plurality of index identifiers, the SQL index conditions corresponding to each index identifier are integrated to obtain an initial SQL index statement.
4. The method according to claim 3, characterized in that The step S220 includes: Step S221: Obtain the character length of each keyword in the user's question, and obtain a first character length list B=(B1, B2, ..., B g ,...,B h ), where g = 1, 2, ..., h, and h is the number of keywords asked by the user; B g The length of the keyword in the gth question of the user; Step S222, traverse the first character length list B, if B g ≥ B0, the g-th user question keyword is determined as the target user question keyword to obtain a number of target user question keywords; wherein B0 is a preset character length threshold; Step S223: rewrite each of the target user's question keywords according to a preset character abbreviation rule to obtain a rewritten user question keyword corresponding to each of the target user's question keywords; the character length of the rewritten user question keyword is shorter than the character length of the target user's question keyword corresponding to the rewritten user question keyword; Step S224: Obtain the information entropy of each keyword asked by the target user to obtain a first information entropy list C = (C1, C2, ..., C a ,...,C b ); where a = 1, 2, ..., b; b is the number of keywords asked by the target user; C a The information entropy of the keywords asked by the target user a; Step S225: Obtain the information entropy of each of the rewritten user question keywords to obtain a second information entropy list D = (D1, D2, ..., D a ,...,D b ), where D a is the information entropy of the rewritten user question keywords obtained by rewriting the a-th target user's question keywords; Step S226: traverse the first information entropy list C and the second information entropy list D. If |D a -C a |≤d, then the rewritten user question keyword corresponding to the a-th target user question keyword is determined as the SQL index condition corresponding to the a-th target user question keyword; wherein d is the preset information entropy difference threshold.
5. The method according to claim 4, characterized in that The step S222 further includes: Step S2221: If B g <B0, then obtain the information entropy R of the g-th user's question keyword g ; Step S2222: If R g ≥R0, the g-th user question keyword is determined as the SQL index condition; otherwise, step S2223 is executed; wherein R0 is a preset information entropy threshold; Step S2223: Delete the g-th keyword asked by the user.
6. The method according to claim 5, characterized in that The step S300 includes: Step S310: Obtain the index identifier corresponding to each of the SQL index conditions in the initial SQL index statement, and obtain an index identifier list T = (T1, T2, ..., T m ,...,T q ); where m = 1, 2, ..., q; q is the number of the sql index conditions; T m is the index identifier corresponding to the mth SQL index condition in the initial SQL index statement; Step S320: traverse the index identifier list T, and m Corresponding to the index type, a number of response data having the same data type as the index type are determined from the information database; Step S330: According to T m The corresponding sql index condition is traversed through each of the response data. If there is response data corresponding to the sql index condition, the response data is determined as the index data corresponding to the mth sql index condition, and step S340 is executed; otherwise, a question-answering abnormality flag is generated, and T m and the question-answer anomaly identifier is determined as an initial index result; Step S340: integrating the plurality of index data according to the plurality of SQL index conditions in the initial SQL index statement to obtain an integration result; Step S350: If an exception occurs in the integration result, a question-and-answer exception mark is generated, and the several index data with exceptions corresponding to the integration result and the question-and-answer exception mark are determined as the initial index result; otherwise, the integration result is determined as the initial index result.
7. The method according to claim 6, characterized in that The step S400 includes: Step S411: If the initial index result includes a question-answer anomaly indicator, determine whether the initial index result includes index data. If the initial index result includes index data, execute step S412; otherwise, execute step S413; Step S412: determining the SQL index conditions corresponding to the plurality of index data included in the initial index result as abnormal index conditions; Step S413: Determine, among the plurality of SQL index conditions, the SQL index condition that has no corresponding relationship with any of the response data as an abnormal index condition.
8. The method according to claim 7, characterized in that The step S800 further includes: Step S810: If the modified index result indicates that the question-answer index is abnormal, the modified index condition and the abnormal index condition are deleted, and the remaining SQL index conditions are integrated to obtain a target SQL index statement; Step S820: Determine a target index result from the information database according to the target SQL index statement; Step S830: Generate a target answer statement according to the target index result and the user question statement; Step S840: convert the abnormal index condition into natural language to obtain an abnormal index statement; Step S850: output the target reply statement and the exception index statement.
9. A non-transitory computer-readable storage medium, wherein at least one instruction or at least one program is stored in the storage medium, characterized in that: The at least one instruction or the at least one program is loaded and executed by the processor to implement the SQL language-based question and answer correction method as described in any one of claims 1-8.
10. An electronic device, characterized in that: The invention comprises a processor and the non-transitory computer-readable storage medium as claimed in claim 9.
Citation Information
Patent Citations
SQL query-oriented refined scoring method
CN112132420A
Language conversion method and device, electronic equipment and storage medium
CN114722069A
Automatic testing method and device for SQL statement execution in relational database
CN115344500A
Natural language intelligent query method and device based on multi-agent interaction
CN118012900A
SQL (Structured Query Language) generation method, device and equipment based on large language model and storage medium
CN118093622A