Natural Language to SQL Conversion via Directed Acyclic Graphs
Find Innovative SolutionsGenerate Solutions
Solution Overview
Problem
Non-professionals face difficulties in mastering Structured Query Language (SQL) due to the need to learn various syntaxes, necessitating a method to convert natural language into structured query sentences for database querying.
Innovation Solution
A method and apparatus that utilize a pre-trained sequence-to-sequence model to convert natural language sentences into structured query sentences by generating a directed acyclic graph based on an action sequence, with the model trained using sample sets of natural language and structured query sentences, and outputting the structured query sentence based on a preset corresponding relationship.
Engineering Contradictions & Design Principles
Engineering Contradiction Analysis
1Ease of operation
If non-professionals manually learn SQL syntax to query databases, then they can perform database queries, but the learning difficulty and time requirement increase significantly
Solution Approach 1:
The patent introduces a natural language processing system as an intermediary between the user and the database query system. Instead of requiring users to directly write SQL syntax, the system translates natural language queries into structured query sentences automatically, eliminating the need for users to learn SQL while maintaining query functionality
Solution Approach 2:
The patent replaces the mechanical process of manually writing and debugging SQL syntax with an automated natural language processing system. The system uses sequence-to-sequence models and directed acyclic graphs to automatically convert natural language into executable queries, substituting manual mechanical typing and syntax construction with intelligent automated translation
2Ease of operation
If a pre-trained machine learning model directly converts natural language to structured query sentences, then the conversion process is simplified, but the accuracy of the generated queries decreases
Solution Approach 1:
The patent segments the query generation process into distinct stages: natural language input, action sequence generation via sequence-to-sequence model, directed acyclic graph construction, and structured query sentence generation. This segmentation allows each component to be optimized independently, improving overall accuracy while maintaining ease of operation
Solution Approach 2:
The patent introduces a directed acyclic graph as an intermediary structure between the sequence-to-sequence model output and the final structured query sentence. This intermediate representation captures the semantic relationships and query structure more accurately, serving as a bridge that improves precision without complicating the overall conversion process
Data Source
AI summary
Embodiments of the present disclosure provide a method and apparatus for outputting a structured query sentence. The method may include: acquiring a to-be-converted natural language sentence; inputting the to-be-converted natural language sentence into a pre-trained sequence to sequence model to obtain an action sequence corresponding to the to-be-converted natural language sentence; generating a directed acyclic graph according to the action sequence; and outputting a structured query sentence corresponding to the generated directed acyclic graph according to a preset corresponding relationship between a directed acyclic graph and a structured query sentence.


