Anaphora disambiguation method and system based on big language model enhanced text and structured query language generation
By combining a large language model with semantic and fuzzy matching methods, we can automatically identify fuzzy time expressions and optimize query generation, which solves the problems of low query accuracy and resource waste in existing technologies and achieves efficient and accurate generation of structured query language.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- CHINA TELECOM DIGITAL INTELLIGENCE TECH CO LTD
- Filing Date
- 2025-12-19
- Publication Date
- 2026-05-01
AI Technical Summary
Existing technologies struggle to accurately identify the association between user intent and database fields when dealing with complex referential relationships, especially in scenarios with ambiguous expressions or unclear semantics. This leads to inaccurate query results, and fixed value matching methods result in wasted resources when not needed.
Employing a large language model-based approach, this method utilizes a dual mechanism of semantic matching and fuzzy matching, combined with time awareness and threshold judgment, to automatically identify and match fuzzy time expressions. It triggers the referential disambiguation process only when necessary, generating structured query language statements that conform to database syntax.
It improves query accuracy and resource utilization, reduces computational overhead, is suitable for large-scale, high-concurrency enterprise-level database environments, and enhances query accuracy and practicality in time series data analysis scenarios.
Smart Images

Figure CN121958307A_ABST
Abstract
Description
A method and system for disambiguation of reference based on large language model-enhanced text and structured query language generation Technical Field
[0001] This invention relates to the field of natural language processing technology, specifically to a method and system for disambiguation of reference based on large language models to enhance text and structured query language generation. Background Technology
[0002] Disambiguation is a key task in natural language processing, its core function being to accurately resolve ambiguous expressions in text and clarify the correspondence between referents and actual database elements. This task is particularly important in text-to-structured query language generation, as its accuracy directly determines the correctness of the final generated SQL query. However, due to the diversity of natural language expressions, existing methods based on large language models have limited performance in handling complex referential relationships. Especially when faced with ambiguous expressions or semantically unclear scenarios, models often struggle to accurately identify the association between user intent and specific database fields, thus affecting the correctness of query results.
[0003] One of the main approaches currently employed is to provide external knowledge. For example, Blar-SQL enhances model understanding by introducing column descriptions and external knowledge: column descriptions supplement semantic information from database fields, while external knowledge helps the model understand domain-specific concepts. Additionally, there are methods that provide clearer semantic knowledge by constructing detailed data documents, such as recording data consistency, coverage, and granularity, and specifying query output patterns. While providing external knowledge can reduce ambiguity to some extent, injecting a large amount of supplementary information and database values into hints is often impractical due to the context window limitations of large language models. Furthermore, because external knowledge needs to be pre-imported, this approach lacks robustness and flexibility in practical applications.
[0004] Existing research on relevance-based value retrieval methods primarily focuses on similarity matching. For example, XiYan-SQL extracts keywords using few-shot suggestions and utilizes a column retriever and a value retriever based on locality-sensitive hashing and semantic similarity to obtain relevant information, subsequently generating concise pattern links through a column selector. However, the column selector relies on the judgment of a large language model; if the model lacks sufficient understanding of domain knowledge, it may incorrectly remove necessary columns, thus affecting the accuracy of SQL generation. E-SQL optimizes pattern links through a candidate predicate generation module, which parses candidate SQL and uses the LIKE operator to match similar values in the database to generate candidate predicates. However, fuzzy matching relying solely on the LIKE operator may ignore the deep semantic information of the values, leading to deviations between the generated candidate predicates and the user's true intent. CHASE-SQL extracts keywords from the user query, uses the locality-sensitive hashing algorithm to obtain semantically similar words, and then re-ranks the search results through semantic matching and edit distance to improve accuracy. However, this method does not strictly limit the matching scope, which may introduce significant time overhead in practical applications.
[0005] Furthermore, existing value matching methods are typically performed as a fixed preprocessing step. However, not all SQL generation requires referential disambiguation. For queries that can be correctly generated by the model itself, pre-executing the value matching module can actually waste significant computational resources, a problem particularly pronounced in real-world enterprise database environments. Summary of the Invention
[0006] The purpose of this invention is to provide a method and system for disambiguation of pronouns based on large language model-enhanced text and structured query language generation, so as to solve the problems of low query accuracy and serious resource waste caused by ambiguous pronouns, unclear time expressions, single and fixed matching methods in the prior art.
[0007] To achieve the above objectives, the technical solution provided by this invention is: a method for disambiguation of reference based on large language model-enhanced text and structured query language generation, comprising the following steps: S1: receiving a natural language question input by a user, analyzing it based on pattern information in a database, generating and outputting structured table field information associated with the natural language question; S2: identifying fuzzy time expressions in the natural language question, converting them into a specific time range based on the current time point, and generating a rewritten user question containing the specific time range; S3: performing intent recognition on the natural language question, extracting ambiguous named entities, and disambiguating them through semantic matching and fuzzy matching. Matching involves matching and replacing ambiguous named entities with standard values in the database, outputting standardized user questions; S4: Based on the structured table field information, the rewritten user questions, and the standardized user questions, a structured query language statement conforming to database syntax is generated; S5: The structured query language statement is executed; if execution is successful and returns valid data, the valid data is output as the query result; if execution is successful but the return result is empty, the referencing disambiguation process is triggered: the field values in the structured query language statement are corrected, a corrected structured query language statement is generated, the structured query language statement is executed, and its query result is output.
[0008] To optimize the above technical solution, the specific measures also include: In step S1, the analysis based on the schema information in the database to generate and output structured table field information associated with the user's question specifically includes: constructing a prompt template containing database schema information, wherein the database schema information includes table name, field name, field type, primary key, default value, whether NULL is allowed, and sample sub-data; the prompt template includes structured constraints on the output format, specifying that the identified table name and its associated field list are output in JSON format; further, the prompt template and the natural language question are input into a large language model, which parses the semantics of the question and matches it with the database schema, outputting analysis results containing preliminary correlations; and extracting a list of table names and field names that conform to the structured constraints from the analysis results as structured table field information.
[0009] In step S2, identifying fuzzy time expressions in natural language questions, converting them into specific time ranges based on the current time, and generating a rewritten user question containing the specific time range includes: guiding the large language model to identify the types of time expressions in natural language questions, including explicit time, relative time, and fuzzy time, using a Few-Shot prompting method; parsing the identified time expressions into specific start and end time points based on the current time; and replacing the fuzzy time expressions in the original question with specific time ranges to generate a rewritten user question containing the specific time ranges.
[0010] In step S3, the step of matching and replacing ambiguous named entities with standard values in the database through semantic matching and fuzzy matching to output a standardized user question specifically includes: further, based on preset entity recognition prompts, parsing ambiguous named entities and their corresponding database fields from the natural language question to generate an intermediate representation set; for each entity in the intermediate representation set, performing a matching operation: using a sentence embedding model to encode all unique values in the entity and corresponding field column into vectors, and calculating cosine similarity; if the highest similarity exceeds a first preset threshold, then directly selecting that value as the matching result; otherwise, further using a fuzzy matching algorithm based on Levenshtein edit distance to calculate character similarity; further, combining semantic similarity and character similarity, determining the best matching value through weighted scoring, and replacing the corresponding entity in the original question to output the standardized user question.
[0011] In step S4, generating a structured query language statement that conforms to the database syntax based on the structured table field information, the rewritten user question, and the standardized user question specifically includes: using the structured table field information, the rewritten user question, and the standardized user question as a reference context for generating the structured query language statement; and comprehensively understanding the query intent, time conditions, standardized entities, and database table structure through a large language model to generate a structured query language statement that conforms to the target database syntax specification.
[0012] In step S5, executing the structured query language statement further includes: setting an execution timeout threshold; when the execution time exceeds the threshold, returning an execution timeout error and not triggering the referencing disambiguation step.
[0013] Further, in step S5, the referential disambiguation process specifically includes: parsing the structured query language statement, locating the condition field corresponding to the named entity extracted from its WHERE clause, and using the named entity as the original field value input by the user; using a sentence embedding model to calculate the cosine similarity between the original field value and all unique values in the corresponding column of the condition field; selecting the candidate value with the highest similarity exceeding a preset threshold as the semantic matching result; further, if the semantic matching does not reach the preset threshold, using Levenshtein edit distance to calculate the character similarity between the original field value and each candidate value, and selecting the candidate value with the highest similarity as the fuzzy matching result; determining the final matching value from the semantic matching result and the fuzzy matching result according to preset rules, and replacing the field value in the original statement to generate the corrected structured query language statement.
[0014] As another important technical solution, this invention also provides a referential disambiguation system based on large language model-enhanced text and structured query language generation, comprising: a pattern parsing module, used to receive natural language questions input by users, analyze pattern information based on the database, generate and output structured table field information associated with the natural language questions; a time normalization module, used to identify fuzzy time expressions in natural language questions, convert them into specific time ranges based on the current time point, and generate rewritten user questions containing specific time ranges; and an entity disambiguation module, used to perform intent recognition on natural language questions, extract ambiguous named entities, and resolve them through semantic matching and fuzzy matching. Ambiguous named entities are matched and replaced with standard values in the database, outputting standardized user questions. A Structured Query Language (SCL) statement generation module generates SCL statements that conform to database syntax based on structured table field information, rewritten user questions, and standardized user questions. A dynamic disambiguation execution module executes the SCL statements; if execution is successful and returns valid data, the valid data is output as the query result; if execution is successful but returns an empty result, the referencing disambiguation process is triggered: the field values in the SCL statements are corrected, a corrected SCL statement is generated, the SCL statement is executed, and its query result is output.
[0015] The present invention also proposes an electronic device, comprising: a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the computer program, it implements a reference disambiguation method based on large language model-enhanced text and structured query language generation as described above.
[0016] The present invention also proposes a computer-readable storage medium storing a computer program that enables a computer to execute a reference disambiguation method based on large language model-enhanced text and structured query language generation as described above.
[0017] Compared with the prior art, the beneficial effects of the present invention are: by integrating semantic matching and fuzzy matching dual matching mechanisms, the present invention considers both semantic relevance and character similarity in the process of referential disambiguation, effectively solving the field value matching deviation caused by differences in expression, spelling variations or inconsistencies in abbreviations or full names, and improving the matching accuracy and generalization ability.
[0018] This invention integrates time awareness and time rewriting, which can automatically identify ambiguous time descriptions in user queries and convert them into specific date ranges based on the current time. This effectively avoids query failures or result deviations caused by unclear time descriptions, and improves the accuracy and practicality of queries in time series data analysis scenarios.
[0019] This invention introduces a hierarchical matching design based on threshold judgment, which performs fast matching within the current column range. If the confidence threshold is not reached, it automatically expands to a full database search. This ensures matching efficiency in common scenarios and comprehensive matching in complex and ambiguous situations, achieving a good balance between computational performance and query results.
[0020] This invention uses an adaptive triggering mechanism to automatically initiate the referencing disambiguation process only when the SQL execution result is abnormal. This avoids performing unnecessary calculations in simple queries or scenarios where disambiguation is not required, significantly reducing system overhead and making it suitable for large-scale, high-concurrency enterprise-level database environments.
[0021] The methods of schema parsing, time normalization, entity disambiguation, and dynamic execution in this invention are easy to extend and adapt to different database architectures and application scenarios. Attached Figure Description
[0022] Figure 1: Schematic diagram of the referential disambiguation process in an embodiment of the present invention.
[0023] Figure 2: Schematic diagram of the algorithm flow in an embodiment of the present invention. The following detailed description of the embodiments further illustrates the above-mentioned content of the present invention. However, it should not be construed as limiting the scope of the above-mentioned subject matter of the present invention to the following embodiments. All technologies implemented based on the above-mentioned content of the present invention fall within the scope of the present invention.
[0024] The following is an explanation of some terms used in this invention: Structured Query Language (SQL): a standard programming language used to manage and manipulate relational databases. It achieves precise control over data through a series of commands, is applicable to various database management systems, and is widely used to store, retrieve, update, and delete data in databases.
[0025] NL2SQL (Natural Language to Structured Query Language) is a natural language processing technology used to automatically convert user questions in natural language into structured query language in order to extract relevant data from the database. It is often used to build intelligent question-answering systems, data analysis assistants and other platforms to lower the barrier for non-technical users to interact with the database.
[0026] Natural Language Processing (NLP) is a technology in the field of artificial intelligence that aims to enable computers to understand, generate, and process human natural language. It combines computational linguistics, machine learning, and deep learning methods to achieve various functions by analyzing the syntax, semantics, and context of text or speech.
[0027] Pattern linking is a technique for establishing semantic connections between natural language problems and database structures. This technique identifies and aligns words or phrases in natural language with pattern elements in a database to correctly generate corresponding SQL queries. It significantly improves the model's understanding of the database structure and is one of the core steps in enhancing the accuracy and generalization capabilities of NL2SQL systems.
[0028] M-Schema, proposed by XiYan-SQL, is a semi-structured database schema representation method that generates detailed metadata descriptions for selected data tables, including table names, field names, field types, primary keys, default values, whether NULL is allowed, and sample sub-data. M-Schema introduces data types and more detailed column descriptions, reducing ambiguity when handling similar columns and ensuring more accurate execution of generated SQL queries. It significantly improves the accuracy of generated SQL when handling complex queries.
[0029] Levenshtein distance is a metric that measures the minimum number of editing operations required to transform one string into another. This includes insertion, deletion, and replacement operations. The distance value represents the minimum number of operations required to transform one string into another, and it is widely used in fields such as spell correction, information retrieval, and natural language processing.
[0030] Sentence Transformers are models used to map sentences to fixed-length vectors, based on pre-trained Transformer architectures (such as BERT). By optimizing sentence-level embeddings, SentenceTransformers can improve performance in natural language processing tasks such as sentence similarity calculation, semantic retrieval, and text matching. They are typically adapted for specific tasks through fine-tuning.
[0031] distiluse-base-multilingual-cased-v1 is a multilingual sentence embedding model based on the Transformer architecture, belonging to the Sentence Transformers family. It compresses the originally large BERT model through distillation, making it more efficient while maintaining high performance. It supports multilingual input and transforms sentences into fixed-dimensional vector representations. It is widely used in natural language processing tasks such as semantic search, text similarity calculation, and cross-language text matching.
[0032] The technical solution of the present invention will be further described in detail below with reference to specific embodiments: In some embodiments, as shown in Figure 2, the present invention provides a method for disambiguation of reference based on large language model-enhanced text and structured query language generation, including the following steps: S1: Receive a natural language question input by a user, analyze it based on the pattern information in the database, generate and output structured table field information associated with the natural language question; In some embodiments, construct a prompt template containing database pattern information M-Schema, wherein the database pattern information M-Schema includes table name, field name, field type, primary key, default value, whether NULL is allowed, sample sub-data, etc.; The prompt template includes structured constraints on the output format, specifying that the identified table name and its associated field list are output in JSON format; Input the prompt template and the natural language question into the large language model, the large language model parses the semantics of the question and matches it with the database pattern, and outputs analysis results containing preliminary association relationships; Extract the list of table names and field names that conform to the structured constraints from the analysis results as structured table field information.
[0033] S2: Identify ambiguous time expressions in natural language questions, convert them into specific time ranges based on the current time point, and generate rewritten user questions containing the specific time ranges; in some implementations, based on the Few-Shot large language model, accurately locate various time descriptions in user questions, including explicit time (e.g., 2023), relative time (e.g., the last three months), and ambiguous time (e.g., the beginning of the year); then, combined with contextual semantic analysis and the system's current timestamp, convert the time into specific time points. <yyyy-mm-dd>Finally, a new query statement containing a specific time range is generated without changing the original query intent.
[0034] As shown in Figure 1, S3: Perform intent recognition on the natural language question, extract ambiguous named entities, match and replace the ambiguous named entities with standard values in the database through semantic matching and fuzzy matching, and output the standardized user question; Based on the preset entity recognition prompts, parse the ambiguous named entities and their corresponding database fields from the natural language question, generate an intermediate representation set, and perform a matching operation on each entity in the intermediate representation set: In some implementations, the pre-trained Sentence-BERT model is called to first convert the entity to be matched into vector form, and at the same time, all non-repeating values in the corresponding field column of the database are also encoded into vectors one by one; Then, the cosine similarity algorithm is used to calculate the similarity value between the entity vector and the field value vector, with the value range being [-1, 1]. The closer the value is to 1, the higher the semantic matching degree. The system will filter out the top few results with the highest similarity values. If the highest value exceeds the first preset threshold (e.g., 0.7), the field value will be selected as the matching result. If it does not reach the first preset threshold, the system will use a fuzzy matching algorithm based on Levenshtein edit distance to supplement the calculation of character similarity. Combining semantic similarity and character similarity, the system will determine the best matching value through weighted scoring and replace the corresponding entity in the original question, outputting the standardized user question.
[0035] Preferably, if no suitable match is found after fuzzy matching within a column, it is determined that the initial field column association may be inaccurate or the entity description is too vague. In this case, the system will perform an extended search across the entire database: using the entity name, it will quickly retrieve the string-type fields from all tables in the database using the aforementioned semantic and character similarity combination algorithm, selecting several candidate values with the highest global similarity. The system may prompt the user for confirmation or automatically select the most probable value based on predefined confidence rules.
[0036] Entity information is the specific named entities parsed from the initial user question by the large language model based on a preset entity recognition template.
[0037] S4: Based on the structured table field information, the rewritten user question, and the standardized user question, a structured query language statement conforming to database syntax is generated. The structured table field information, the rewritten user question, and the standardized user question serve as the reference context for generating the structured query language statement. Utilizing the code generation capabilities of a large language model, an SQL query statement conforming to database syntax specifications is automatically constructed. This process intelligently determines the query type (such as data retrieval, statistical calculation, or multi-table joins) and comprehensively considers the identified query conditions (WHERE clause), target fields (SELECT part), and sorting / grouping requirements (ORDER BY / GROUP BY), ultimately generating a syntactically correct and fully executable structured query language statement that reflects the user's intent. Simultaneously, query optimization ensures execution efficiency.
[0038] S5: Execute the Structured Query Language (SCL) statement; if the execution is successful and returns valid data, output the valid data as the query result; if the execution is successful but the returned result is empty, trigger the referencing disambiguation process: correct the field values in the SCL statement, generate a corrected SCL statement, execute the SCL statement and output its query result.
[0039] In some implementations, an empty query result is not a syntax error, but rather a situation where no matching data was found after the Structured Query Language (SCL) statement was executed. If the system returns an error indicating that the execution time is too long, it will not be determined to be a field value matching problem, nor will it trigger the referencing disambiguation process. Manual intervention is required to optimize the SQL (such as simplifying multi-table joins, adding indexes) or adjust the timeout threshold.
[0040] The disambiguation process specifically includes: parsing the structured query language statement, locating the condition field corresponding to the named entity extracted from its WHERE clause, and using the named entity as the original field value input by the user; calculating the cosine similarity between the original field value and all unique values in the corresponding column of the condition field using a sentence embedding model (e.g., the distiluse-base-multilingual-cased-v1 model in Sentence Transformers); selecting the candidate value with the highest similarity exceeding a preset threshold as the semantic matching result; preferably, if the semantic matching does not reach the preset threshold, using Levenshtein edit distance to calculate the character similarity between the original field value and each candidate value to address spelling variations or differences in expression details, and selecting the candidate value with the highest similarity as the fuzzy matching result; determining the final matching value from the semantic matching result and the fuzzy matching result according to preset rules, and replacing the field value in the original statement to generate a corrected structured query language statement, thereby effectively solving the query failure problem caused by expression deviation and improving the robustness of the system.
[0041] In another embodiment of this invention, a disambiguation system for reference based on large language model-enhanced text and structured query language generation is proposed, comprising: a pattern parsing module, used to receive natural language questions input by users, analyze pattern information based on a database, generate and output structured table field information associated with the natural language questions; a time normalization module, used to identify fuzzy time expressions in natural language questions, convert them into specific time ranges based on the current time point, and generate rewritten user questions containing specific time ranges; and an entity disambiguation module, used to perform intent recognition on natural language questions, extract ambiguous named entities, and disambiguate ambiguous named entities through semantic matching and fuzzy matching. The system matches and replaces named entities with standard values in the database, outputting standardized user questions. A Structured Query Language (SCL) statement generation module generates SCL statements that conform to database syntax based on structured table field information, the rewritten user questions, and the standardized user questions. A dynamic disambiguation execution module executes the SCL statements; if execution is successful and returns valid data, the valid data is output as the query result; if execution is successful but the result is empty, the referencing disambiguation process is triggered: the field values in the SCL statements are corrected, a corrected SCL statement is generated, the SCL statement is executed, and its query result is output.
[0042] In another embodiment of the present invention, an electronic device is proposed, comprising: a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the computer program, it implements a reference disambiguation method based on large language model-enhanced text and structured query language generation as described above.
[0043] In another embodiment of the present invention, a computer-readable storage medium is provided, storing a computer program that causes a computer to execute a referential disambiguation method based on large language model-enhanced text and structured query language generation as described above.
[0044] In the embodiments disclosed in this application, a computer storage medium may be a tangible medium that may contain or store programs for use by or in conjunction with an instruction execution system, apparatus, or device. The computer storage medium may include, but is not limited to, electronic, magnetic, optical, electromagnetic, infrared, or semiconductor systems, apparatus, or devices, or any suitable combination of the foregoing. More specific examples of computer storage media include electrical connections based on one or more wires, portable computer disks, hard disks, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fibers, portable compact disk read-only memory (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination of the foregoing.
[0045] The above description is merely a preferred embodiment of the present invention and is not intended to limit the present invention in any way. Any simple modifications, equivalent substitutions, and improvements made by those skilled in the art to the above embodiments without departing from the scope of the technical solution of the present invention, based on the technical essence of the present invention, shall still fall within the protection scope of the technical solution of the present invention.
Claims
1. A method for disambiguation of pronouns based on large language models to enhance text and structured query language generation, characterized in that, Includes the following steps: S1: Receive the natural language question input by the user, analyze it based on the pattern information in the database, generate and output the structured table field information associated with the natural language question; S2: Identify the fuzzy time expression in the natural language question, convert it into a specific time range based on the current time point, and generate a rewritten user question containing the specific time range; S3: Perform intent recognition on the natural language question, extract the ambiguous named entities, match and replace the ambiguous named entities with the standard values in the database through semantic matching and fuzzy matching, and output the standardized user question; S4: Based on the structured table field information, the rewritten user questions, and the standardized user questions, generate a structured query language statement that conforms to the database syntax; S5: Execute the Structured Query Language statement; if the execution is successful and returns valid data, output the valid data as the query result; If the execution is successful but the returned result is empty, the referencing disambiguation process is triggered: the field values in the structured query language statement are corrected, a corrected structured query language statement is generated, the structured query language statement is executed, and its query results are output.
2. The method for disambiguation of reference based on large language model-enhanced text and structured query language generation according to claim 1, characterized in that: In step S1, the analysis based on the schema information in the database to generate and output structured table field information associated with the user's question specifically includes: constructing a prompt template containing database schema information, including table name, field name, field type, primary key, default value, whether NULL is allowed, and sample sub-data; the prompt template includes structured constraints on the output format, specifying JSON format output of the identified table name and its associated field list; inputting the prompt template and the natural language question into a large language model, which parses the question semantics and matches them with the database schema, outputting analysis results containing preliminary associations; and extracting a list of table names and field names that conform to the structured constraints from the analysis results as structured table field information.
3. The method for disambiguation of reference based on large language model-enhanced text and structured query language generation according to claim 1, characterized in that: In step S2, identifying fuzzy time expressions in natural language questions, converting them into specific time ranges based on the current time, and generating a rewritten user question containing the specific time range includes: guiding the large language model to identify the types of time expressions in natural language questions, including explicit time, relative time, and fuzzy time, using a Few-Shot prompting method; parsing the identified time expressions into specific start and end time points based on the current time; and replacing the fuzzy time expressions in the original question with specific time ranges to generate a rewritten user question containing the specific time ranges.
4. The method for disambiguation of reference based on large language model-enhanced text and structured query language generation according to claim 1, characterized in that: In step S3, the step of matching and replacing ambiguous named entities with standard values in the database through semantic matching and fuzzy matching to output a standardized user question specifically includes: based on preset entity recognition prompts, parsing ambiguous named entities and their corresponding database fields from the natural language question to generate an intermediate representation set; for each entity in the intermediate representation set, performing a matching operation: using a sentence embedding model to encode all unique values in the entity and corresponding field column into vectors, and calculating cosine similarity; if the highest similarity exceeds a first preset threshold, then directly selecting that value as the matching result; otherwise, further using a fuzzy matching algorithm based on Levenshtein edit distance to calculate character similarity; combining semantic similarity and character similarity, determining the best matching value through weighted scoring, and replacing the corresponding entity in the original question to output the standardized user question.
5. The method for disambiguation of reference based on large language model-enhanced text and structured query language generation according to claim 1, characterized in that: In step S4, generating a structured query language statement that conforms to the database syntax based on the structured table field information, the rewritten user question, and the standardized user question specifically includes: using the structured table field information, the rewritten user question, and the standardized user question as a reference context for generating the structured query language statement; and comprehensively understanding the query intent, time conditions, standardized entities, and database table structure through a large language model to generate a structured query language statement that conforms to the target database syntax specification.
6. The method for disambiguation of reference based on large language model-enhanced text and structured query language generation according to claim 1, characterized in that: In step S5, executing the structured query language statement further includes: setting an execution timeout threshold; when the execution time exceeds the threshold, returning an execution timeout error and not triggering the referencing disambiguation step.
7. The method for disambiguation of reference based on large language model-enhanced text and structured query language generation according to claim 1, characterized in that: In step S5, the referential disambiguation process specifically includes: parsing the structured query language statement, locating the condition field corresponding to the named entity extracted from its WHERE clause, and using the named entity as the original field value input by the user; using a sentence embedding model to calculate the cosine similarity between the original field value and all unique values in the corresponding column of the condition field; selecting the candidate value with the highest similarity exceeding a preset threshold as the semantic matching result; if the semantic matching does not reach the preset threshold, using Levenshtein edit distance to calculate the character similarity between the original field value and each candidate value, and selecting the candidate value with the highest similarity as the fuzzy matching result; determining the final matching value from the semantic matching result and the fuzzy matching result according to preset rules, and replacing the field value in the original statement to generate the corrected structured query language statement.
8. A system for disambiguation of pronouns based on large language models to enhance text and structured query language generation, characterized in that, include: The pattern parsing module receives natural language questions input by the user, analyzes them based on pattern information in the database, and generates and outputs structured table field information associated with the natural language questions. The time normalization module identifies fuzzy time expressions in natural language questions, converts them into specific time ranges based on the current time, and generates rewritten user questions containing the specific time ranges. The entity disambiguation module performs intent recognition on natural language questions, extracts ambiguous named entities, and matches and replaces ambiguous named entities with standard values in the database through semantic matching and fuzzy matching, outputting standardized user questions. The Structured Query Language (SCL) statement generation module generates SCL statements that conform to database syntax based on structured table field information, rewritten user questions, and standardized user questions; the dynamic disambiguation execution module executes the SCL statements; if the execution is successful and returns valid data, the valid data is output as the query result. If the execution is successful but the returned result is empty, the referencing disambiguation process is triggered: the field values in the structured query language statement are corrected, a corrected structured query language statement is generated, the structured query language statement is executed, and its query results are output.
9. An electronic device, characterized in that, include: The memory, the processor, and the computer program stored in the memory and executable on the processor, wherein when the processor executes the computer program, it implements the reference disambiguation method based on large language model-enhanced text and structured query language generation as described in any one of claims 1 to 7.
10. A computer-readable storage medium having a computer program stored thereon, characterized in that: The computer program causes the computer to execute a referential disambiguation method based on large language model-enhanced text and structured query language generation as described in any one of claims 1 to 7.
Citation Information
Cited By
Enterprise-oriented large model question optimization method and system
CN122196147A
Active probe based enterprise database field semantic validation method and system
CN122262220A