Movatterモバイル変換


[0]ホーム

URL:


CN114090719A - AST-based abstract semantic parsing analysis method and device and electronic equipment - Google Patents

AST-based abstract semantic parsing analysis method and device and electronic equipment
Download PDF

Info

Publication number
CN114090719A
CN114090719ACN202111421833.1ACN202111421833ACN114090719ACN 114090719 ACN114090719 ACN 114090719ACN 202111421833 ACN202111421833 ACN 202111421833ACN 114090719 ACN114090719 ACN 114090719A
Authority
CN
China
Prior art keywords
ast
tree
sql
syntax
analysis method
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202111421833.1A
Other languages
Chinese (zh)
Inventor
蓝城
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Zhejiang Baiying Technology Co Ltd
Original Assignee
Zhejiang Baiying Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Zhejiang Baiying Technology Co LtdfiledCriticalZhejiang Baiying Technology Co Ltd
Priority to CN202111421833.1ApriorityCriticalpatent/CN114090719A/en
Publication of CN114090719ApublicationCriticalpatent/CN114090719A/en
Pendinglegal-statusCriticalCurrent

Links

Images

Classifications

Landscapes

Abstract

Translated fromChinese

本发明公开了一种基于AST的抽象语义拆解分析方法,所述方法包括:获取前端发送的查询请求;将所述查询请求中的select请求体封装成语法树;基于语法对应表解析所述语法树得到对应的SQL条件树;将所述SQL条件树拼接成对应的SQL语句。

Figure 202111421833

The invention discloses an AST-based abstract semantic disassembly and analysis method. The method includes: obtaining a query request sent by a front end; encapsulating a select request body in the query request into a syntax tree; parsing the query request based on a syntax correspondence table The syntax tree obtains a corresponding SQL condition tree; the SQL condition tree is spliced into a corresponding SQL statement.

Figure 202111421833

Description

AST-based abstract semantic parsing analysis method and device and electronic equipment
Technical Field
The application relates to the field of databases, in particular to an AST-based abstract semantic parsing analysis method and device and electronic equipment.
Background
At present, if multi-condition query of different business scenes needs to be carried out, developers need to write multi-condition query sentences in project codes, the work is long and tedious, and each business iteration needs to be manually modified.
Moreover, the current query can only realize the grammar query of a single data engine, and if a plurality of other data engines are added to a business, a developer needs to re-redundant a piece of similar code according to the new grammar.
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.
Drawings
Fig. 1 is a schematic flowchart illustrating an AST-based abstract semantic parsing analysis method according to an embodiment of the present application;
FIG. 2 is a flowchart illustrating a method for encapsulating select request bodies in query requests into syntax trees according to an embodiment of the present application;
fig. 3 is a schematic structural diagram of an AST-based abstract semantic parsing apparatus according to an embodiment of the present application;
fig. 4 is a schematic structural diagram of an electronic device according to an embodiment of the present application.
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.

Claims (7)

