Error detection methods, devices and equipment for database query text
By decomposing the query text into text fragments and applying semantic parsing and error correction rules, the problem of inaccurate semantic error correction in existing technologies is solved, achieving higher accuracy in semantic evaluation and error correction.
Patent Information
- Application Number
- CN202510629793.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-05-15
- Publication Date
- 2026-11-17
AI Technical Summary
Existing technologies have weak semantic error correction capabilities for long texts, resulting in inaccurate detection of semantic errors in database query texts.
The query text is broken down into multiple text fragments. Suspicious text fragments are identified through semantic parsing, and corresponding semantic error correction rules are obtained from the knowledge base for evaluation. Priority is given to detecting semantic errors in suspicious text fragments.
It improves the accuracy of semantic evaluation results, enhances the ability to understand and analyze query text, and improves the accuracy of semantic error correction.
Smart Images

Figure CN123115193A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of computer technology, and in particular to a method, apparatus, and device for error detection in database query text. Background Technology
[0002] When a user inputs text to retrieve target data from a database, it is necessary to detect and correct any errors in the input text.
[0003] In related technologies, LLM (Large Language Model) is usually used to perform semantic error correction on input text. By using the rubber duck debugging method, semantic deviations in the input text are detected line by line to find semantic errors in the input text. Then, SQL (Structured Query Language) tools based on fine-tuning are used to perform semantic correction and generate corrected text. The corrected text can then be used to query the corresponding data in the database.
[0004] However, the above methods are weak in understanding and analyzing long texts, which can easily lead to inaccurate semantic correction. Summary of the Invention
[0005] This application provides a method, apparatus, and device for error detection in database query text. The technical solution provided by this application is as follows:
[0006] According to one aspect of the embodiments of this application, a method for error detection of database query text is provided, the method comprising:
[0007] Obtain query text for a database, the query text including at least one text fragment, the query text being used to query data stored in the database;
[0008] Perform semantic parsing on the query text to obtain at least one suspicious text fragment in the query text, wherein the suspicious text fragment is a text fragment that is suspected of having a semantic error;
[0009] Obtain semantic error correction rules corresponding to the at least one suspicious text fragment from the knowledge base, wherein the knowledge base includes at least one semantic error correction rule, and the semantic error correction rule is used to indicate the correction strategy for semantic errors;
[0010] Based on the semantic error correction rules corresponding to the query text, the at least one suspicious text fragment, and the at least one suspicious text fragment, a semantic evaluation result of the query text is obtained, and the semantic evaluation result is used to indicate whether there are semantic errors in the query text.
[0011] According to one aspect of the embodiments of this application, an error detection device for database query text is provided, the device comprising:
[0012] The text acquisition module is used to acquire query text for a database, the query text including at least one text fragment, the query text being used to query data stored in the database;
[0013] The semantic parsing module is used to perform semantic parsing on the query text to obtain at least one suspicious text fragment in the query text, wherein the suspicious text fragment is a text fragment that is suspected of having semantic errors;
[0014] The rule extraction module is used to obtain semantic error correction rules corresponding to the at least one suspicious text fragment from the knowledge base. The knowledge base includes at least one semantic error correction rule, which is used to indicate the correction strategy for semantic errors.
[0015] The semantic evaluation module is used to obtain the semantic evaluation result of the query text based on the semantic error correction rules corresponding to the query text, the at least one suspicious text fragment, and the at least one suspicious text fragment, respectively. The semantic evaluation result is used to indicate whether there are semantic errors in the query text.
[0016] According to one aspect of the embodiments of this application, a computer device is provided, the computer device including a processor and a memory, the memory storing a computer program, the computer program being loaded and executed by the processor to implement the above-described error detection method for database query text.
[0017] According to one aspect of the embodiments of this application, a computer-readable storage medium is provided, wherein a computer program is stored in the computer-readable storage medium, the computer program being loaded and executed by a processor to implement the above-described error detection method for database query text.
[0018] According to one aspect of the embodiments of this application, a computer program product is provided, the computer program product including a computer program, the computer program being loaded and executed by a processor to implement the above-described error detection method for database query text.
[0019] The technical solution provided in this application can bring the following beneficial effects:
[0020] By decomposing the query text into at least one text segment, localized semantic evaluation can be performed on each text segment. Compared to related technologies that directly perform semantic evaluation on the query text, the technical solution provided in this application reduces the context load when analyzing the query text, enhances the understanding and analysis capabilities of the query text, and helps improve the accuracy of semantic evaluation results. This, in turn, contributes to the accuracy of subsequent semantic error correction based on the semantic evaluation results. Furthermore, by performing semantic parsing on the query text, at least one suspicious text segment with potential semantic errors is extracted first. This allows for the focus on detecting semantic errors in the at least one suspicious text segment during semantic evaluation, based on the semantic error correction rules corresponding to each of the at least one suspicious text segment. This helps to better understand each text segment in the query text, further improving the accuracy of the semantic evaluation results. Attached Figure Description
[0021] Figure 1 This is a schematic diagram of a computer system provided in one embodiment of this application;
[0022] Figure 2 This is a flowchart of an error detection method for database query text provided in one embodiment of this application;
[0023] Figure 3 This is a schematic diagram of a first configuration template provided in one embodiment of this application;
[0024] Figure 4 This is a schematic diagram of the text error detection interface of a data management program provided in one embodiment of this application;
[0025] Figure 5 This is a flowchart of a knowledge base update method provided in one embodiment of this application;
[0026] Figure 6 This is a schematic diagram of the error correction process for query text provided in one embodiment of this application;
[0027] Figure 7 This is a flowchart of a semantic error correction method for query text provided in one embodiment of this application;
[0028] Figure 8 This is a schematic diagram of a second configuration template provided in one embodiment of this application;
[0029] Figure 9 This is a schematic diagram of a semantic error correction process provided in one embodiment of this application;
[0030] Figure 10 This is a flowchart of a syntax correction method for query text provided in one embodiment of this application;
[0031] Figure 11 This is a schematic diagram of a syntax error correction process provided in one embodiment of this application;
[0032] Figure 12 This is a flowchart of an error detection method for database query text applied in the field of logistics and transportation, provided in one embodiment of this application;
[0033] Figure 13 This is a flowchart of an error detection method for database query text applied in the financial field, provided in one embodiment of this application;
[0034] Figure 14 This is a block diagram of an error detection device for database query text provided in one embodiment of this application;
[0035] Figure 15 This is a structural block diagram of a computer device provided in one embodiment of this application. Detailed Implementation
[0036] To make the objectives, technical solutions, and advantages of this application clearer, the embodiments of this application will be described in further detail below with reference to the accompanying drawings.
[0037] Please refer to Figure 1 This illustration shows a schematic diagram of a computer system provided in one embodiment of this application. The computer system may include: a terminal device 10 and a server 20.
[0038] There may be one or more terminal devices 10. Terminal devices 10 may be electronic devices such as mobile phones, tablets, laptops, desktop computers, game consoles, e-book readers, multimedia playback devices, wearable devices, smart voice interaction devices, smart home appliances, vehicle terminals, aircraft, etc.
[0039] The terminal device 10 can install a client application for a data management program. This program has a database-based query function, allowing users to input query text and retrieve the corresponding target data. Optionally, the data management program can be an application that requires downloading and installation, or it can be a ready-to-use application; this application does not impose any limitations on this.
[0040] Server 20 provides background services to clients of the data management program installed and running on terminal device 10. For example, server 20 can be a background server for the aforementioned data management program. Server 20 can be a standalone physical server, a server cluster or distributed system composed of multiple physical servers, or a cloud server providing basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communication, middleware services, domain name services, security services, CDN (Content Delivery Network), and big data and artificial intelligence platforms, but is not limited to these. Optionally, server 20 can simultaneously provide background services to data management programs on multiple terminal devices 10. Terminal devices 10 and server 20 can communicate with each other via a network.
[0041] In this embodiment, a user inputs query text into a data management program, and a computer device (terminal device 10 or server 20) obtains the query text. The query text includes at least one text segment and is used to query data stored in a database. Semantic parsing is performed on the query text to analyze text segments suspected of containing semantic errors, resulting in at least one suspicious text segment. Semantic correction rules corresponding to each of the at least one suspicious text segment are obtained from a knowledge base. These rules indicate the correction strategy for semantic errors in the suspicious text segments. Based on the query text, the at least one suspicious text segment, and the semantic correction rules corresponding to each suspicious text segment, a semantic evaluation is performed on the query text to obtain a semantic evaluation result. This result indicates whether semantic errors exist in the query text.
[0042] Please refer to Figure 2 This document illustrates a flowchart of a database query text error detection method according to an embodiment of this application. The execution entity for each step of this method can be a computer device. The method may include at least one of the following steps 210 to 240:
[0043] Step 210: Obtain the query text for the database. The query text includes at least one text fragment and is used to query data stored in the database.
[0044] Query text is text entered by a user in a data management program to query data stored in a database. Query text includes at least one text fragment, each indicating a portion of the query text's content. For example, if the query text is an SQL query statement, then including at least one text fragment means that the query text includes at least one SQL query clause. SQL query clauses include, but are not limited to, SELECT, FROM, WHERE, GROUP BY, HAVING, ORDER BY, etc., each indicating a portion of the query intent within the SQL query statement.
[0045] Optionally, if the data management program is a comprehensive one, then it supports data queries against multiple databases. Each database represents a specific vertical field, including but not limited to logistics and transportation, finance, e-commerce, healthcare, social media, gaming, education, business operations, and website management. When performing a data query, the user can select the desired database from among the multiple databases, and the database system will then retrieve the target data from the selected database.
[0046] Optionally, if the data management program is a targeted data management program, then this data management program supports data queries against a single database. Users can then directly query the target data in the database corresponding to the data management program. The data types stored in the database are related to the type of data management program. For example, if the data management program is for managing logistics and transportation data, then the database is a database storing logistics and transportation data, including cargo status, transportation routes, vehicle locations, delivery history, and other logistics and transportation data. For example, if the data management program is for managing financial data, then the database is a database storing financial data, including account balances, transaction records, risk assessments, customer credit scores, and other financial data. For example, if the data management program is for managing medical data, then the database is a database storing medical data, including patient information, medical records, drug prescriptions, examination results, and other medical data.
[0047] Because query text may contain semantic or syntactic errors, after the computer device receives the query text, it needs to be input into a text detection system. The text detection system checks for semantic or syntactic errors. If errors are found, the query text is input into a text correction system, which corrects them, resulting in a corrected query text. This corrected query text is then input into a database system, which uses it to search for the corresponding target data. Conversely, if the query text does not contain any syntactic or semantic errors, it can be directly input into the database system, which then searches for the corresponding target data.
[0048] In some embodiments, a compiler performs a syntax evaluation on the query text to obtain a syntax evaluation result, which indicates whether there are syntax errors in the query text. For example, the compiler can be a DBMS (Database Management System) compiler.
[0049] Syntax evaluation is used to assess whether there are syntax errors in the query text. Syntax errors refer to errors in the text structure of the query text. If syntax errors exist in the query text, the database system will be unable to find the target data based on the textual logic of the query text, causing the database system to malfunction.
[0050] Syntax evaluation consists of two phases: lexical analysis and syntax analysis. In the lexical analysis phase, after the query text is input into the compiler, the compiler scans the SQL query statement character by character, identifying lexical units (tokens) according to predefined lexical rules (such as regular expressions). Lexical units include, but are not limited to, keywords, identifiers, operators, and delimiters. The obtained lexical units are then passed to the syntax analysis phase. If unrecognized characters (such as Chinese symbols or special characters), or unclosed strings or comments are encountered, the compiler will immediately report an error, indicating a syntax error. In the syntax analysis phase, the compiler uses a parsing algorithm to convert the lexical units into an abstract syntax tree (AST). Then, the AST is used to check whether the structure of the SQL query statement conforms to predefined syntax rules (such as the clause order and bracket matching rules of SELECT statements). Specifically, if the compiler detects keyword errors (such as spelling mistakes or using reserved keywords as identifiers), clause order errors (such as a WHERE clause preceding a FROM clause), or mismatched parentheses (such as unclosed parentheses in nested queries or function calls), it will immediately report an error, indicating a syntax error at that point. Therefore, the syntax evaluation process described above will determine the location of syntax errors in the query text and the type of syntax error at that location.
[0051] Therefore, in some embodiments, when there are grammatical errors in the query text, the grammatical evaluation result is also used to indicate at least one grammatical error location in the query text and the grammatical error type corresponding to each of the at least one grammatical error locations.
[0052] The syntax error location in the query text indicates the syntax error segment within the query text where a syntax error occurs. The syntax error location includes the start and end positions of the characters where the syntax error occurs. The syntax error segment refers to the local text fragment between these two positions. Optionally, the local text fragment can be a text segment within the query text (such as an SQL query clause), a portion of a text fragment (such as a portion of a clause within an SQL query clause), or a portion of the query text (such as a clause comprising one SQL query clause and a portion of another SQL query clause).
[0053] The syntax error type corresponding to the syntax error location indicates the reason for the syntax error segment at that location. For example, the syntax error type can be a syntax error segment with unrecognized characters, an unclosed string, a spelling error, an incorrect order of text segments, or an incorrect nesting of parentheses.
[0054] Each syntax error location corresponds to a syntax error type. Different syntax error locations may correspond to the same or different syntax error types. That is, a syntax error type in the syntax evaluation result may correspond to one syntax error location or multiple syntax error locations.
[0055] In some embodiments, if the syntax evaluation result indicates a syntax error in the query text, semantic evaluation is not performed on the query text; instead, syntax correction is performed directly. If the syntax evaluation result indicates no syntax error in the query text, semantic evaluation is performed on the query text to obtain a semantic evaluation result. If the semantic evaluation result indicates a semantic error in the query text, semantic correction is performed on the query text. The specific processes of syntax correction and semantic correction can be found in the following embodiments and will not be described here.
[0056] Steps 220 to 240 below are used to perform semantic evaluation on the query text and detect whether there are semantic errors in the query text.
[0057] Semantic evaluation assesses whether semantic errors exist in the query text. A semantic error is when the meaning of the query text does not achieve the intended function, resulting in the inability to obtain the expected result. If semantic errors exist in the query text, the database system will search for target data based on the meaning of the query text, leading to the return of data that is not what the user expected.
[0058] Step 220: Perform semantic parsing on the query text to obtain at least one suspicious text fragment in the query text. The suspicious text fragment is a text fragment that is suspected of having semantic errors.
[0059] A semantic parsing algorithm is used to perform semantic parsing on the query text, analyzing the execution path to be implemented by the query text and capturing suspicious text fragments. Optionally, suspicious text fragments can be text fragments with algorithmic logic errors, such as text fragments where an incorrect factorial result is caused by an incorrect loop condition. Optionally, suspicious text fragments can also be text fragments with incorrect data types, such as text fragments with mismatched operand types, such as text fragments containing the addition of strings and numbers. Optionally, suspicious text fragments can also be text fragments with incorrect variable scope, such as text fragments accessing undefined or out-of-scope variables, such as text fragments accessing local variables inside a function from outside the function. Optionally, suspicious text fragments can also be text fragments with incorrect boundary conditions, such as text fragments that do not properly handle boundary cases of input, such as text fragments accessing arrays out of bounds or text fragments that do not handle negative number inputs.
[0060] Optionally, a suspicious text fragment may contain semantic errors or it may not. Further semantic evaluation is needed to determine whether a suspicious text fragment contains semantic errors.
[0061] Step 230: Obtain at least one semantic error correction rule corresponding to each suspicious text fragment from the knowledge base. The knowledge base includes at least one semantic error correction rule, which is used to indicate the correction strategy for semantic errors.
[0062] The knowledge base also includes tag information corresponding to at least one semantic error correction rule, with each rule corresponding to one tag. The semantic error correction strategy explains how semantic errors should be corrected, and the tag information corresponding to a semantic error correction rule is typically a keyword phrase or a regular expression. For example, a semantic error correction rule could be "Before sorting a particular field in ascending order, ensure that all values in that field are not NULL." and the tag information corresponding to that rule could be "SORT_IN_ASC_ORDER".
[0063] The semantic error correction rules corresponding to the suspicious text fragments are used to indicate the correction strategy for semantic errors in the suspicious text fragments.
[0064] In some embodiments, step 230 includes at least one of sub-steps 231 to 232.
[0065] Sub-step 231: For each suspicious text segment, based on the label information corresponding to the suspicious text segment and at least one semantic error correction rule, obtain the label information matching the suspicious text segment. The label information matching the suspicious text segment is the label information with the highest matching degree among the label information corresponding to at least one semantic error correction rule.
[0066] Optionally, regular expressions can be used to perform character matching on the suspicious text fragment and the tag information corresponding to at least one semantic error correction rule, respectively, to obtain the tag information corresponding to the semantic error correction rule that matches the suspicious text fragment, that is, to obtain the tag information that matches the suspicious text fragment.
[0067] Optionally, the similarity between the suspicious text fragment and the label information corresponding to at least one semantic error correction rule can be calculated to obtain at least one similarity. The label information of the semantic error correction rule corresponding to the maximum value of the at least one similarity can be determined as the label information matching the suspicious text fragment.
[0068] Sub-step 232: The semantic error correction rule corresponding to the tag information matched by the suspicious text fragment is determined as the semantic error correction rule corresponding to the suspicious text fragment.
[0069] Since there is a one-to-one correspondence between tag information and semantic error correction rules, the semantic error correction rules corresponding to the tag information matching the suspicious text fragments can be obtained from the knowledge base.
[0070] By storing the tag information corresponding to semantic error correction rules in the knowledge base, the corresponding semantic error correction rules can be matched from the knowledge base based on the tag information. Compared with matching directly based on semantic error correction rules, matching based on tag information saves the computing resources required for rule matching and improves the rule matching speed.
[0071] Step 240: Based on the semantic error correction rules corresponding to the query text, at least one suspicious text fragment, and at least one suspicious text fragment respectively, obtain the semantic evaluation result of the query text. The semantic evaluation result is used to indicate whether there are semantic errors in the query text.
[0072] Based on the query text, at least one suspicious text fragment, and the semantic correction rules corresponding to each of the at least one suspicious text fragment, a semantic evaluation is performed again to determine whether semantic errors exist in the at least one suspicious text fragment. This yields the semantic evaluation results for each of the at least one suspicious text fragment, which indicate whether semantic errors exist within the suspicious text fragment. Simultaneously, based on the query text, a comprehensive semantic evaluation is performed on the query text to determine whether there are other text fragments with semantic errors besides the at least one suspicious text fragment. This yields the semantic evaluation results for each of the at least one other text fragment in the query text, which indicate whether semantic errors exist within those other text fragments. Finally, based on the semantic evaluation results for both the at least one suspicious text fragment and the at least one other text fragment, a semantic evaluation result for the query text is obtained. This semantic evaluation result indicates whether semantic errors exist in the query text, or can be understood as whether semantically erroneous fragments exist within the query text.
[0073] In some embodiments, step 240 includes at least one of sub-steps 241 to 242.
[0074] Sub-step 241: Generate a first prompt message based on the semantic correction rules corresponding to the query text, at least one suspicious text fragment, and at least one suspicious text fragment, and the first configuration template; wherein, the first configuration template is used to indicate the arrangement rules of the semantic correction rules corresponding to the query text, at least one suspicious text fragment, and at least one suspicious text fragment.
[0075] The semantic correction rules corresponding to the query text, at least one suspicious text fragment, and at least one suspicious text fragment are respectively filled into the first configuration template to obtain the first prompt information. For example, the first prompt information is in text form.
[0076] The first configuration template can be used as a reference. Figure 3 As shown, the first configuration template includes template content 301, template content 302 and template content 303, wherein template content 301 is used to indicate the evaluation steps of semantic evaluation, template content 302 is used to indicate the task requirements of semantic evaluation, and template content 303 is used to indicate the arrangement rules of semantic error correction rules corresponding to the query text, at least one suspicious text fragment and at least one suspicious text fragment respectively.
[0077] Sub-step 242: Based on the first prompt information, the first artificial intelligence (AI) model obtains the semantic evaluation result of the query text.
[0078] The first AI (Artificial Intelligence) model here can be any publicly available large language model, such as a natural language model based on a transformer structure trained with a large amount of data, such as hundreds of millions of samples. This application does not limit this.
[0079] The first AI model performs a comprehensive semantic evaluation of the query text based on the first prompt information, resulting in a semantic evaluation result for the query text. For example, if semantic errors exist in the query text, the semantic evaluation result can be a semantic evaluation report in JSON format.
[0080] In some embodiments, when there are semantic errors in the query text, the semantic evaluation results are also used to indicate at least one semantically erroneous segment in the query text, the semantic error type corresponding to the at least one semantically erroneous segment, and a semantic correction suggestion for the query text.
[0081] A semantically erroneous fragment refers to a text fragment in the query text that contains semantic errors. Optionally, if at least one other text fragment does not contain semantic errors, and at least one suspicious text fragment contains semantic errors, then at least one semantically erroneous fragment includes at least one suspicious text fragment. Optionally, if at least one other text fragment does not contain semantic errors, and when at least one suspicious text fragment undergoes semantic evaluation again, some suspicious text fragments are evaluated as not containing semantic errors, then at least one semantically erroneous fragment includes a portion of the suspicious text fragments. Optionally, if at least one other text fragment contains semantic errors, and at least one suspicious text fragment does not contain semantic errors, then at least one semantically erroneous fragment includes at least one other text fragment. Optionally, if when at least one other text fragment undergoes semantic evaluation, some other text fragments are evaluated as containing semantic errors, and at least one suspicious text fragment does not contain semantic errors, then at least one semantically erroneous fragment includes a portion of the other text fragments. For example, if the query text includes text fragment 1, text fragment 2, and text fragment 3, and text fragment 1 and text fragment 2 are suspicious text fragments, then at least one semantically erroneous fragment may include text fragment 1 and text fragment 2, or may include text fragment 1, or may include text fragment 1, text fragment 2, and text fragment 3, or may include text fragment 3.
[0082] The semantic error type corresponding to a semantic error fragment indicates the cause of the error. For example, a semantic error type can be an algorithmic logic error, a data type error, a variable scope error, or a boundary condition error within the semantic error fragment. Each semantic error fragment corresponds to one semantic error type. Different semantic error fragments can correspond to the same or different semantic error types; that is, one semantic error type in the semantic evaluation result can correspond to one semantic error fragment or multiple semantic error fragments.
[0083] The semantic correction suggestions for the query text are correction suggestions for semantic errors in at least one semantically erroneous segment, indicating how semantic errors in the query text should be corrected.
[0084] By using the first configuration template to generate the first prompt information, the computer device can easily identify the various data in the first prompt information to generate the semantic evaluation result of the query text, which improves the standardization and convenience of error detection. Furthermore, the generated semantic evaluation result conforms to the text format required by the first configuration template, which facilitates the subsequent computer device to identify the information contained in the semantic evaluation result, realize the semantic error correction of the query text, and improve the standardization and convenience of error correction.
[0085] The technical solution provided in this application decomposes the query text into at least one text segment, enabling localized semantic evaluation of each text segment. Compared to related technologies that directly perform semantic evaluation on the query text, this solution reduces the context load during query text analysis, enhances the understanding and analysis capabilities of the query text, and helps improve the accuracy of semantic evaluation results. This, in turn, contributes to the accuracy of subsequent semantic error correction based on the semantic evaluation results. Furthermore, by performing semantic parsing on the query text, at least one suspicious text segment with potential semantic errors is extracted first. This allows for the focus on detecting semantic errors in the at least one suspicious text segment during semantic evaluation, based on the semantic error correction rules corresponding to each of the at least one suspicious text segment. This helps to better understand each text segment in the query text, further improving the accuracy of the semantic evaluation results.
[0086] Figure 4 A schematic diagram of the text error checking interface of the data management program is shown. Figure 4 The data management program is a comprehensive one. The text error detection interface 400 displays a database selection box 401, allowing users to select the database they wish to query. The text error detection interface 400 also displays a text input box and a data management control 403. Users can enter query text 402 in the text input box and click the error correction control in the data management control 403 to complete error detection and correction with a single click, obtaining the corrected query text. Clicking the query control in the data management control 403 again allows users to query the target data in the selected database.
[0087] In some embodiments, the knowledge base includes a grammar rule base and a semantic rule base.
[0088] The semantic rule base includes at least one semantic error correction rule and at least one corresponding tag information for each semantic error correction rule. For details, please refer to the above embodiment; further elaboration is not provided here.
[0089] The syntax rule base includes at least one syntax correction rule and corresponding tag information for each rule. The syntax correction rule indicates the strategy for correcting syntax errors. It includes: database indication information, local text fragment indication information, and the correction strategy of the syntax correction rule. The database indication information indicates whether to use database table metadata for syntax correction, and the local text fragment indication information indicates whether to extract grammatically incorrect fragments from the query text for syntax correction.
[0090] Each syntax correction rule corresponds to a tag, which is typically a keyword phrase or a regular expression. A syntax correction rule is a three-element set of information, including database indications, local text fragment indications, and the rule's correction strategy. Database indications specify whether the syntax error corresponding to the rule requires syntax correction using database table metadata. Database table metadata indicates the database's structure, specifically the structure and attributes of tables, but only provides information about the tables themselves, not the actual data. This metadata includes, but is not limited to, basic table information (e.g., table name, creation time), column information (e.g., column names), index information (e.g., index names), constraint information (e.g., relationships between tables), trigger information (execution process when a trigger is activated), storage information (e.g., tablespace), and other metadata (e.g., descriptive information about tables or columns). Local text fragment indications specify whether syntax error corresponding to the rule requires extracting the relevant text fragment for syntax correction. The correction strategy of syntax error correction rules is used to explain how syntax errors should be corrected.
[0091] Please refer to Figure 5 This document illustrates a flowchart of a knowledge base update method according to an embodiment of this application. The execution entity for each step of this method can be a computer device. The method may include at least one of the following steps A1 to A5.
[0092] Step A1: Obtain the log data of query failures. The log data of query failures includes the query failure text and the process information of the query failure text. The query failure text is the query text that failed to retrieve data from the database. The process information is used to indicate the query steps of the query failure text.
[0093] Users use query text to query data in the database. If the target data is found in the database, the query text is considered successful and a query success log is generated. If the target data is not found in the database, the query text is considered unsuccessful and a query failure log is generated. In this case, the query text can be called a query failure text.
[0094] The process information for querying failed texts includes the expected query steps and the actual query steps, thus allowing the reason for the failure to query the failed texts to be determined based on the process information.
[0095] Step A2: The fourth AI model generates error correction rules corresponding to the failed query text based on the failed query text and the process information of the failed query text.
[0096] The fourth AI model here can be any publicly available large language model, such as a natural language model based on a transformer structure trained with a large amount of data, where the large amount of data can reach hundreds of millions of samples. This application does not limit this. Optionally, the fourth AI model and the first AI model can be the same AI model or different AI models.
[0097] The fourth AI model summarizes and analyzes the process information of the failed query text, generates error correction rules corresponding to the failed query text, and converts these error correction rules into JSON structured data. These error correction rules are used to indicate the correction strategies for textual errors in the failed query text.
[0098] The error correction rules corresponding to the generated query failure texts are temporarily stored in the external buffer of the knowledge base for verification. To ensure the compliance of the error correction rules, a threshold trigger mechanism is used to initiate the manual expert review process. When the number of new rules in the buffer exceeds the preset threshold t1 or the time since the last rule update exceeds the threshold t2, experts perform compliance verification on the error correction rules in the buffer according to predefined conditions, and allow the error correction rules that pass the compliance verification to enter the knowledge base.
[0099] By automatically capturing text cases of failed queries through log analysis, the fourth AI model is driven to generate new error correction rules. After expert review, the knowledge base is updated according to the error correction rules corresponding to the failed query texts, resulting in an updated knowledge base. This realizes a self-iterative update system for the knowledge base, ensuring the accuracy of each error correction rule in the knowledge base.
[0100] Step A3: If the error correction rule corresponding to the failed query text passes the compliance verification, calculate the similarity between the error correction rule corresponding to the failed query text and at least two error correction rules to obtain at least two similarity scores.
[0101] To avoid redundancy of similar rules, when adding error correction rules corresponding to failed query texts to the knowledge base, it is necessary to cluster the error correction rules corresponding to failed query texts and the existing error correction rules in the knowledge base, and perform semantic removal on the error correction rules in the knowledge base to ensure the uniqueness of each type of error correction rule in the knowledge base.
[0102] Calculate the similarity between the error correction rule corresponding to the failed query text and at least two error correction rules in the knowledge base to obtain at least two similarity scores.
[0103] Step A4: Perform semantic merging on the error correction rules corresponding to the maximum value of at least two similarities and the error correction rules corresponding to the failed query text to obtain the updated error correction rules.
[0104] A centroid synthesis deduplication mechanism is adopted to perform semantic merging on the error correction rules corresponding to the maximum value of at least two similarities and the error correction rules corresponding to the failed query text, so as to obtain the updated error correction rules.
[0105] Step A5: Replace the error correction rule corresponding to the maximum value in the knowledge base with the updated error correction rule to obtain the updated knowledge base.
[0106] In some embodiments, if the maximum value of at least two similarities is less than the similarity threshold, it is considered that the error correction rule corresponding to the failed query text does not belong to any of the existing error correction rules in the knowledge base. In this case, the error correction rule corresponding to the failed query text is determined as a new type of error correction rule, and can be directly added to the knowledge base to obtain the updated knowledge base.
[0107] In some embodiments, if the maximum value of at least two similarities is greater than or equal to the similarity threshold, the error correction rule corresponding to the failed query text is considered to belong to a certain type of error correction rule in the existing error correction rules in the knowledge base. In this case, the error correction rule corresponding to the failed query text and the error correction rule of that type need to be semantically merged to obtain the updated error correction rule, and then the updated knowledge base is obtained.
[0108] By using the above method to semantically remove error correction rules belonging to the same category in the knowledge base, redundancy of similar rules is avoided, and the uniqueness of error correction rules of each type in the knowledge base is guaranteed.
[0109] In some embodiments, query text with semantic errors will retrieve unexpected data in the database, but will not result in a complete data failure. However, query text with grammatical errors cannot retrieve data in the database. Therefore, the above knowledge base update method is for updating the grammar rule base within the knowledge base. The process involves acquiring query failure log data and generating grammar correction rules corresponding to the failed query text using a fourth AI model based on the failed query text and its process information. If the correction rules for the failed query text pass compliance verification, the similarity between the grammar correction rules for the failed query text and at least one grammar correction rule is calculated to obtain at least one similarity score. Semantic merging is performed on the grammar correction rule corresponding to the maximum similarity score and the grammar correction rule corresponding to the failed query text to obtain the updated grammar correction rule. The grammar correction rule corresponding to the maximum similarity score in the grammar rule base is replaced with the updated grammar correction rule to obtain the updated grammar rule base, thus obtaining the updated knowledge base. For updating the semantic rule base within the knowledge base, at least one semantic correction rule can be manually formulated and corrected by experts.
[0110] In some embodiments, step 240 is followed by step 250, which includes at least one of sub-steps 251 to 252.
[0111] Sub-step 251: Based on at least one of the semantic evaluation results and the syntactic evaluation results of the query text, obtain the error correction rules corresponding to the query text from the knowledge base.
[0112] Specifically, the grammatical evaluation result is used to indicate whether there are grammatical errors in the query text; when the grammatical evaluation result indicates that there are grammatical errors in the query text, the error correction rules corresponding to the query text include the grammatical error correction rules corresponding to the query text; when the semantic evaluation result indicates that there are semantic errors in the query text, the error correction rules corresponding to the query text include the semantic error correction rules corresponding to the query text.
[0113] Sub-step 252: Based on the error correction rules corresponding to the query text, correct the query text to obtain the corrected query text.
[0114] In some embodiments, a grammatical evaluation is performed on the query text to obtain a grammatical evaluation result. If the grammatical evaluation result indicates that there is a grammatical error in the query text, a grammatical correction rule corresponding to the query text is obtained from the knowledge base. Based on the grammatical correction rule corresponding to the query text, grammatical correction is performed on the query text to obtain a grammatically corrected query text.
[0115] In some embodiments, a semantic evaluation is performed on the query text to obtain a semantic evaluation result of the query text. If the semantic evaluation result indicates that there is a semantic error in the query text, a semantic error correction rule corresponding to the query text is obtained from the knowledge base. Based on the semantic error correction rule corresponding to the query text, semantic error correction is performed on the query text to obtain a semantically corrected query text.
[0116] In some embodiments, a syntactic evaluation is performed on the query text to obtain a syntactic evaluation result. If the syntactic evaluation result indicates that there is a syntactic error in the query text, a semantic evaluation is not performed on the query text; instead, syntactic correction is performed directly. Syntactic correction rules corresponding to the query text are retrieved from the knowledge base. Based on these rules, syntactic correction is performed on the query text to obtain the syntactically corrected query text. Alternatively, if the syntactic evaluation result indicates that there are no syntactic errors in the query text, a semantic evaluation is performed on the query text to obtain a semantic evaluation result. If the semantic evaluation result indicates that there are semantic errors in the query text, semantic correction is performed on the query text. Semantic correction rules corresponding to the query text are retrieved from the knowledge base. Based on these rules, semantic correction is performed on the query text to obtain the semantically corrected query text.
[0117] By combining semantic and syntactic evaluation results to correct query text, semantic and syntactic error correction for query text is achieved. This improves the comprehensiveness of text correction and the accuracy of the corrected query text. Therefore, querying the database based on the corrected query text can increase the probability of successful query and improve the accuracy of query results.
[0118] Figure 6 The diagram illustrates the error correction process for query text, which mainly comprises three modules: a text detection system, a text correction system, and a database system. After the user inputs query text, it is first fed into the correctness evaluator of the text detection system. The evaluator detects semantic or grammatical errors in the query text. If semantic or grammatical errors are found, the query text is fed into the error corrector of the text correction system. The error corrector corrects the semantic or grammatical errors, and the corrected query text is then resent to the correctness evaluator for a new round of correctness evaluation until no semantic or grammatical errors are detected, resulting in the corrected query text. During text detection and text correction, task-related error correction rules are extracted from the knowledge base for correctness evaluation and error correction. The corrected query text is then input into the database system, which searches for the corresponding target data based on the corrected query text. Furthermore, during the database system's search process, log data of failed queries is collected to extract new grammatical error correction rules and update the knowledge base.
[0119] The following section describes the process of semantic error correction for query text.
[0120] Please refer to Figure 7This document illustrates a flowchart of a semantic error correction method for query text provided in an embodiment of this application. The execution entity for each step of this method can be a computer device. The method may include at least one of the following steps 710-770:
[0121] Step 710: For each semantic error segment, according to the semantic error type corresponding to the semantic error segment and the label information corresponding to at least one semantic error correction rule, obtain the label information matching the semantic error segment. The label information matching the semantic error segment is the label information with the highest matching degree between the label information corresponding to at least one semantic error correction rule and the semantic error segment.
[0122] Optionally, regular expressions can be used to perform character matching on the semantic error type corresponding to the semantic error fragment and the tag information corresponding to at least one semantic error correction rule, respectively, to obtain the tag information corresponding to the semantic error correction rule that matches the semantic error type corresponding to the semantic error fragment, that is, to obtain the tag information matching the semantic error fragment.
[0123] Optionally, the similarity between the semantic error type corresponding to the semantic error segment and the label information corresponding to at least one semantic error correction rule can be calculated to obtain at least one similarity. The label information of the semantic error correction rule corresponding to the maximum value of the at least one similarity can be determined as the label information for matching the semantic error segment.
[0124] Step 720: Determine the semantic error correction rule corresponding to the tag information matched by the semantic error fragment as the semantic error correction rule corresponding to the semantic error fragment.
[0125] Since there is a one-to-one correspondence between label information and semantic error correction rules, the semantic error correction rules corresponding to the label information matching the semantic error fragment are obtained from the semantic rule base, thus obtaining the semantic error correction rules corresponding to the semantic error fragment.
[0126] Step 730: Obtain the semantic correction rules corresponding to the query text based on the semantic correction rules corresponding to at least one semantically erroneous segment.
[0127] The semantic correction rules corresponding to the query text include semantic correction rules corresponding to at least one semantically erroneous segment. Optionally, the semantic correction rules corresponding to the at least one semantically erroneous segment may contain duplicate semantic correction rules, or they may all be different semantic correction rules.
[0128] By extracting semantic error correction rules corresponding to semantic error fragments from the knowledge base, subsequent semantic correction of semantic error fragments in the query text can be carried out in a targeted manner based on the semantic error correction rules corresponding to the semantic error fragments, thereby improving the accuracy of semantic correction.
[0129] Step 740: Obtain partial table information of the database corresponding to the query text. The partial table information is used to indicate the structural information in the database that matches the query text.
[0130] Retrieve partial table metadata corresponding to the query text from the database's table metadata. This partial table metadata refers to the table metadata related to the query text, indicating the partial structural information in the database that matches the query text. For example, partial table metadata includes basic table information related to the query text (such as partial table names), column information related to the query text (such as partial column names), index information related to the query text (such as partial index names), constraint information related to the query text (such as partial relationships between tables), trigger information related to the query text (partial execution process when the trigger is activated), storage information related to the query text (such as partial tablespaces), and other metadata related to the query text (such as partial descriptive information about tables or columns).
[0131] Step 750: Based on partial table element information, semantic error correction rules corresponding to the query text, at least one semantic error fragment, and semantic correction suggestions, obtain the first preparation data corresponding to the query text. The first preparation data is the data used to perform semantic error correction on the query text.
[0132] The first set of preparation data corresponding to the query text includes some table metadata, semantic error correction rules corresponding to the query text, at least one semantic error fragment, and semantic correction suggestions for the query text.
[0133] Step 760: Generate a second prompt message based on the first prepared data and the second configuration template. The second configuration template is used to indicate the arrangement rules of the first prepared data.
[0134] The first prepared data is entered into the second configuration template to obtain the second prompt message. For example, the second prompt message is in text format.
[0135] The second configuration template can be referenced. Figure 8 As shown, the second configuration template includes template content 801, template content 802 and template content 803, wherein template content 801 is used to indicate the error correction steps of semantic error correction, template content 802 is used to indicate the task requirements of semantic error correction, and template content 803 is used to indicate the arrangement rules of the first preparation data.
[0136] Step 770: The second AI model generates the semantically corrected query text based on the second prompt information.
[0137] The second AI model here can be any publicly available large language model, such as a natural language model based on a transformer structure trained with a large amount of data, where the large amount of data can reach hundreds of millions of samples. This application does not limit this. Optionally, the second AI model can be the same as the first AI model or the fourth AI model mentioned above, or it can be an AI model that is different from both the first AI model and the fourth AI model mentioned above.
[0138] The second AI model performs semantic correction on at least one semantically erroneous segment in the query text based on the second prompt information, resulting in the semantically corrected query text.
[0139] By using a second configuration template to generate a second prompt message, computer devices can easily identify the various data in the second prompt message to generate semantically corrected query text, which improves the standardization and convenience of semantic correction, thereby increasing the speed of semantic correction.
[0140] Figure 9 The diagram illustrates the semantic error correction process, which includes a data preparation stage and a semantic error correction stage. In the data preparation stage, based on the semantic evaluation results of the query text, at least one semantically erroneous segment in the query text, the corresponding semantic error type for each segment, and semantic correction suggestions for the query text are obtained. Based on the semantic error type corresponding to each of the at least one semantically erroneous segment, semantic error correction rules corresponding to each segment are obtained. Partial table metadata corresponding to the query text is obtained. A second prompt message is constructed based on the at least one semantically erroneous segment, the corresponding semantic error correction rules, the partial table metadata, and the semantic correction suggestions. In the semantic error correction stage, a second AI model generates the semantically corrected query text based on the second prompt message.
[0141] The following section describes the process of performing syntax correction on the query text.
[0142] Please refer to Figure 10 This document illustrates a flowchart of a syntax correction method for query text provided in an embodiment of this application. The execution entity for each step of this method can be a computer device. The method may include at least one of the following steps 1010 to 1060:
[0143] Step 1010: For each syntax error location, obtain the tag information matching the syntax error location based on the syntax error type corresponding to the syntax error location and the tag information corresponding to at least one syntax correction rule. The tag information matching the syntax error location is the tag information with the highest matching degree between the tag information corresponding to at least one syntax correction rule and the syntax error type corresponding to the syntax error location.
[0144] The syntax error type corresponding to a syntax error location refers to the syntax error type of the syntax error segment corresponding to that location. Each syntax error location corresponds to one syntax error segment.
[0145] Optionally, regular expressions can be used to perform character matching on the syntax error type corresponding to the syntax error location and the tag information corresponding to at least one syntax correction rule, respectively, to obtain the tag information corresponding to the syntax correction rule that matches the syntax error type corresponding to the syntax error location, i.e., to obtain the tag information matching the syntax error location.
[0146] Alternatively, the similarity between the syntax error type corresponding to the syntax error location and the label information corresponding to at least one syntax correction rule can be calculated to obtain at least one similarity. The label information of the syntax correction rule corresponding to the maximum value of the at least one similarity can be determined as the label information matching the syntax error location.
[0147] Step 1020: Determine the syntax correction rule corresponding to the tag information matching the syntax error location as the syntax correction rule corresponding to the syntax error location.
[0148] Since there is a one-to-one correspondence between tag information and syntax correction rules, the syntax correction rules corresponding to the tag information matching the syntax error position are obtained from the syntax rule base, thus obtaining the syntax correction rules corresponding to the syntax error position.
[0149] Step 1030: Obtain the syntax correction rules corresponding to the query text based on the syntax correction rules corresponding to at least one syntax error location.
[0150] The syntax correction rules corresponding to the query text include syntax correction rules corresponding to at least one syntax error location. Optionally, the syntax correction rules corresponding to at least one syntax error location may contain duplicate syntax correction rules, or they may all be different syntax correction rules.
[0151] By extracting semantic error correction rules corresponding to the locations of grammatical errors from the knowledge base, subsequent grammatical corrections can be performed on the grammatically incorrect segments in the query text based on these rules, thereby improving the accuracy of grammatical correction.
[0152] Step 1040: Based on the query text and the corresponding syntax correction rules, obtain the second preparation data corresponding to the query text. The second preparation data is the data used to perform syntax correction on the query text.
[0153] In some embodiments, step 1040 includes at least one of sub-steps 1041 to 1043.
[0154] Sub-step 1041: If the database instruction information is used to indicate that syntax correction is performed using the database table metadata, obtain partial table metadata of the database corresponding to the query text.
[0155] The interpretation of some table element information can be found in the above-described semantic error correction process implementation examples, and will not be repeated here.
[0156] When the database's instruction information is used to indicate that syntax correction should not be performed using the database's table metadata, it is not necessary to obtain the partial table metadata corresponding to the query text.
[0157] Sub-step 1042: When the indication information of the local text fragment is used to indicate the extraction of local text fragments in the query text for grammatical correction, at least one local text fragment at the location of a grammatical error is extracted from the query text to obtain at least one grammatically incorrect fragment in the query text.
[0158] A syntax error location includes the starting and ending positions of the characters where the syntax error occurs. Therefore, a syntax error location refers to the local text segment between the starting and ending positions of the characters where the syntax error occurs. Based on at least one syntax error location, at least one syntax error segment in the query text is obtained.
[0159] In cases where the indication information for a local text fragment is used to indicate that no grammatically incorrect fragment needs to be extracted if no local text fragment is extracted from the query text for grammatical correction, at least one grammatically incorrect fragment needs to be extracted.
[0160] Sub-step 1043: Based on the partial table information, the correction strategy of the syntax error correction rule corresponding to at least one syntax error segment and at least one syntax error position, the second preparation data is obtained.
[0161] Optionally, when the database instruction information is used to instruct the use of the database table meta information to perform syntax correction, and the local text fragment instruction information is used to instruct the extraction of local text fragments from the query text to perform syntax correction, the second preparation data corresponding to the query text includes partial table meta information, at least one syntax error fragment, and syntax correction rules corresponding to at least one syntax error location.
[0162] Optionally, when the database indication information is used to indicate that syntax correction is not performed using the database table meta information, and the local text fragment indication information is used to indicate that syntax correction is performed by extracting local text fragments from the query text, the second preparation data corresponding to the query text includes at least one syntax error fragment and at least one syntax error location corresponding to a syntax correction rule.
[0163] Optionally, when the database instruction information is used to instruct the use of the database table meta information to perform syntax correction, and the local text fragment instruction information is used to instruct the non-extraction of local text fragments from the query text to perform syntax correction, the second preparation data corresponding to the query text includes partial table meta information and syntax correction rules corresponding to at least one syntax error location.
[0164] Optionally, when the database indication information is used to indicate that syntax correction is not performed using the database table meta information, and the local text fragment indication information is used to indicate that syntax correction is not performed by extracting local text fragments from the query text, the second preparation data corresponding to the query text includes at least one syntax correction rule corresponding to each syntax error location.
[0165] By determining whether to use the database table metadata and grammatically incorrect fragments in the query text for syntax correction based on the triple information in the syntax correction rules, the second preparation data is the data used to perform syntax correction on the query text, avoiding redundancy in the second preparation data and affecting the efficiency of syntax correction.
[0166] Step 1050: Generate a third prompt message based on the second prepared data and the third configuration template. The third configuration template is used to indicate the arrangement rules of the second prepared data.
[0167] The second prepared data is entered into the third configuration template to obtain the third prompt message. For example, the third prompt message is in text format.
[0168] Step 1060: The third AI model obtains the grammatically corrected query text based on the third prompt information.
[0169] The third AI model here can be any publicly available large language model, such as a natural language model based on a transformer structure trained with a large amount of data, where the large amount of data can reach hundreds of millions of samples. This application does not limit this. Optionally, the third AI model can be the same as the first, fourth, or second AI model mentioned above, or it can be an AI model that is different from all of the first, fourth, and second AI models mentioned above.
[0170] The third AI model corrects at least one grammatically incorrect segment in the query text based on the third prompt information, resulting in the grammatically corrected query text.
[0171] By using a third configuration template to generate third prompt information, computer devices can easily identify the various data in the third prompt information to generate query text after syntax correction, which improves the standardization and convenience of syntax correction, thereby increasing the speed of syntax correction.
[0172] In some embodiments, a third AI model generates at least one corrected syntax error fragment based on third prompt information; at least one syntax error fragment in the query text is replaced with at least one corrected syntax error fragment to obtain the syntax-corrected query text.
[0173] The third prompt information is input into the third AI model, which outputs at least one corrected syntax error segment corresponding to at least one syntax error segment. The at least one corrected syntax error segment is then replaced with at least one syntax error segment in the query text to obtain the syntax-corrected query text.
[0174] By performing syntax correction on at least one syntax error segment and generating at least one corrected syntax error segment, compared to directly generating syntax-corrected query text, syntax errors in the query text can be avoided, further improving the accuracy of syntax correction.
[0175] Figure 11 The diagram illustrates the syntax correction process, which includes a rule retrieval stage, a data preparation stage, and a semantic correction stage. In the rule retrieval stage, based on the syntax evaluation results of the query text, at least one syntax error location and its corresponding syntax error type are obtained. Based on the syntax error types corresponding to each of the at least one syntax error location, syntax correction rules are derived. In the data preparation stage, based on the database indication information in the syntax correction rules, it is determined whether to use database table metadata for syntax correction, and based on the local text fragment indication information in the syntax correction rules, it is determined whether to extract syntax error fragments from the query text for syntax correction. Then, based on the correction strategy in the syntax correction rules and the information recalled in the data preparation stage, a third prompt is constructed. In the syntax correction stage, a second AI model generates at least one corrected syntax error fragment based on the third prompt, and then this corrected syntax error fragment is added to the query text to obtain the syntax-corrected query text.
[0176] This application tested error detection and error correction capabilities on the BIRD (Big Impulse Response Dataset) public dataset. For error detection, we used the result set of the CodeS-7B model on the BIRD dataset as the detection object to determine whether a SQL query statement contains errors at the syntactic and semantic levels. Since this is a binary classification problem, we used accuracy and F1 score as evaluation metrics, and the results are shown in Table 1 below.
[0177] Table 1
[0178] Data difficulty categories all Simple medium challenge quantity 1534 925 464 145 Accuracy (%) of the method in this application 75.8 77.6 73.5 71.7 F1 score (%) of this application method 79.8 83.7 72.1 67.2 Accuracy rate (%) of SQLFixAgent 70.1 71.9 67.9 65.5 SQLFixAgent's F1 score (%) 73.7 78.8 69.3 55.1
[0179] Regarding error correction capabilities, we targeted the erroneous portions of the result sets of the CodeS-7B and CodeS-15B models on the BIRD dataset as the correction targets, attempting to correct SQL queries containing syntax or semantic errors. We used correction accuracy as the evaluation metric, and the results are shown in Table 2 below.
[0180] Table 2
[0181] Error data statistics all Simple medium challenge Error data volume in CodeS-7B 691 333 267 91 Accuracy (%) of the method in this application 25.8 26.4 26.2 22.0 Accuracy rate (%) of SQLFixAgent 15.6 17.0 15.6 10.4 Error data volume in CodeS-15B 667 324 255 88 Accuracy (%) of the method in this application 25.2 26.9 23.1 25.0 Accuracy rate (%) of SQLFixAgent 14.7 15.2 15.4 10.9
[0182] Based on the experimental results above, we can conclude that the method described in this application significantly outperforms the most advanced SQL error correction tool, SQLFixAgent, in both error detection and correction. The advantage is particularly pronounced on the challenging dataset, demonstrating that the method's ability to handle long and complex SQL queries is indeed a significant improvement over existing technologies.
[0183] Application scenario examples:
[0184] The error detection method for database query text provided in this application embodiment can be applied to fields such as logistics and transportation, finance, e-commerce, medical care, social networking, gaming, education, enterprise operation, and website management. Below, the error detection methods for database query text applied to the e-commerce and finance fields will be introduced.
[0185] Applications in the logistics and transportation sector:
[0186] In one application scenario, error detection methods for database query text can be applied to the logistics and transportation field. Figure 12 A flowchart illustrating an embodiment of this application provides a method for error detection of database query text applied in the field of logistics and transportation. The execution entity for each step of this method can be a computer device. The method may include at least one of the following steps 1210 to 1240.
[0187] Step 1210: Obtain the query text for the logistics database. The query text includes at least one text fragment and is used to query the logistics data stored in the logistics database.
[0188] Step 1220: Perform semantic parsing on the query text to obtain at least one suspicious text fragment in the query text. The suspicious text fragment is a text fragment that is suspected of having semantic errors.
[0189] Step 1230: Obtain at least one semantic error correction rule corresponding to each suspicious text fragment from the knowledge base. The knowledge base includes at least one semantic error correction rule, which is used to indicate the correction strategy for semantic errors.
[0190] Step 1240: Based on the semantic error correction rules corresponding to the query text, at least one suspicious text fragment, and at least one suspicious text fragment respectively, obtain the semantic evaluation result of the query text. The semantic evaluation result is used to indicate whether there are semantic errors in the query text.
[0191] In some embodiments, the knowledge base also includes tag information corresponding to at least one semantic correction rule. For each suspicious text segment, based on the suspicious text segment and the tag information corresponding to at least one semantic correction rule, tag information matching the suspicious text segment is obtained. The tag information matching the suspicious text segment is the tag information with the highest matching degree among the tag information corresponding to at least one semantic correction rule. The semantic correction rule corresponding to the tag information matching the suspicious text segment is determined as the semantic correction rule corresponding to the suspicious text segment.
[0192] In some embodiments, a first prompt message is generated based on the query text, at least one suspicious text fragment, semantic correction rules corresponding to at least one suspicious text fragment, and a first configuration template; wherein, the first configuration template is used to indicate the arrangement rules of the semantic correction rules corresponding to the query text, at least one suspicious text fragment, and at least one suspicious text fragment. The semantic evaluation result of the query text is obtained by a first artificial intelligence (AI) model based on the first prompt message.
[0193] In some embodiments, the knowledge base further includes at least one syntax correction rule, which indicates a strategy for correcting syntax errors. Based on at least one of the semantic evaluation result and the syntax evaluation result of the query text, a correction rule corresponding to the query text is obtained from the knowledge base; wherein, the syntax evaluation result indicates whether there is a syntax error in the query text; if the syntax evaluation result indicates that there is a syntax error in the query text, the correction rule corresponding to the query text includes the syntax correction rule corresponding to the query text; if the semantic evaluation result indicates that there is a semantic error in the query text, the correction rule corresponding to the query text includes the semantic correction rule corresponding to the query text. Based on the correction rule corresponding to the query text, the query text is corrected to obtain the corrected query text.
[0194] In some embodiments, when semantic errors exist in the query text, the semantic evaluation result is further used to indicate at least one semantically erroneous segment in the query text and the semantic error type corresponding to each semantically erroneous segment. For each semantically erroneous segment, based on the semantic error type corresponding to the semantically erroneous segment and the label information corresponding to at least one semantic correction rule, the label information matching the semantically erroneous segment is obtained. The label information matching the semantically erroneous segment is the label information with the highest matching degree among the label information corresponding to at least one semantic correction rule. The semantic correction rule corresponding to the label information matching the semantically erroneous segment is determined as the semantic correction rule corresponding to the semantically erroneous segment. Based on the semantic correction rules corresponding to at least one semantically erroneous segment, the semantic correction rule corresponding to the query text is obtained.
[0195] In some embodiments, when semantic errors exist in the query text, the semantic evaluation result is also used to indicate semantic correction suggestions for the query text. Partial table metadata of the logistics database corresponding to the query text is obtained; this partial table metadata indicates the structural information in the logistics database that matches the query text. Based on the partial table metadata, the semantic correction rules corresponding to the query text, at least one semantically erroneous segment, and the semantic correction suggestions, first preparation data corresponding to the query text is obtained. This first preparation data is the data used to perform semantic correction on the query text. Based on the first preparation data and a second configuration template, a second prompt message is generated; the second configuration template indicates the arrangement rules of the first preparation data. A second AI model generates the semantically corrected query text based on the second prompt message.
[0196] In some embodiments, when grammatical errors exist in the query text, the grammatical evaluation result is further used to indicate at least one grammatical error location in the query text and the grammatical error type corresponding to each grammatical error location; the knowledge base also includes tag information corresponding to at least one grammatical correction rule. For each grammatical error location, based on the grammatical error type corresponding to the grammatical error location and the tag information corresponding to at least one grammatical correction rule, tag information matching the grammatical error location is obtained. The tag information matching the grammatical error location is the tag information with the highest matching degree between the tag information corresponding to at least one grammatical correction rule and the grammatical error type corresponding to the grammatical error location. The grammatical correction rule corresponding to the tag information matching the grammatical error location is determined as the grammatical correction rule corresponding to the grammatical error location. Based on the grammatical correction rules corresponding to at least one grammatical error location, the grammatical correction rule corresponding to the query text is obtained.
[0197] In some embodiments, second preparation data corresponding to the query text is obtained based on the query text and the corresponding syntax correction rules. This second preparation data is the data used to perform syntax correction on the query text. A third prompt message is generated based on the second preparation data and a third configuration template, whereby the third configuration template indicates the arrangement rules of the second preparation data. The syntax-corrected query text is then obtained through a third AI model based on the third prompt message.
[0198] In some embodiments, the syntax correction rules corresponding to the syntax error locations include: database indication information, local text fragment indication information, and correction strategies for the syntax correction rules corresponding to the syntax error locations. The database indication information indicates whether to use the database's table metadata for syntax correction, and the local text fragment indication information indicates whether to extract syntax error fragments from the query text for syntax correction. When the logistics database indication information indicates that the logistics database's table metadata is used for syntax correction, partial table metadata of the logistics database corresponding to the query text is obtained. When the local text fragment indication information indicates that local text fragments at at least one syntax error location are extracted from the query text for syntax correction, at least one syntax error fragment in the query text is obtained. Second preparation data is obtained based on the correction strategies for the syntax correction rules corresponding to the partial table metadata, at least one syntax error fragment, and at least one syntax error location, respectively.
[0199] In some embodiments, a third AI model generates at least one corrected syntax error fragment based on third prompt information. The at least one syntax error fragment in the query text is then replaced with at least one corrected syntax error fragment to obtain the syntax-corrected query text.
[0200] In some embodiments, the knowledge base includes a grammar rule base and a semantic rule base. The grammar rule base includes at least one grammar correction rule, which is used to indicate a strategy for correcting grammatical errors. The semantic rule base includes at least one semantic correction rule.
[0201] In some embodiments, log data of failed queries is obtained. This log data includes the query failure text and process information related to the failed query text. The query failure text indicates that data was not successfully retrieved from the logistics database, and the process information indicates the query steps involved. A fourth AI model generates correction rules corresponding to the failed query text based on the text and its process information. If the correction rules for the failed query text pass compliance verification, the knowledge base is updated according to these rules to obtain the updated knowledge base.
[0202] In some embodiments, the similarity between the error correction rule corresponding to the failed query text and at least two other error correction rules is calculated to obtain at least two similarity scores. Semantic merging is then performed on the error correction rule corresponding to the maximum similarity score among the at least two similarity scores and the error correction rule corresponding to the failed query text to obtain an updated error correction rule. The error correction rule corresponding to the maximum similarity score in the knowledge base is then replaced with the updated error correction rule to obtain an updated knowledge base.
[0203] By decomposing the query text into at least one text segment, localized semantic evaluation of each segment is possible. This reduces the contextual load during query text analysis, enhances the understanding and analysis capabilities of the query text, and helps improve the accuracy of semantic evaluation and semantic correction. Furthermore, by combining semantic and syntactic evaluation results to correct the query text, both semantic and syntactic errors are achieved, improving the comprehensiveness of text correction and the accuracy of the corrected query text. Consequently, querying the logistics database based on the corrected query text increases the probability of successful queries and improves the accuracy of query results.
[0204] Applications in the financial sector:
[0205] In one application scenario, error detection methods for database query text can be applied to the financial field. Figure 13 A flowchart illustrating an embodiment of this application provides a method for error detection of database query text applied in the financial field. The execution entity for each step of this method can be a computer device. The method may include at least one of the following steps 1310 to 1340.
[0206] Step 1310: Obtain the query text for the financial database. The query text includes at least one text fragment and is used to query the financial data stored in the financial database.
[0207] Step 1320: Perform semantic parsing on the query text to obtain at least one suspicious text fragment in the query text. The suspicious text fragment is a text fragment that is suspected of having semantic errors.
[0208] Step 1330: Obtain at least one semantic error correction rule corresponding to each suspicious text fragment from the knowledge base. The knowledge base includes at least one semantic error correction rule, which is used to indicate the correction strategy for semantic errors.
[0209] Step 1340: Based on the semantic error correction rules corresponding to the query text, at least one suspicious text fragment, and at least one suspicious text fragment respectively, obtain the semantic evaluation result of the query text. The semantic evaluation result is used to indicate whether there are semantic errors in the query text.
[0210] In some embodiments, the knowledge base also includes tag information corresponding to at least one semantic correction rule. For each suspicious text segment, based on the suspicious text segment and the tag information corresponding to at least one semantic correction rule, tag information matching the suspicious text segment is obtained. The tag information matching the suspicious text segment is the tag information with the highest matching degree among the tag information corresponding to at least one semantic correction rule. The semantic correction rule corresponding to the tag information matching the suspicious text segment is determined as the semantic correction rule corresponding to the suspicious text segment.
[0211] In some embodiments, a first prompt message is generated based on the query text, at least one suspicious text fragment, semantic correction rules corresponding to at least one suspicious text fragment, and a first configuration template; wherein, the first configuration template is used to indicate the arrangement rules of the semantic correction rules corresponding to the query text, at least one suspicious text fragment, and at least one suspicious text fragment. The semantic evaluation result of the query text is obtained by a first artificial intelligence (AI) model based on the first prompt message.
[0212] In some embodiments, the knowledge base further includes at least one syntax correction rule, which indicates a strategy for correcting syntax errors. Based on at least one of the semantic evaluation result and the syntax evaluation result of the query text, a correction rule corresponding to the query text is obtained from the knowledge base; wherein, the syntax evaluation result indicates whether there is a syntax error in the query text; if the syntax evaluation result indicates that there is a syntax error in the query text, the correction rule corresponding to the query text includes the syntax correction rule corresponding to the query text; if the semantic evaluation result indicates that there is a semantic error in the query text, the correction rule corresponding to the query text includes the semantic correction rule corresponding to the query text. Based on the correction rule corresponding to the query text, the query text is corrected to obtain the corrected query text.
[0213] In some embodiments, when semantic errors exist in the query text, the semantic evaluation result is further used to indicate at least one semantically erroneous segment in the query text and the semantic error type corresponding to each semantically erroneous segment. For each semantically erroneous segment, based on the semantic error type corresponding to the semantically erroneous segment and the label information corresponding to at least one semantic correction rule, the label information matching the semantically erroneous segment is obtained. The label information matching the semantically erroneous segment is the label information with the highest matching degree among the label information corresponding to at least one semantic correction rule. The semantic correction rule corresponding to the label information matching the semantically erroneous segment is determined as the semantic correction rule corresponding to the semantically erroneous segment. Based on the semantic correction rules corresponding to at least one semantically erroneous segment, the semantic correction rule corresponding to the query text is obtained.
[0214] In some embodiments, when semantic errors exist in the query text, the semantic evaluation result is also used to indicate semantic correction suggestions for the query text. Partial table cell information of the financial database corresponding to the query text is obtained; this partial table cell information indicates the structural information in the financial database that matches the query text. Based on the partial table cell information, the semantic correction rules corresponding to the query text, at least one semantically erroneous segment, and the semantic correction suggestions, first preparation data corresponding to the query text is obtained. This first preparation data is the data used to perform semantic correction on the query text. Based on the first preparation data and a second configuration template, a second prompt message is generated; the second configuration template indicates the arrangement rules of the first preparation data. A second AI model generates the semantically corrected query text based on the second prompt message.
[0215] In some embodiments, when grammatical errors exist in the query text, the grammatical evaluation result is further used to indicate at least one grammatical error location in the query text and the grammatical error type corresponding to each grammatical error location; the knowledge base also includes tag information corresponding to at least one grammatical correction rule. For each grammatical error location, based on the grammatical error type corresponding to the grammatical error location and the tag information corresponding to at least one grammatical correction rule, tag information matching the grammatical error location is obtained. The tag information matching the grammatical error location is the tag information with the highest matching degree between the tag information corresponding to at least one grammatical correction rule and the grammatical error type corresponding to the grammatical error location. The grammatical correction rule corresponding to the tag information matching the grammatical error location is determined as the grammatical correction rule corresponding to the grammatical error location. Based on the grammatical correction rules corresponding to at least one grammatical error location, the grammatical correction rule corresponding to the query text is obtained.
[0216] In some embodiments, second preparation data corresponding to the query text is obtained based on the query text and the corresponding syntax correction rules. This second preparation data is the data used to perform syntax correction on the query text. A third prompt message is generated based on the second preparation data and a third configuration template, whereby the third configuration template indicates the arrangement rules of the second preparation data. The syntax-corrected query text is then obtained through a third AI model based on the third prompt message.
[0217] In some embodiments, the syntax correction rules corresponding to the syntax error locations include: database indication information, local text fragment indication information, and correction strategies for the syntax correction rules corresponding to the syntax error locations. The database indication information indicates whether to use the database's table metadata for syntax correction, and the local text fragment indication information indicates whether to extract syntax error fragments from the query text for syntax correction. When the financial database indication information indicates that the financial database's table metadata is used for syntax correction, partial table metadata of the financial database corresponding to the query text is obtained. When the local text fragment indication information indicates that local text fragments at at least one syntax error location are extracted from the query text for syntax correction, at least one syntax error fragment in the query text is obtained. Second preparation data is obtained based on the correction strategies for the syntax correction rules corresponding to the partial table metadata, at least one syntax error fragment, and at least one syntax error location, respectively.
[0218] In some embodiments, a third AI model generates at least one corrected syntax error fragment based on third prompt information. The at least one syntax error fragment in the query text is then replaced with at least one corrected syntax error fragment to obtain the syntax-corrected query text.
[0219] In some embodiments, the knowledge base includes a grammar rule base and a semantic rule base. The grammar rule base includes at least one grammar correction rule, which is used to indicate a strategy for correcting grammatical errors. The semantic rule base includes at least one semantic correction rule.
[0220] In some embodiments, log data of failed queries is obtained. This log data includes the query failure text and process information related to the failed query text. The query failure text indicates a query that failed to retrieve data from the financial database, and the process information indicates the query steps involved. A fourth AI model generates correction rules corresponding to the failed query text based on the text and its process information. If the correction rules for the failed query text pass compliance verification, the knowledge base is updated according to these rules to obtain the updated knowledge base.
[0221] In some embodiments, the similarity between the error correction rule corresponding to the failed query text and at least two other error correction rules is calculated to obtain at least two similarity scores. Semantic merging is then performed on the error correction rule corresponding to the maximum similarity score among the at least two similarity scores and the error correction rule corresponding to the failed query text to obtain an updated error correction rule. The error correction rule corresponding to the maximum similarity score in the knowledge base is then replaced with the updated error correction rule to obtain an updated knowledge base.
[0222] By decomposing the query text into at least one text segment, localized semantic evaluation of each segment is possible. This reduces the contextual load during query text analysis, enhances the understanding and analysis capabilities of the query text, and helps improve the accuracy of semantic evaluation and error correction. Furthermore, by combining semantic and syntactic evaluation results to correct the query text, both semantic and syntactic errors are achieved, improving the comprehensiveness of text correction and the accuracy of the corrected query text. Consequently, querying financial databases based on the corrected query text increases the probability of successful queries and improves the accuracy of query results.
[0223] The following are embodiments of the apparatus described in this application, which can be used to execute the embodiments of the method described in this application. For details not disclosed in the apparatus embodiments of this application, please refer to the embodiments of the method described in this application.
[0224] Please refer to Figure 14 This diagram illustrates a block diagram of an error detection apparatus for database query text according to an embodiment of this application. The apparatus has the function of implementing the aforementioned error detection method for database query text. This function can be implemented in hardware or by hardware executing corresponding software. The apparatus can be the computer device described above, or it can be installed within a computer device. Figure 14 As shown, the device 1400 may include: a text acquisition module 1410, a semantic parsing module 1420, a rule extraction module 1430, and a semantic evaluation module 1440.
[0225] The text acquisition module 1410 is used to acquire query text for a database, the query text including at least one text fragment, the query text being used to query data stored in the database.
[0226] The semantic parsing module 1420 is used to perform semantic parsing on the query text to obtain at least one suspicious text fragment in the query text, wherein the suspicious text fragment is a text fragment that is suspected of having semantic errors.
[0227] The rule extraction module 1430 is used to obtain semantic error correction rules corresponding to the at least one suspicious text fragment from the knowledge base. The knowledge base includes at least one semantic error correction rule, which is used to indicate the correction strategy for semantic errors.
[0228] The semantic evaluation module 1440 is used to obtain the semantic evaluation result of the query text based on the semantic error correction rules corresponding to the query text, the at least one suspicious text fragment, and the at least one suspicious text fragment, respectively. The semantic evaluation result is used to indicate whether there is a semantic error in the query text.
[0229] In some embodiments, the knowledge base further includes tag information corresponding to each of the at least one semantic error correction rule; the rule extraction module 1430 is used for:
[0230] For each suspicious text segment, according to the tag information corresponding to the suspicious text segment and the at least one semantic error correction rule respectively, the tag information matching the suspicious text segment is obtained. The tag information matching the suspicious text segment is the tag information with the highest matching degree among the tag information corresponding to the at least one semantic error correction rule respectively.
[0231] The semantic error correction rule corresponding to the tag information matched by the suspicious text fragment is determined as the semantic error correction rule corresponding to the suspicious text fragment.
[0232] In some embodiments, the semantic evaluation module 1440 is configured to:
[0233] A first prompt message is generated based on the query text, the at least one suspicious text fragment, the semantic correction rules corresponding to the at least one suspicious text fragment, and the first configuration template; wherein, the first configuration template is used to indicate the arrangement rules of the semantic correction rules corresponding to the query text, the at least one suspicious text fragment, and the at least one suspicious text fragment.
[0234] The semantic evaluation result of the query text is obtained by the first artificial intelligence (AI) model based on the first prompt information.
[0235] In some embodiments, the knowledge base further includes at least one syntax correction rule, which is used to indicate a strategy for correcting syntax errors; the apparatus further includes a text correction module, which is used to:
[0236] Based on at least one of the semantic evaluation result and the grammatical evaluation result of the query text, the error correction rule corresponding to the query text is obtained from the knowledge base; wherein, the grammatical evaluation result is used to indicate whether there is a grammatical error in the query text; when the grammatical evaluation result indicates that there is a grammatical error in the query text, the error correction rule corresponding to the query text includes the grammatical error correction rule corresponding to the query text; when the semantic evaluation result indicates that there is a semantic error in the query text, the error correction rule corresponding to the query text includes the semantic error correction rule corresponding to the query text.
[0237] Based on the error correction rules corresponding to the query text, the query text is corrected to obtain the corrected query text.
[0238] In some embodiments, when semantic errors exist in the query text, the semantic evaluation result is further used to indicate at least one semantically erroneous segment in the query text and the semantic error type corresponding to the at least one semantically erroneous segment; the text correction module is used to:
[0239] For each semantic error segment, according to the semantic error type corresponding to the semantic error segment and the label information corresponding to the at least one semantic error correction rule, the label information matching the semantic error segment is obtained. The label information matching the semantic error segment is the label information with the highest matching degree among the label information corresponding to the at least one semantic error correction rule.
[0240] The semantic error correction rule corresponding to the tag information matched by the semantic error fragment is determined as the semantic error correction rule corresponding to the semantic error fragment;
[0241] Based on the semantic error correction rules corresponding to the at least one semantic error segment, the semantic error correction rules corresponding to the query text are obtained.
[0242] In some embodiments, if a semantic error exists in the query text, the semantic evaluation result is further used to indicate semantic correction suggestions for the query text; the text correction module is used to:
[0243] Obtain partial table element information of the database corresponding to the query text; the partial table element information is used to indicate the structural information in the database that matches the query text.
[0244] Based on the partial table metadata, the semantic error correction rules corresponding to the query text, the at least one semantic error fragment, and the semantic correction suggestion, the first preparation data corresponding to the query text is obtained. The first preparation data is the data used to perform semantic error correction on the query text.
[0245] Based on the first prepared data and the second configuration template, a second prompt message is generated, wherein the second configuration template is used to indicate the arrangement rules of the first prepared data.
[0246] The second AI model generates semantically corrected query text based on the second prompt information.
[0247] In some embodiments, when there are grammatical errors in the query text, the grammatical evaluation result is further used to indicate at least one grammatical error location in the query text and the grammatical error type corresponding to each of the at least one grammatical error locations; the knowledge base also includes tag information corresponding to at least one grammatical correction rule; the text correction module is used to:
[0248] For each of the syntax error locations, according to the syntax error type corresponding to the syntax error location and the tag information corresponding to the at least one syntax correction rule, the tag information matching the syntax error location is obtained. The tag information matching the syntax error location is the tag information with the highest matching degree between the at least one syntax correction rule and the syntax error type corresponding to the syntax error location.
[0249] The syntax correction rule corresponding to the tag information matched by the syntax error location is determined as the syntax correction rule corresponding to the syntax error location.
[0250] Based on the syntax correction rules corresponding to the at least one syntax error location, the syntax correction rules corresponding to the query text are obtained.
[0251] In some embodiments, the text correction module is used for:
[0252] Based on the query text and the corresponding syntax correction rules, the second preparation data corresponding to the query text is obtained. The second preparation data is the data used to perform syntax correction on the query text.
[0253] Based on the second prepared data and the third configuration template, a third prompt message is generated, wherein the third configuration template is used to indicate the arrangement rules of the second prepared data;
[0254] The third AI model obtains the grammatically corrected query text based on the third prompt information.
[0255] In some embodiments, the syntax correction rules corresponding to the syntax error locations include: indication information from the database, indication information from local text fragments, and a correction strategy for the syntax correction rules corresponding to the syntax error locations. The indication information from the database is used to indicate whether to use the table metadata of the database to perform syntax correction, and the indication information from the local text fragments is used to indicate whether to extract syntax error fragments from the query text to perform syntax correction. The text correction module is used to:
[0256] When the database's instruction information indicates that syntax correction is performed using the database's table metadata, partial table metadata of the database corresponding to the query text is obtained;
[0257] When the indication information of the local text fragment is used to instruct the extraction of local text fragments in the query text to perform syntax correction, the local text fragments at the positions of the at least one syntax error are extracted from the query text to obtain at least one syntax error fragment in the query text;
[0258] The second preparation data is obtained based on the partial table information, the correction strategies of the at least one syntax error segment and the syntax error location corresponding to the syntax correction rules.
[0259] In some embodiments, the text correction module is used for:
[0260] The third AI model generates at least one corrected grammatical error fragment based on the third prompt information.
[0261] The at least one grammatically incorrect segment in the query text is replaced with the at least one corrected grammatically incorrect segment to obtain the grammatically corrected query text.
[0262] In some embodiments, the knowledge base includes a grammar rule base and a semantic rule base. The grammar rule base includes at least one grammar correction rule, which is used to indicate a strategy for correcting grammatical errors. The semantic rule base includes the at least one semantic correction rule.
[0263] In some embodiments, the apparatus further includes a knowledge base update module, the knowledge base update module being configured to:
[0264] Obtain log data of query failures. The log data of query failures includes query failure text and process information of the query failure text. The query failure text is the query text in which data was not successfully retrieved from the database. The process information is used to indicate the query steps of the query failure text.
[0265] The fourth AI model generates error correction rules corresponding to the query failure text based on the query failure text and the process information of the query failure text;
[0266] If the error correction rule corresponding to the failed query text passes the compliance verification, the knowledge base is updated according to the error correction rule corresponding to the failed query text to obtain the updated knowledge base.
[0267] In some embodiments, the knowledge base includes at least two error correction rules; the knowledge base update module is configured to:
[0268] Calculate the similarity between the error correction rule corresponding to the failed query text and the at least two error correction rules respectively to obtain at least two similarities;
[0269] Semantic merging is performed on the error correction rule corresponding to the maximum value of the at least two similarities and the error correction rule corresponding to the query failure text to obtain the updated error correction rule;
[0270] The error correction rule corresponding to the maximum value in the knowledge base is replaced with the updated error correction rule to obtain the updated knowledge base.
[0271] It should be noted that the apparatus provided in the above embodiments is only illustrated by the division of the above functional modules when implementing its functions. In actual applications, the above functions can be assigned to different functional modules as needed, that is, the content structure of the device can be divided into different functional modules to complete all or part of the functions described above. In addition, the apparatus and method embodiments provided in the above embodiments belong to the same concept, and the specific implementation process can be found in the method embodiments, which will not be repeated here.
[0272] Please refer to Figure 15 This diagram illustrates a structural block diagram of a computer device 1500 provided in one embodiment of this application. The computer device 1500 can be any electronic device capable of data calculation, processing, and storage. The computer device 1500 can be used to implement the error detection method for database query text provided in the above embodiments.
[0273] Typically, computer device 1500 includes a processor 1501 and a memory 1502.
[0274] Processor 1501 may include one or more processing cores, such as a quad-core processor, an octa-core processor, etc. Processor 1501 may be implemented using at least one hardware form selected from DSP (Digital Signal Processing), FPGA (Field Programmable Gate Array), and PLA (Programmable Logic Array). Processor 1501 may also include a main processor and a coprocessor. The main processor, also known as a CPU (Central Processing Unit), is used to process data in the wake-up state; the coprocessor is a low-power processor used to process data in the standby state. In some embodiments, processor 1501 may integrate a GPU (Graphics Processing Unit), which is responsible for rendering and drawing the content to be displayed on the screen. In some embodiments, processor 1501 may also include an AI processor for handling computational operations related to machine learning.
[0275] The memory 1502 may include one or more computer-readable storage media, which may be non-transitory. The memory 1502 may also include high-speed random access memory and non-volatile memory, such as one or more disk storage devices or flash memory devices. In some embodiments, the non-transitory computer-readable storage media in the memory 1502 is used to store a computer program configured to be executed by one or more processors to implement the above-described error detection method for database query text.
[0276] Those skilled in the art will understand that Figure 15 The structure shown does not constitute a limitation on the computer device 1500, and may include more or fewer components than shown, or combine certain components, or use different component arrangements.
[0277] In an illustrative embodiment, a computer-readable storage medium is also provided, wherein a computer program is stored in the storage medium, and the computer program, when executed by a processor of a computer device, implements the above-described error detection method for database query text. Optionally, the above-described computer-readable storage medium may be ROM (Read-Only Memory), RAM (Random Access Memory), CD-ROM (Compact Disc Read-Only Memory), magnetic tape, floppy disk, and optical data storage device, etc.
[0278] In an exemplary embodiment, a computer program product is also provided, comprising a computer program stored in a computer-readable storage medium. A processor of a computer device reads the computer program from the computer-readable storage medium and executes the computer program, causing the computer device to perform the aforementioned error detection method for database query text.
[0279] It should be noted that this application may display prompt interfaces, pop-ups, or output voice prompts before and during the collection of user data. These prompt interfaces, pop-ups, or voice prompts are used to inform users that their data is being collected. This ensures that the application only begins the steps for collecting user data after receiving confirmation from the user regarding the prompt interface or pop-up; otherwise (i.e., without user confirmation), the steps for collecting user data end, meaning no user data is collected. In other words, all user data collected by this application is processed strictly in accordance with the requirements of relevant national laws and regulations. The informed consent or separate consent of the data subject is obtained only with the user's consent and authorization. Subsequent data use and processing are conducted within the scope of laws, regulations, and the data subject's authorization, and the collection, use, and processing of relevant user data must comply with the relevant laws, regulations, and standards of the relevant countries and regions.
[0280] It should be understood that "multiple" as used herein refers to two or more. "And / or" describes the relationship between related objects, indicating that three relationships can exist. For example, A and / or B can represent: A alone, A and B simultaneously, or B alone. The character " / " generally indicates that the preceding and following related objects are in an "or" relationship. Furthermore, the step numbers described herein are merely illustrative of one possible execution order. In some other embodiments, the steps may not be executed in numerical order, such as two steps with different numbers being executed simultaneously, or two steps with different numbers being executed in the reverse order of the illustration. This application does not limit this.
[0281] The above description is merely an exemplary embodiment of this application and is not intended to limit this application. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of this application should be included within the protection scope of this application.
Claims
1. A method for error detection in database query text, characterized in that, The method includes: Obtain query text for a database, the query text including at least one text fragment, the query text being used to query data stored in the database; Perform semantic parsing on the query text to obtain at least one suspicious text fragment in the query text, wherein the suspicious text fragment is a text fragment that is suspected of having a semantic error; Obtain semantic error correction rules corresponding to the at least one suspicious text fragment from the knowledge base, wherein the knowledge base includes at least one semantic error correction rule, and the semantic error correction rule is used to indicate the correction strategy for semantic errors; Based on the semantic error correction rules corresponding to the query text, the at least one suspicious text fragment, and the at least one suspicious text fragment, a semantic evaluation result of the query text is obtained, and the semantic evaluation result is used to indicate whether there are semantic errors in the query text.
2. The method according to claim 1, characterized in that, The knowledge base also includes tag information corresponding to each of the at least one semantic error correction rule; The step of obtaining the semantic correction rules corresponding to the at least one suspicious text fragment from the knowledge base includes: For each suspicious text segment, according to the tag information corresponding to the suspicious text segment and the at least one semantic error correction rule respectively, the tag information matching the suspicious text segment is obtained. The tag information matching the suspicious text segment is the tag information with the highest matching degree among the tag information corresponding to the at least one semantic error correction rule respectively. The semantic error correction rule corresponding to the tag information matched by the suspicious text fragment is determined as the semantic error correction rule corresponding to the suspicious text fragment.
3. The method according to claim 1 or 2, characterized in that, The step of obtaining the semantic evaluation result of the query text based on the semantic correction rules corresponding to the query text, the at least one suspicious text segment, and the at least one suspicious text segment includes: A first prompt message is generated based on the query text, the at least one suspicious text fragment, the semantic correction rules corresponding to the at least one suspicious text fragment, and the first configuration template; wherein, the first configuration template is used to indicate the arrangement rules of the semantic correction rules corresponding to the query text, the at least one suspicious text fragment, and the at least one suspicious text fragment. The semantic evaluation result of the query text is obtained by the first artificial intelligence (AI) model based on the first prompt information.
4. The method according to any one of claims 1 to 3, characterized in that, The knowledge base also includes at least one syntax correction rule, which is used to indicate the strategy for correcting syntax errors. The method further includes: Based on at least one of the semantic evaluation result and the grammatical evaluation result of the query text, the error correction rule corresponding to the query text is obtained from the knowledge base; wherein, the grammatical evaluation result is used to indicate whether there is a grammatical error in the query text; when the grammatical evaluation result indicates that there is a grammatical error in the query text, the error correction rule corresponding to the query text includes the grammatical error correction rule corresponding to the query text; when the semantic evaluation result indicates that there is a semantic error in the query text, the error correction rule corresponding to the query text includes the semantic error correction rule corresponding to the query text. Based on the error correction rules corresponding to the query text, the query text is corrected to obtain the corrected query text.
5. The method according to claim 4, characterized in that, In the event that a semantic error exists in the query text, the semantic evaluation result is also used to indicate at least one semantically erroneous segment in the query text and the semantic error type corresponding to the at least one semantically erroneous segment; The step of obtaining the error correction rule corresponding to the query text from the knowledge base based on at least one of the semantic evaluation result and the syntactic evaluation result of the query text includes: For each semantic error segment, according to the semantic error type corresponding to the semantic error segment and the label information corresponding to the at least one semantic error correction rule, the label information matching the semantic error segment is obtained. The label information matching the semantic error segment is the label information with the highest matching degree among the label information corresponding to the at least one semantic error correction rule. The semantic error correction rule corresponding to the tag information matched by the semantic error fragment is determined as the semantic error correction rule corresponding to the semantic error fragment; Based on the semantic error correction rules corresponding to the at least one semantic error segment, the semantic error correction rules corresponding to the query text are obtained.
6. The method according to claim 4 or 5, characterized in that, In the event of a semantic error in the query text, the semantic evaluation result is also used to indicate semantic correction suggestions for the query text; The step of correcting the query text based on the error correction rules corresponding to the query text to obtain the corrected query text includes: Obtain partial table element information of the database corresponding to the query text; the partial table element information is used to indicate the structural information in the database that matches the query text. Based on the partial table metadata, the semantic error correction rules corresponding to the query text, the at least one semantic error fragment, and the semantic correction suggestion, the first preparation data corresponding to the query text is obtained. The first preparation data is the data used to perform semantic error correction on the query text. Based on the first prepared data and the second configuration template, a second prompt message is generated, wherein the second configuration template is used to indicate the arrangement rules of the first prepared data. The second AI model generates semantically corrected query text based on the second prompt information.
7. The method according to any one of claims 4 to 6, characterized in that, If there are grammatical errors in the query text, the grammatical evaluation result is also used to indicate at least one location of a grammatical error in the query text and the grammatical error type corresponding to each of the at least one grammatical error locations; the knowledge base also includes tag information corresponding to at least one grammatical correction rule. The step of obtaining the error correction rule corresponding to the query text from the knowledge base based on at least one of the semantic evaluation result and the syntactic evaluation result of the query text includes: For each of the syntax error locations, according to the syntax error type corresponding to the syntax error location and the tag information corresponding to the at least one syntax correction rule, the tag information matching the syntax error location is obtained. The tag information matching the syntax error location is the tag information with the highest matching degree between the at least one syntax correction rule and the syntax error type corresponding to the syntax error location. The syntax correction rule corresponding to the tag information matched by the syntax error location is determined as the syntax correction rule corresponding to the syntax error location. Based on the syntax correction rules corresponding to the at least one syntax error location, the syntax correction rules corresponding to the query text are obtained.
8. The method according to claim 7, characterized in that, The step of correcting the query text based on the error correction rules corresponding to the query text to obtain the corrected query text includes: Based on the query text and the corresponding syntax correction rules, the second preparation data corresponding to the query text is obtained. The second preparation data is the data used to perform syntax correction on the query text. Based on the second prepared data and the third configuration template, a third prompt message is generated, wherein the third configuration template is used to indicate the arrangement rules of the second prepared data; The third AI model obtains the grammatically corrected query text based on the third prompt information.
9. The method according to claim 8, characterized in that, The syntax correction rules corresponding to the syntax error locations include: the database indication information, the local text fragment indication information, and the correction strategy of the syntax correction rules corresponding to the syntax error locations. The database indication information is used to indicate whether to use the table meta information of the database to perform syntax correction, and the local text fragment indication information is used to indicate whether to extract the syntax error fragments in the query text to perform syntax correction. The step of obtaining the second preparation data corresponding to the query text based on the query text and the corresponding syntax correction rules includes: When the database's instruction information indicates that syntax correction is performed using the database's table metadata, partial table metadata of the database corresponding to the query text is obtained; When the indication information of the local text fragment is used to instruct the extraction of local text fragments in the query text to perform syntax correction, the local text fragments at the positions of the at least one syntax error are extracted from the query text to obtain at least one syntax error fragment in the query text; The second preparation data is obtained based on the partial table information, the correction strategies of the at least one syntax error segment and the syntax error location corresponding to the syntax correction rules.
10. The method according to claim 9, characterized in that, The process of obtaining the grammatically corrected query text through a third AI model based on the third prompt information includes: The third AI model generates at least one corrected grammatical error fragment based on the third prompt information. The at least one grammatically incorrect segment in the query text is replaced with the at least one corrected grammatically incorrect segment to obtain the grammatically corrected query text.
11. The method according to any one of claims 1 to 10, characterized in that, The knowledge base includes a syntax rule base and a semantic rule base. The syntax rule base includes at least one syntax error correction rule, which is used to indicate the correction strategy for syntax errors. The semantic rule base includes the at least one semantic error correction rule.
12. The method according to any one of claims 1 to 11, characterized in that, The method further includes: Obtain log data of query failures. The log data of query failures includes query failure text and process information of the query failure text. The query failure text is the query text in which data was not successfully retrieved from the database. The process information is used to indicate the query steps of the query failure text. The fourth AI model generates error correction rules corresponding to the query failure text based on the query failure text and the process information of the query failure text; If the error correction rule corresponding to the failed query text passes the compliance verification, the knowledge base is updated according to the error correction rule corresponding to the failed query text to obtain the updated knowledge base.
13. The method according to claim 12, characterized in that, The knowledge base includes at least two error correction rules; The step of updating the knowledge base according to the error correction rules corresponding to the failed query text to obtain the updated knowledge base includes: Calculate the similarity between the error correction rule corresponding to the failed query text and the at least two error correction rules respectively to obtain at least two similarities; Semantic merging is performed on the error correction rule corresponding to the maximum value of the at least two similarities and the error correction rule corresponding to the query failure text to obtain the updated error correction rule; The error correction rule corresponding to the maximum value in the knowledge base is replaced with the updated error correction rule to obtain the updated knowledge base.
14. An error detection device for database query text, characterized in that, The device includes: The text acquisition module is used to acquire query text for a database, the query text including at least one text fragment, the query text being used to query data stored in the database; The semantic parsing module is used to perform semantic parsing on the query text to obtain at least one suspicious text fragment in the query text, wherein the suspicious text fragment is a text fragment that is suspected of having semantic errors; The rule extraction module is used to obtain semantic error correction rules corresponding to the at least one suspicious text fragment from the knowledge base. The knowledge base includes at least one semantic error correction rule, which is used to indicate the correction strategy for semantic errors. The semantic evaluation module is used to obtain the semantic evaluation result of the query text based on the semantic error correction rules corresponding to the query text, the at least one suspicious text fragment, and the at least one suspicious text fragment, respectively. The semantic evaluation result is used to indicate whether there are semantic errors in the query text.
15. A computer device, characterized in that, The computer device includes a processor and a memory, the memory storing a computer program, the computer program being loaded and executed by the processor to implement the error detection method for database query text as described in any one of claims 1 to 13.
16. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program, which is loaded and executed by a processor to implement the error detection method for database query text as described in any one of claims 1 to 13.
17. A computer program product, characterized in that, The computer program product includes a computer program that is loaded and executed by a processor to implement the error detection method for database query text as described in any one of claims 1 to 13.
