Disclosure of Invention
The technical problem to be solved by the embodiments of the present application is to provide an AST-based abstract semantic parsing method, an AST-based abstract semantic parsing apparatus, and an AST-based electronic device, so as to solve the technical problem that developers need to re-redundancy a similar code according to a new syntax when a plurality of other data engines are newly added to a service.
In order to achieve the above purpose, the embodiments of the present application adopt the following technical solutions:
in a first aspect, an embodiment of the present application provides an AST-based abstract semantic parsing analysis method, where the method includes:
acquiring a query request sent by a front end;
packaging a select request body in the query request into a syntax tree;
analyzing the syntax tree based on a syntax correspondence table to obtain a corresponding SQL condition tree;
and splicing the SQL condition trees into corresponding SQL sentences.
In a second aspect, an embodiment of the present application provides an AST-based abstract semantic parsing apparatus, where the apparatus includes:
the first acquisition unit is used for acquiring the query request sent by the front end;
the first packaging unit is used for packaging a select request body in the query request into a syntax tree;
the first parsing unit is used for parsing the syntax tree based on the syntax correspondence table to obtain a corresponding SQL condition tree;
and the first splicing unit is used for splicing the SQL condition tree into corresponding SQL sentences.
In a third aspect, an embodiment of the present application provides an electronic device, which includes a processor and a memory, where the memory stores at least one instruction, at least one program, a set of codes, or a set of instructions, and the at least one instruction, the at least one program, the set of codes, or the set of instructions is executed by the processor to implement the AST-based abstract semantic parsing method according to the first aspect.
In a fourth aspect, embodiments of the present application provide a computer-readable storage medium having at least one instruction, at least one program, a set of codes, or a set of instructions stored therein, which are executed by a processor to implement the AST-based abstract semantic parsing method according to the first aspect.
The beneficial effects of the embodiment of the application are that: the embodiment of the application provides an AST-based abstract semantic parsing method, an AST-based abstract semantic parsing device and electronic equipment, and the user-defined grammar, an abstract grammar tree and a semantic parsing engine are used for accurately integrating a request returned by a front end and packaging the request into a modular grammar packet, so that parameters returned by the front end can be parsed into a universal grammar under different users and different scenes, and the workload of developers is greatly reduced.
Detailed Description
The technical solutions of the present application are further described in detail with reference to the following specific embodiments, and it is obvious that the described embodiments are only a part of the embodiments of the present application, but not all of the embodiments. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present application.
The application provides an AST-based abstract semantic parsing analysis method, an AST-based abstract semantic parsing analysis device and electronic equipment, and aims to solve the technical problem that when a plurality of other data engines are newly added to a service, a developer needs to re-redundantly copy a similar code according to a new grammar.
The technical solutions provided by the embodiments of the present application are described in detail below with reference to the accompanying drawings.
Referring to fig. 1, a schematic flow chart of an AST-based abstract semantic parsing analysis method according to an embodiment of the present application is shown, where the method includes:
s101, acquiring a query request sent by a front end;
s102, encapsulating a select request body in the query request into a syntax tree;
s103, analyzing the syntax tree based on a syntax correspondence table to obtain a corresponding SQL condition tree;
s104, splicing the SQL condition trees into corresponding SQL sentences.
In an embodiment, please refer to fig. 2, which shows a flowchart illustrating a method for encapsulating select request bodies in a query request into a syntax tree according to an embodiment of the present application, including:
s201, obtaining a select statement in the query request;
s202, analyzing the select statement to generate a select request body;
s203, analyzing the select request body to obtain at least one comparison expression, wherein the at least one comparison expression is used as a leaf node to obtain the syntax tree.
In one embodiment, each leaf node of the syntax tree is analyzed based on a syntax correspondence table to obtain an SQL expression corresponding to each leaf node, and the SQL conditional tree is obtained by replacing the comparison expression of the leaf node based on the SQL expression.
In one embodiment, the method further comprises: and sending the SQL statement to a corresponding database for query to obtain a query result, and returning the query result to the front end.
Referring to fig. 3, a schematic structural diagram of an AST-based abstract semantic parsing apparatus according to an embodiment of the present application is shown, where the apparatus includes:
a first obtainingunit 301, configured to obtain an inquiry request sent by a front end;
a first encapsulatingunit 302, configured to encapsulate a select request body in the query request into a syntax tree;
afirst parsing unit 303, configured to parse the syntax tree based on the syntax correspondence table to obtain a corresponding SQL conditional tree;
afirst splicing unit 304, configured to splice the SQL conditional tree into corresponding SQL statements.
Referring to fig. 4, a schematic structural diagram of an electronic device according to an embodiment of the present application is shown, where the electronic device may include: at least onenetwork interface 402,memory 403, and at least oneprocessor 401. The various components in the electronic device are coupled together by abus system 404. It will be appreciated that thebus system 404 is used to enable communications among the components for connection. Thebus system 404 includes a power bus, a control bus, and a status signal bus in addition to a data bus, but for clarity of illustration, the various buses are labeled asbus system 404 in FIG. 4.
In some embodiments,memory 403 stores the following elements, executable modules or data structures, or a subset thereof, or an expanded set thereof: anoperating system 4031 and application programs 4032.
Theoperating system 4031 includes various system programs, such as a framework layer, a core library layer, a driver layer, and the like, and is used to implement various outgoing services and process hardware-based tasks. The application 4032 includes various applications, such as a Media Player (Media Player), a Browser (Browser), and the like, and is used to implement various application services. The program for implementing the method of the embodiment of the present application may be included in an application program.
In the above embodiment, the electronic device further includes: at least one instruction, at least one program, set of codes, or set of instructions stored on thememory 403 that is executable by theprocessor 401 to perform steps implementing any of the AST-based abstract semantic parsing methods described in embodiments of the present application.
In one embodiment, the present application further provides a computer-readable storage medium having at least one instruction, at least one program, a set of codes, or a set of instructions stored therein, which when executed by a processor, implement the steps of any of the AST-based abstract semantic parsing methods described in the embodiments of the present application.
It will be understood by those skilled in the art that all or part of the processes of the methods of the embodiments described above may be implemented by hardware instructions of a computer program, and that the at least one instruction, the at least one program, the code set, or the instruction set may be stored in a non-volatile computer-readable storage medium, and when executed, the at least one instruction, the at least one program, the code set, or the instruction set may implement the steps of any of the mapping methods described in the embodiments of the present application. Any reference to memory, storage, database, or other medium used in the embodiments provided herein may include non-volatile and/or volatile memory, among others. Non-volatile memory can include read-only memory (ROM), Programmable ROM (PROM), Electrically Programmable ROM (EPROM), Electrically Erasable Programmable ROM (EEPROM), or flash memory. Volatile memory can include Random Access Memory (RAM) or external cache memory. By way of illustration and not limitation, RAM is available in a variety of forms such as Static RAM (SRAM), Dynamic RAM (DRAM), Synchronous DRAM (SDRAM), Double Data Rate SDRAM (DDRSDRAM), Enhanced SDRAM (ESDRAM), Synchronous Link DRAM (SLDRAM), Rambus Direct RAM (RDRAM), direct bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM).
The embodiments of the present application have been described above with reference to the accompanying drawings, but the present application is not limited to the above-described embodiments, which are only illustrative and not restrictive; meanwhile, for a person skilled in the art, according to the idea of the present application, there may be variations in the specific embodiments and the application scope, which are within the protection scope of the present application.