Translated fromChinese
1.一种基于AST的抽象语义拆解分析方法,其特征是,所述方法包括:1. an abstract semantic dismantling analysis method based on AST, is characterized in that, described method comprises:获取前端发送的查询请求;Get the query request sent by the front end;将所述查询请求中的select请求体封装成语法树;encapsulating the select request body in the query request into a syntax tree;基于语法对应表解析所述语法树得到对应的SQL条件树;Parse the syntax tree based on the syntax correspondence table to obtain a corresponding SQL condition tree;将所述SQL条件树拼接成对应的SQL语句。The SQL condition tree is spliced into corresponding SQL statements.2.根据权利要求1所述的一种基于AST的抽象语义拆解分析方法,其特征是,将所述查询请求中的select请求体封装成语法树包括:2. a kind of AST-based abstract semantic dismantling analysis method according to claim 1, is characterized in that, encapsulating the select request body in the described query request into a syntax tree comprises:获取所述查询请求中的select语句;Obtain the select statement in the query request;将所述select语句解析生成所述select请求体;Parse the select statement to generate the select request body;解析所述select请求体获得至少一个比较表达式,其中,所述至少一个比较Parse the select request body to obtain at least one comparison expression, wherein the at least one comparison表达式作为叶子节点得到所述语法树。Expressions get the syntax tree as leaf nodes.3.根据权利要求2所述的一种基于AST的抽象语义拆解分析方法,其特征是,3. a kind of abstract semantic dismantling analysis method based on AST according to claim 2, is characterized in that,基于语法对应表对所述语法树的每一个所述叶子节点进行解析,得到每一个Parse each of the leaf nodes of the syntax tree based on the syntax correspondence table, and obtain each所述叶子节点对应的SQL表达式,基于所述SQL表达式替换所述叶子节点的比较表达式得到所述SQL条件树。The SQL expression corresponding to the leaf node is obtained by replacing the comparison expression of the leaf node based on the SQL expression to obtain the SQL condition tree.4.根据权利要求1-3任一项所述的一种基于AST的抽象语义拆解分析方法,其4. a kind of AST-based abstract semantic disassembly analysis method according to any one of claims 1-3, its特征是,所述方法还包括:The feature is that the method further includes:将所述SQL语句发送至对应的数据库中进行查询获得查询结果,将所述查询The SQL statement is sent to the corresponding database for query to obtain query results, and the query结果返回至前端。The result is returned to the front end.5.一种基于AST的抽象语义拆解分析装置,其特征是,所述装置包括:5. A device for disassembling and analyzing abstract semantics based on AST, characterized in that the device comprises:第一获取单元,用于获取前端发送的查询请求;a first obtaining unit, used for obtaining the query request sent by the front end;第一封装单元,用于将所述查询请求中的select请求体封装成语法树;a first encapsulation unit, configured to encapsulate the select request body in the query request into a syntax tree;第一解析单元, 用于基于语法对应表解析所述语法树得到对应的SQL条件树;a first parsing unit, configured to parse the syntax tree based on the syntax correspondence table to obtain a corresponding SQL condition tree;第一拼接单元,用于将所述SQL条件树拼接成对应的SQL语句。The first splicing unit is used for splicing the SQL condition tree into corresponding SQL statements.6.一种电子设备,其特征是,所述电子设备包括处理器和存储器,所述存储6. An electronic device, characterized in that the electronic device comprises a processor and a memory, the storage器中存储有至少一条指令、至少一段程序、代码集或指令集,所述至少一条指令、所述至少一段程序、所述代码集或指令集由所述处理器执行以实现如权利要求1-4任一项所述的基于AST的抽象语义拆解分析方法。At least one instruction, at least one piece of program, code set or instruction set is stored in the processor, and the at least one instruction, the at least one piece of program, the code set or the instruction set are executed by the processor to implement the method as claimed in claim 1- 4. The AST-based abstract semantic disassembly analysis method described in any one.7.一种计算机可读存储介质,其特征是,所述计算机可读存储介质中存储有7. A computer-readable storage medium, wherein the computer-readable storage medium stores至少一条指令、至少一段程序、代码集或指令集,所述至少一条指令、所述至少一段程序、所述代码集或指令集由处理器执行以实现如权利要求1-4任一项所述的基于AST的抽象语义拆解分析方法。at least one instruction, at least one piece of program, code set or instruction set, said at least one instruction, said at least one piece of program, said code set or instruction set being executed by a processor to implement any one of claims 1-4 AST-based abstract semantic disassembly analysis method.
CN202111421833.1A2021-11-262021-11-26AST-based abstract semantic parsing analysis method and device and electronic equipmentPendingCN114090719A (en)

Priority Applications (1)

Application NumberPriority DateFiling DateTitle
CN202111421833.1ACN114090719A (en)2021-11-262021-11-26AST-based abstract semantic parsing analysis method and device and electronic equipment

Applications Claiming Priority (1)

Application NumberPriority DateFiling DateTitle
CN202111421833.1ACN114090719A (en)2021-11-262021-11-26AST-based abstract semantic parsing analysis method and device and electronic equipment

Publications (1)

Publication NumberPublication Date
CN114090719Atrue CN114090719A (en)2022-02-25

Family

ID=80305006

Family Applications (1)

Application NumberTitlePriority DateFiling Date
CN202111421833.1APendingCN114090719A (en)2021-11-262021-11-26AST-based abstract semantic parsing analysis method and device and electronic equipment

Country Status (1)

CountryLink
CN (1)CN114090719A (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication numberPriority datePublication dateAssigneeTitle
CN115051873A (en)*2022-07-272022-09-13深信服科技股份有限公司Network attack result detection method and device and computer readable storage medium

Citations (7)

* Cited by examiner, † Cited by third party
Publication numberPriority datePublication dateAssigneeTitle
CN101021874A (en)*2007-03-212007-08-22金蝶软件(中国)有限公司Method and apparatus for optimizing request to poll SQL
CN103761080A (en)*2013-12-252014-04-30中国农业大学Structured query language (SQL) based MapReduce operation generating method and system
CN104199831A (en)*2014-07-312014-12-10深圳市腾讯计算机系统有限公司Information processing method and device
CN110362597A (en)*2019-06-282019-10-22华为技术有限公司A kind of structured query language SQL injection detection method and device
CN111694846A (en)*2020-06-042020-09-22贵州易鲸捷信息技术有限公司Separate mode distributed storage process implementation method based on Type2 JDBC drive
CN112541002A (en)*2020-12-092021-03-23北京奇艺世纪科技有限公司Program language conversion method, device, electronic equipment and storage medium
US20210191934A1 (en)*2020-09-042021-06-24Beijing Baidu Netcom Science Technology Co., Ltd.Target data obtaining method and apparatus

Patent Citations (7)

* Cited by examiner, † Cited by third party
Publication numberPriority datePublication dateAssigneeTitle
CN101021874A (en)*2007-03-212007-08-22金蝶软件(中国)有限公司Method and apparatus for optimizing request to poll SQL
CN103761080A (en)*2013-12-252014-04-30中国农业大学Structured query language (SQL) based MapReduce operation generating method and system
CN104199831A (en)*2014-07-312014-12-10深圳市腾讯计算机系统有限公司Information processing method and device
CN110362597A (en)*2019-06-282019-10-22华为技术有限公司A kind of structured query language SQL injection detection method and device
CN111694846A (en)*2020-06-042020-09-22贵州易鲸捷信息技术有限公司Separate mode distributed storage process implementation method based on Type2 JDBC drive
US20210191934A1 (en)*2020-09-042021-06-24Beijing Baidu Netcom Science Technology Co., Ltd.Target data obtaining method and apparatus
CN112541002A (en)*2020-12-092021-03-23北京奇艺世纪科技有限公司Program language conversion method, device, electronic equipment and storage medium

Cited By (2)

* Cited by examiner, † Cited by third party
Publication numberPriority datePublication dateAssigneeTitle
CN115051873A (en)*2022-07-272022-09-13深信服科技股份有限公司Network attack result detection method and device and computer readable storage medium
CN115051873B (en)*2022-07-272024-02-23深信服科技股份有限公司Network attack result detection method, device and computer readable storage medium

Similar Documents

PublicationPublication DateTitle
CN109670053B (en) Data object mapping method, apparatus, device, and computer-readable storage medium
CN110704479A (en)Task processing method and device, electronic equipment and storage medium
CN108572819A (en) Page updating method, device, terminal and computer-readable storage medium
US11650901B2 (en)Automated generation of software patches
CN111459537A (en)Redundant code removing method, device, equipment and computer readable storage medium
CN114116268A (en)Method and device for checking Flink SQL statement, computer equipment and storage medium
CN112667287A (en)Method, device and equipment for creating rule file and computer readable storage medium
CN114281842A (en) A kind of method and device for database sub-table query
CN113901083A (en)Heterogeneous data source operation resource analysis positioning method and equipment based on multiple analyzers
CN114546381A (en) Front-end page code file generation method, device, electronic device and storage medium
CN112579151A (en)Method and device for generating model file
CN114090719A (en)AST-based abstract semantic parsing analysis method and device and electronic equipment
CN111796830B (en) A protocol parsing and processing method, device, equipment and medium
CN115878120A (en)Code generation method, device and storage medium
CN111723104B (en)Method, device and system for analyzing grammar in data processing system
CN115545006B (en) Rule script generation method, device, computer equipment and media
WO2017097125A1 (en)Executive code generation method and device
CN113377674B (en)Log code adding method and device
CN114115900B (en)Script compiling method and device and electronic equipment
CN116466955A (en)Routing table generation method, page jump method, device, equipment and medium
CN114968622A (en)Processor interface management method, device, equipment and storage medium
CN115113869A (en)Online webpage development method and device based on browser
CN114721748A (en)Data query method, system, equipment and readable storage medium
CN119512522B (en) Methods, systems, and cross-shard/cross-blockchain interaction methods, systems, terminals, and media supporting cross-shard/cross-blockchain calls
CN112052012B (en)XSLT and XSD-based code automatic generation method and equipment

Legal Events

DateCodeTitleDescription
PB01Publication
PB01Publication
SE01Entry into force of request for substantive examination
SE01Entry into force of request for substantive examination
RJ01Rejection of invention patent application after publication

Application publication date:20220225


[8]ページ先頭

©2009-2025 Movatter.jp