A syntax conversion method, apparatus, device, and computer-readable storage medium
By generating feature codes in database syntax conversion and using the target large language model for syntax conversion, the problems of high cost and low efficiency in addition to conversion rules in the prior art are solved, and a more flexible and efficient syntax conversion process is achieved.
Patent Information
- Application Number
- CN202411616526.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-13
- Publication Date
- 2025-04-18
- Estimated Expiration
- 2044-11-13
AI Technical Summary
When performing database syntax compatibility conversion, adding new conversion rules requires modifying and publishing new syntax conversion tool code, resulting in increased costs and reduced efficiency.
By generating the characteristic code of the statement to be converted and syntax conversion using the target large language model, a statement with the target database syntax is generated. The uniqueness of the feature code and the training of large language models make the update of conversion rules more flexible and efficient.
It avoids frequent modifications to the code of the syntax conversion tool, reduces the cost of adding new syntax conversion rules, and improves the efficiency of syntax conversion by introducing a syntax summary list.
Smart Images

Figure CN119179492B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of information technology, and in particular to a grammar conversion method, device, equipment and computer-readable storage medium. Background Art
[0002] Database syntax compatibility conversion is a very common requirement; when performing database migration, statements that work in the original database syntax need to be converted to the target database syntax; usually, the related technology usually uses syntax conversion tools (such as Ora2Pg) that require continuous code writing, compilation and release to perform syntax conversion; however, during the implementation process, the inventors found that there are at least the following problems in the prior art: when performing syntax conversion, once new conversion rules need to be added, the existing code of the syntax conversion tool must be modified and a new version must be released, thereby increasing the cost of syntax conversion and reducing the efficiency of syntax conversion. Summary of the invention
[0003] To solve the above technical problems, the embodiments of the present application hope to provide a grammar conversion method, apparatus, device and computer-readable storage medium, which solves the problem that the prior art increases the cost of grammar conversion and reduces the efficiency of grammar conversion.
[0004] The technical solution of this application is implemented as follows:
[0005] Obtaining a statement to be converted having a first database grammar;
[0006] Based on the sentence to be converted, generating a feature code corresponding to the sentence to be converted; wherein the feature code is unique;
[0007] If the feature code is not included in the initial summary list, a target large language model is used to perform grammatical conversion on the sentence to be converted to generate a target sentence with a second database grammar; wherein the target natural language model is obtained by training the initial large language model using sample data.
[0008] In the above solution, the step of generating a feature code corresponding to the sentence to be converted based on the sentence to be converted includes:
[0009] Based on the sentence to be converted and the placeholder, generate a first grammatical summary corresponding to the sentence to be converted;
[0010] The first grammatical summary is converted using a hash algorithm to obtain the feature code.
[0011] In the above solution, generating a first grammatical summary corresponding to the statement to be converted based on the statement to be converted and the placeholder includes:
[0012] Performing grammatical analysis on the statement to be converted by a first grammatical analyzer to determine a first constant in the statement to be converted;
[0013] The first syntax summary is generated based on the placeholder, the first constant, and the statement to be converted.
[0014] In the above scheme, after the target large language model is used to perform grammar conversion on the sentence to be converted to generate a target sentence with the grammar of the second database, the method further includes:
[0015] Performing grammatical parsing on the target sentence by a second grammatical parser to determine a second constant in the target sentence;
[0016] Based on the placeholder, the second constant, and the target sentence, a second grammatical digest corresponding to the target sentence is determined.
[0017] In the above scheme, the method further includes:
[0018] Based on the first grammatical digest, the feature code and the second grammatical digest, establishing a target correspondence relationship between the first grammatical digest and the second grammatical digest;
[0019] The target correspondence is stored in the initial summary list, a target summary list is obtained, and the target sentence is returned.
[0020] In the above scheme, the method further includes:
[0021] If the feature code is in the initial summary list, obtaining a second grammatical summary from the initial summary list based on the feature code and a preset correspondence in the initial summary list; wherein the preset correspondence represents a relationship between the grammatical summary of the first database and the grammatical summary of the second database;
[0022] The target sentence is generated based on the sentence to be converted and the second grammar summary, and the target sentence is returned.
[0023] In the above solution, generating the target sentence based on the sentence to be converted and the second grammar summary includes:
[0024] The first constant in the statement to be converted is used to replace the placeholder in the second grammar summary to generate the target statement.
[0025] A grammar conversion device, comprising:
[0026] An acquisition unit, used for acquiring a statement to be converted having a first database grammar;
[0027] A processing unit, configured to generate a feature code corresponding to the sentence to be converted based on the sentence to be converted; wherein the feature code is unique;
[0028] A generating unit is used for, if the initial summary list does not contain the feature code, using a target large language model to perform grammatical conversion on the sentence to be converted, so as to generate a target sentence with a second database grammar; wherein the target natural language model is obtained by training the initial large language model using sample data.
[0029] A grammar conversion device, the device comprising: a processor, a memory and a communication bus;
[0030] The communication bus is used to realize the communication connection between the processor and the memory;
[0031] The processor is used to execute the grammar conversion program in the memory to implement the steps of the above-mentioned grammar conversion method.
[0032] A computer-readable storage medium stores one or more programs, and the one or more programs can be executed by one or more processors to implement the steps of the above-mentioned grammar conversion method.
[0033] Because after obtaining the sentence to be converted with the grammar of the first database, a feature code corresponding to the sentence to be converted can be generated based on the sentence to be converted, and the feature code is unique. Then, if the feature code is not in the initial summary list, the target large language model is used to perform grammatical conversion on the sentence to be converted to generate a target sentence with the grammar of the second database, and the target natural language model is obtained by training the initial large language model with sample data; in this way, when performing grammatical conversion on the sentence to be converted, the target large language model is used for conversion, that is, the trained artificial intelligence model is used for conversion. When new conversion rules need to be added, it is only necessary to continuously upgrade and train the artificial intelligence model, thereby avoiding the problem of modifying the code of the conversion tool as in the related art, thereby reducing the cost of adding new grammatical conversion rules, and by introducing the grammatical summary list, the efficiency of grammatical conversion is improved, overcoming the problem of increasing the cost of grammatical conversion and reducing the efficiency of grammatical conversion in the prior art. BRIEF DESCRIPTION OF THE DRAWINGS
[0034] Figure 1 A schematic diagram of an off-line grammar conversion method in the related art;
[0035] Figure 2 A schematic diagram of an online grammar conversion method in the related art;
[0036] Figure 3A flowchart of a grammar conversion method provided in an embodiment of the present application;
[0037] Figure 4 A schematic diagram for comparing different grammar conversion methods in a grammar conversion method in the related art;
[0038] Figure 5 A flowchart of another syntax conversion method provided in an embodiment of the present application;
[0039] Figure 6 Another flowchart of another syntax conversion method provided in an embodiment of the present application;
[0040] Figure 7 Another schematic diagram of another grammar conversion method provided in an embodiment of the present application;
[0041] Figure 8 A schematic diagram of the structure of a grammar conversion device provided in an embodiment of the present application;
[0042] Fig. 9 A schematic diagram of the structure of a grammar conversion device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0043] The technical solutions in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application.
[0044] It should be understood that the "embodiments of the present application" or "the aforementioned embodiments" mentioned throughout the specification mean that specific features, structures or characteristics related to the embodiments are included in at least one embodiment of the present application. Therefore, "in the embodiments of the present application" or "in the aforementioned embodiments" appearing throughout the specification may not necessarily refer to the same embodiment. In addition, these specific features, structures or characteristics may be combined in one or more embodiments in any suitable manner. In the various embodiments of the present application, the size of the sequence numbers of the above-mentioned processes does not mean the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of the present application. The above-mentioned sequence numbers of the embodiments of the present application are for description only and do not represent the advantages and disadvantages of the embodiments.
[0045] Unless otherwise specified, the electronic device performs any step in the embodiments of the present application, and the processor of the electronic device may perform the step. It is also worth noting that the embodiments of the present application do not limit the order in which the electronic device performs the following steps. In addition, the methods used to process data in different embodiments may be the same method or different methods. It should also be noted that any step in the embodiments of the present application can be independently executed by the electronic device, that is, when the electronic device executes any step in the following embodiments, it may not rely on the execution of other steps.
[0046] It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.
[0047] It should be noted that database syntax compatibility conversion includes offline conversion and online conversion. For offline conversion, the so-called "offline" means collecting all business structured query languages (SQL) and converting the incompatible parts from the original database dialect to the target database dialect. In order to improve the efficiency of conversion operations and reduce the workload and error probability of manual intervention, many automatic syntax conversion tools (i.e., offline conversion tools) have been developed, such as Figure 1 As shown in the figure, the offline conversion tool (i.e., SQL convert tool) converts the original database syntax (i.e., SourceSQL statements) into the target database syntax (i.e., Target SQL statements). After the conversion is completed, the converted syntax is used to modify the business. The above offline conversion has obvious disadvantages. The business code needs to be modified during business migration. In addition, since the developers and DBAs of the original business system may have worked on the original database for a long time and are not very familiar with the target database syntax, they may need to rely on SQL conversion tools for a period of time in the subsequent business development process. Therefore, some database manufacturers will also develop Figure 2 The client and database driver with online syntax conversion capabilities are shown in Figure 1. Figure 2As shown, it can implement a simulation driver compatible with the original database (i.e. Source database JDBCemulator), and encapsulate the SQL converter (i.e. SQL converter) and the driver of the target database (JDBC of target database) in this driver. When the business system (i.e. Application based on Source database) sends the original SQL (i.e. Source SQL) to the simulation driver, the SQL converter converts it into the target database syntax (i.e. Target SQL statements) online and forwards it to the driver of the target database, and then the driver of the target database forwards it to the target database (i.e. Target database). In addition, the simulation client compatible with the original database is similar, that is, a SQL converter and a client library of the target database are encapsulated in the simulation client. In summary, the use of offline migration tools requires changing the development habits of original business developers and modifying existing businesses. Although online conversion solutions can effectively control intrusion into businesses, traditional converters often require continuous code writing, compilation, and release. For example, the open source database migration tool Ora2Pg released its first version in 2001 and has accumulated tens of thousands of lines of code (such as the Perl programming language). However, it still encounters many unsupported syntaxes, and once new conversion rules need to be added, the existing code of Ora2Pg must be modified and a new version released.
[0048] Based on this, the embodiment of the present application provides a grammar conversion method, which can be applied to a grammar conversion device, referring to Figure 3 As shown, the method comprises the following steps:
[0049] Step 101: Obtain a statement to be converted having a first database grammar.
[0050] In an embodiment of the present application, the first database grammar may refer to the grammar of the original database, that is, the grammar of the database that needs to be converted; the statement to be converted may refer to the statement in the first database grammar, which is also the statement that needs to be converted into the grammar of other databases; the grammar conversion device may receive the statement to be converted having the first database grammar through the converter.
[0051] In a feasible implementation, the first database may refer to an Oracle database, and the second database may refer to a PostgreSQL database; the statement to be converted may be an SQL statement or an anonymous block; the first database syntax may include an SQL statement and a PL / SQL statement; when the statement to be converted is an SQL statement, the statement to be converted may specifically be SELECT id, client_id FORM customer WHERE rownum<=100 AND creat_time <TO_DATE(‘20240101’,‘YYYYMMDD’)ORDER BY create_time DESC。
[0052] Step 102: Generate a feature code corresponding to the sentence to be converted based on the sentence to be converted.
[0053] Among them, the feature code is unique.
[0054] In the embodiment of the present application, the feature code may specifically be a hash value of a grammatical summary; a grammatical parser may be used to analyze the statement to be converted to generate a grammatical summary corresponding to the statement to be converted, and then the grammatical summary corresponding to the conversion statement may be converted to obtain the feature code.
[0055] Step 103: If the initial summary list does not contain the feature code, use the target large language model to perform grammar conversion on the sentence to be converted to generate a target sentence with the second database grammar.
[0056] The target natural language model is obtained by training the initial large language model using sample data.
[0057] In an embodiment of the present application, the initial summary list may refer to a preset summary list, and the initial summary list has multiple preset corresponding relationships, and each preset corresponding relationship may characterize the relationship between the grammatical summary of the first database and the grammatical summary of the second database; the second database grammar may refer to the grammar of the target database to which the original database grammar is to be converted; the target sentence may refer to the sentence of the second database grammar, which is also the sentence obtained after the sentence to be converted is grammatically converted through a large language model; Large Language Models (LLMs) is an artificial intelligence model trained with a large amount of data, which aims to understand and generate natural language text; the converter can be connected to the target large language model through application programming interfaces (APIs) to achieve grammatical compatibility conversion.
[0058] In an embodiment of the present application, sample data can be first input into an initial large language model for model training to obtain a target large language model, and then the sentence to be converted is input into the trained target large language model for grammatical conversion to generate a target sentence with the grammar of the second database; it should be noted that the large language model is a branch of generative artificial intelligence (Generative AI) technology, and the basic principle of generative artificial intelligence is to simulate human creativity by learning a large amount of data to generate new, unique and original content. Its learning process mainly relies on deep learning algorithms, especially neural networks. By training these neural networks, the inherent laws and characteristics of the data can be gradually learned, thereby generating new content similar to the training data.
[0059] It should be noted that with the development of generative artificial intelligence technology, large language models (LLMs: Large Language Models) have been widely used. Large language models can not only understand and generate natural language, but also process SQL syntax. Therefore, there is a way to achieve the syntax conversion of conversion statements. Figure 4 The new path shown in Figure 4 The dotted path from the statement to be converted to the target statement shown in FIG. 1 represents a traditional syntax conversion program, that is, the conversion rules are implemented through a programming language, that is, a problem of converting domain-specific languages (DSL) through programming is solved (SQL belongs to DSL); Figure 4 The solid line path from the sentence to be converted to the target sentence is the path implemented by the natural language processing model, that is, the sentence to be converted is input into the trained natural language processing model, and then the natural language processing model directly outputs the target sentence. When the conversion fails, the natural language processing model can be continuously fed back by manually annotating or correcting and supplementing the training set. In this way, a traditional programming conversion DSL problem can be replaced by a natural language processing (NLP) problem. It should be noted that DSL is a language that abstracts operations and concepts in a specific field to solve problems in a specific field. Its basic idea is "specialization rather than perfection". Unlike general-purpose languages, which cover all software problems, DSL is a computer language specifically designed for a specific problem, such as SQL and regular expressions.
[0060] In a feasible implementation, when the first database syntax can include SQL statements, the second database syntax can include SQL statements; when the first database syntax can include PL / SQL statements, the second database syntax can include PL / pgSQL statements; when the statement to be converted is SELECT id, client_id FORM customer WHERE rownum<=100 AND creat_time<TO_DATE('20240101', 'YYYYMMDD') ORDER BY create_time DESC, the target statement can be SELECT id, client_id FORM customer WHERE creat_time<TO_DATE('20240101', 'YYYYMMDD') ORDER BY create_time DESC LIMIT 100.
[0061] When performing syntax conversion on the statement to be converted, the syntax conversion method provided by the embodiments of the present application uses a target large language model for conversion, that is, a trained artificial intelligence model is used for conversion. When new conversion rules need to be added, it is only necessary to continuously upgrade and train the artificial intelligence model, avoiding the problem of modifying the code of the conversion tool as in the related art, thereby reducing the cost of adding new syntax conversion rules, and improving the efficiency of syntax conversion by introducing a syntax summary list, overcoming the problems of increasing the cost of syntax conversion and reducing the efficiency of syntax conversion in the prior art.
[0062] Based on the foregoing embodiments, the embodiments of the present application provide a syntax conversion method, as shown in Figure 5 and Figure 6 shown, the method includes the following steps:
[0063] Step 201, the syntax conversion device obtains the statement to be converted with the first database syntax.
[0064] Step 202, the syntax conversion device generates a first syntax summary corresponding to the statement to be converted based on the statement to be converted and the placeholder.
[0065] In the embodiments of the present application, the statement to be converted can be parsed first, and then the first syntax summary (i.e., DIGEST_TEXT) can be generated according to the parsed statement and the placeholder, and the essence of the first syntax summary is the summary string.
[0066] It should be noted that step 202 can be implemented in the following manner:
[0067] Step 202A1: The syntax conversion device performs syntax analysis on the statement to be converted by using a first syntax parser to determine a first constant in the statement to be converted.
[0068] The grammar conversion device is provided with a converter, and the converter may be provided with a first grammar parser (i.e., Figure 7 SQL parser of Grammar A shown); the first grammar parser may refer to a parser that performs grammar parsing on the statement to be converted; the first constant may refer to a constant value in the statement to be converted, and there may be one or more constants in the statement to be converted, and the first constant may include a value and a string, and may also include other data types, such as a date, a collection, etc.
[0069] In the embodiment of the present application, the sentence to be converted can be input into the first grammar parser to obtain the grammar structure tree corresponding to the sentence to be converted (i.e., Figure 7 The first syntax parser can be a parser and compiler (Another Tool for Language Recognition, Antlr), which is an open source syntax analyzer generator that provides developers with an efficient and reliable way to process structured text or binary files.
[0070] Step 202A2: The grammar conversion device generates a first grammar summary based on the placeholder, the first constant, and the statement to be converted.
[0071] In the embodiment of the present application, the converter may also be provided with a summary generator (i.e. Figure 7 ), the digest generator can use a placeholder to replace the first constant in the statement to be converted to obtain a first syntax digest, and the placeholder is related to the constant value, and "$N" (N is a natural number that increases in sequence) can be used as a placeholder to represent different constants. Then, when there are two first constants in the statement to be converted, the first first constant can be replaced by "$1" and the second first constant can be replaced by "$2". "?" can also be used as a placeholder to represent different constants. Then, when there are two first constants in the statement to be converted, both first constants can be replaced by "?".
[0072] Step 203: The syntax conversion device converts the first syntax summary using a hash algorithm to obtain a feature code.
[0073] Among them, the feature code is unique.
[0074] In an embodiment of the present application, the hash algorithm is a unique hash algorithm; after obtaining the first syntax digest, a hash algorithm (such as a secure hash algorithm, SHA256) can also be used to convert the first syntax digest to obtain a hash value (i.e., a feature code, DIGEST_HASH). Since the SHA265 algorithm is unique, the HASH values of two identical syntax digests are also the same (i.e., the feature codes are the same), which can optimize the efficiency of searching the initial summary list.
[0075] It should be noted that SHA256 belongs to the Secure Hash Algorithm 2 (SHA-2) family, designed by the National Security Agency (NSA) and released by the National Institute of Standards and Technology (NIST). SHA256 always generates a 256-bit hash value and has strong collision resistance.
[0076] It should be noted that steps 204 to 208 may be performed after step 203, and steps 209 to 210 may also be performed after step 203;
[0077] It should be noted that compared with the traditional DSL conversion program solution, the efficiency of the large language model syntax conversion is very low and is not suitable for application in the online conversion scenario. For a stored procedure, only one conversion is required when it is created; after the stored procedure is created on the second database, it is stored on the server side of the second database in the syntax of the second database. Therefore, there is no need to convert again when calling this procedure subsequently. The performance impact of the conversion through the large language model only exists in the stage of creating the stored procedure and is within an acceptable range. However, for the statement to be converted, it must be converted again every time it is executed, and the bottleneck of the conversion performance through the large language model becomes very prominent. Therefore, in order to solve the performance problem caused by the syntax conversion of artificial intelligence (AI), a syntax parser and summary generator module can be introduced in the converter. By storing the corresponding relationship between the syntax summary of the first database and the syntax summary of the second database, the conversion operation of the statement to be converted is accelerated. The specific steps are as follows: Step 204 to Step 208:
[0078] Step 204: If the initial summary list does not contain the feature code, the grammar conversion device uses the target large language model to perform grammar conversion on the sentence to be converted, and generates a target sentence with the second database grammar.
[0079] The target natural language model is obtained by training the initial large language model using sample data.
[0080] Step 205: The grammar conversion device performs grammar analysis on the target sentence through a second grammar analyzer to determine a second constant in the target sentence.
[0081] Among them, a second syntax parser can be set in the converter (i.e. Figure 7 The second grammar parser may refer to a parser that performs grammatical parsing on the target statement; the second constant may refer to a constant value in the target statement, and the target statement may also have one or more constants, and the second constant may include a value, a string, and other data types.
[0082] In the embodiment of the present application, the target sentence can be input into the second grammar parser to obtain the grammar structure tree corresponding to the target sentence (ie, Figure 7 The Parse Trees shown in FIG. 1 are then used to traverse the grammar tree corresponding to the target sentence to identify a constant node (ie, a second constant) in the grammar tree.
[0083] Step 206: The grammar conversion device determines a second grammar summary corresponding to the target sentence based on the placeholder, the second constant, and the target sentence.
[0084] In the embodiment of the present application, Figure 7 The summary generator shown replaces the second constant in the target sentence with a placeholder to obtain a second grammatical summary (ie, TARGET_DIGEST_TEXT).
[0085] It should be noted that the summary generator can convert constants in statements into placeholders (such as "?"). In this way, the syntax summary of the same type of statements to be converted (i.e., only the constant part is different) is also the same, which is convenient for classification audit and performance analysis of the statements to be converted. For example, when the statement to be converted is SELECT*FROM mytable WHERE cola =10 AND colb=20, the DIGEST_HASH (i.e., STATEMENT_DIGEST) generated by the summary generator is: 3bb95eeade896657c4526e74ff2a2862039d0a0fe8a9e7155b5fe492cbd78387, and the TARGET_DIGEST_TEXT (i.e., STATEMENT_DIGEST_TEXT) generated by the summary generator is: SELECT*FROM mytableWHERE cola =? AND colb=?.
[0086] It should be noted that the digest generator includes two interfaces, DIGEST_HASH and TARGET_DIGEST_TEXT. On the one hand, it can convert any SQL statement into a digest format; on the other hand, it provides a method to convert a digest into a HASH value (in SHA265 format). By utilizing the uniqueness of the SHA265 algorithm, the HASH values of two identical SQL digests are also the same, which can optimize the search efficiency of the digest list.
[0087] Step 207: The grammar conversion device establishes a target correspondence relationship between the first grammar summary and the second grammar summary based on the first grammar summary, the feature code, and the second grammar summary.
[0088] In the embodiment of the present application, a key-value pair between a feature code and a first grammatical digest and a second grammatical digest can be constructed. Specifically, the feature code can be used as a key (Key), and the first grammatical digest and the second grammatical digest can be used as a value (Value), thereby establishing a target correspondence relationship (i.e., a key-value pair) as shown in [key: DIGEST_HASH->{DIGEST_TEXT, TARGET_DIGEST_TEXT}], specifically as Figure 7 shown.
[0089] Step 208: The syntax conversion device stores the target correspondence relationship in the initial summary list to obtain a target summary list.
[0090] In the embodiment of the present application, the target summary list is a summary list obtained after the initial summary list is updated; by saving the above-mentioned target correspondence in the initial summary list, the initial summary list can be updated, thereby speeding up the conversion process of the statement to be converted.
[0091] It should be noted that step 211 may be executed after step 208 .
[0092] Step 209: If the initial summary list contains a feature code, the syntax conversion device obtains a second syntax summary from the initial summary list based on a preset correspondence between the feature code and the initial summary list.
[0093] The preset corresponding relationship represents the relationship between the grammatical summary of the first database and the grammatical summary of the second database.
[0094] Step 210: The grammar conversion device generates a target sentence based on the sentence to be converted and the second grammar summary.
[0095] It should be noted that step 211 may also be performed after step 210, and step 210 may be implemented in the following manner:
[0096] Step 210B: The grammar conversion device uses the first constant in the sentence to be converted to replace the placeholder in the second grammar summary to generate a target sentence.
[0097] In an embodiment of the present application, when the syntax conversion device receives a sentence to be converted through the converter, it first inputs it into the first syntax parser to generate the DIGEST_TEXT and DIGEST_HASH of the sentence to be converted respectively; then, the DIGEST_HASH corresponding to the sentence to be converted is used to search in the initial summary list, and if it is hit (there is a feature code in the initial summary list), the preset corresponding relationship is obtained based on DIGEST_HASH, and then TARGET_DIGEST_TEXT is obtained from the preset corresponding relationship, and then the first constant in the sentence to be converted is used to replace the corresponding placeholder in TARGET_DIGEST_TEXT to directly generate the target sentence. Only when the record corresponding to the sentence to be converted cannot be searched in the initial summary list, it is necessary to execute the above steps 204 to 208, that is, to generate the target sentence through AI, and add a new record to the initial summary list to obtain the target summary list. In this way, for the same type of sentences to be converted, it is only necessary to use the large language model for conversion during the first conversion, and the subsequent conversion processes are all based on grammatical summary replacement, which solves the performance problem of AI grammar conversion and achieves conversion efficiency similar to that of traditional DSL conversion programs, meeting the performance requirements of online conversion strategies.
[0098] Step 211: The grammar conversion device returns the target sentence.
[0099] It should be noted that the present application can implement online conversion of database clients or database drivers without modifying the business or changing client operating habits; when it is necessary to add or improve SQL conversion rules, there is no need to modify the code and republish the client library or database driver, only manual feedback on the training set of the AI large language model and iterative training are required; while having the above capabilities, the SQL conversion performance is also close to the traditional DSL conversion program mode, meeting commercial requirements.
[0100] It should be noted that, for the description of the same steps and the same contents in this embodiment as those in other embodiments, reference can be made to the description in other embodiments and will not be repeated here.
[0101] The grammar conversion method provided in the embodiment of the present application uses a target large language model for conversion when performing grammar conversion on the conversion sentence, that is, a trained artificial intelligence model is used for conversion. When new conversion rules need to be added, it is sufficient to continuously upgrade and train the artificial intelligence model, thereby avoiding the problem of modifying the code of the conversion tool as in the related art, thereby reducing the cost of adding new grammar conversion rules, and improving the efficiency of grammar conversion by introducing a grammar summary list, thereby overcoming the problem of increasing the cost of grammar conversion and reducing the efficiency of grammar conversion in the prior art.
[0102] Based on the above embodiments, the present invention provides a grammar conversion device, which can be applied to Figure 3 and Figure 5 In the grammar conversion method provided in the corresponding embodiment, refer to Figure 8 As shown, the grammar conversion device 3 may include: an acquisition unit 31, a processing unit 32 and a generation unit 33, wherein:
[0103] An acquisition unit 31 is used to acquire a statement to be converted having a first database grammar;
[0104] The processing unit 32 is used to generate a feature code corresponding to the sentence to be converted based on the sentence to be converted; wherein the feature code is unique;
[0105] The generating unit 33 is used for performing grammatical conversion on the sentence to be converted by using the target large language model to generate a target sentence with the grammar of the second database if the initial summary list does not contain the feature code; wherein the target natural language model is obtained by training the initial large language model by using the sample data.
[0106] In other embodiments of the present application, the processing unit 32 is specifically configured to perform the following steps:
[0107] Based on the sentence to be converted and the placeholder, generate a first grammatical summary corresponding to the sentence to be converted;
[0108] The first grammatical summary is converted using a hash algorithm to obtain a feature code.
[0109] In other embodiments of the present application, the processing unit 32 is specifically configured to perform the following steps:
[0110] Performing syntax analysis on the statement to be converted by a first syntax analyzer to determine a first constant in the statement to be converted;
[0111] A first syntax summary is generated based on the placeholder, the first constant, and the statement to be converted.
[0112] In other embodiments of the present application, the processing unit 32 is specifically configured to perform the following steps:
[0113] Parsing the target sentence by a second grammar parser to determine a second constant in the target sentence;
[0114] Based on the placeholder, the second constant, and the target sentence, a second grammatical digest corresponding to the target sentence is determined.
[0115] In other embodiments of the present application, the processing unit 32 is specifically configured to perform the following steps:
[0116] Based on the first grammatical summary, the feature code and the second grammatical summary, establishing a target correspondence relationship between the first grammatical summary and the second grammatical summary;
[0117] Store the target correspondence in the initial summary list, obtain the target summary list, and return the target statement.
[0118] In other embodiments of the present application, the processing unit 32 is specifically configured to perform the following steps:
[0119] If the initial summary list contains a feature code, obtaining a second grammatical summary from the initial summary list based on the feature code and a preset correspondence relationship in the initial summary list; wherein the preset correspondence relationship represents a relationship between the grammatical summary of the first database and the grammatical summary of the second database;
[0120] A target sentence is generated based on the sentence to be converted and the second grammar summary, and the target sentence is returned.
[0121] In other embodiments of the present application, the processing unit 32 is specifically configured to perform the following steps:
[0122] The first constant in the statement to be converted is used to replace the placeholder in the second grammar summary to generate a target statement.
[0123] It should be noted that the specific description of the steps performed by each unit can be found in Figure 3 and Figure 5 The syntax conversion method provided in the corresponding embodiment will not be described again here.
[0124] The grammar conversion device provided in the embodiment of the present application uses a target large language model to perform conversion on the sentence to be converted, that is, a trained artificial intelligence model is used for conversion. When new conversion rules need to be added, it is sufficient to continuously upgrade and train the artificial intelligence model, thereby avoiding the problem of modifying the code of the conversion tool as in the related art, thereby reducing the cost of adding new grammar conversion rules, and improving the efficiency of grammar conversion by introducing a grammar summary list, thereby overcoming the problem of increasing the cost of grammar conversion and reducing the efficiency of grammar conversion in the prior art.
[0125] Based on the above embodiments, the embodiments of the present application provide a grammar conversion device, which can be applied to Figure 3 and Figure 5 In the grammar conversion method provided in the corresponding embodiment, refer to Fig. 9 As shown, the grammar conversion device 4 may include: a processor 41, a memory 42 and a communication bus 43, wherein:
[0126] The communication bus 43 is used to realize the communication connection between the processor 41 and the memory 42;
[0127] The processor 41 is used to execute the syntax conversion program in the memory 42 to implement the following steps:
[0128] Obtaining a statement to be converted having a first database grammar;
[0129] Based on the sentence to be converted, generating a feature code corresponding to the sentence to be converted; wherein the feature code is unique;
[0130] If the initial summary list does not contain the feature code, the target large language model is used to perform grammatical conversion on the sentence to be converted to generate a target sentence with the grammar of the second database; wherein the target natural language model is obtained by training the initial large language model using sample data.
[0131] In other embodiments of the present application, the processor 41 is used to execute the grammar conversion program in the memory 42 to generate a feature code corresponding to the sentence to be converted based on the sentence to be converted, so as to implement the following steps:
[0132] Based on the sentence to be converted and the placeholder, generate a first grammatical summary corresponding to the sentence to be converted;
[0133] The first grammatical summary is converted using a hash algorithm to obtain a feature code.
[0134] In other embodiments of the present application, the processor 41 is used to execute the syntax conversion program in the memory 42 to generate a first syntax summary corresponding to the sentence to be converted based on the sentence to be converted and the placeholder, so as to implement the following steps:
[0135] Performing syntax analysis on the statement to be converted by a first syntax analyzer to determine a first constant in the statement to be converted;
[0136] A first syntax summary is generated based on the placeholder, the first constant, and the statement to be converted.
[0137] In other embodiments of the present application, the processor 41 is used to execute the syntax conversion method of the syntax conversion program in the memory 42 to implement the following steps:
[0138] Parsing the target sentence by a second grammar parser to determine a second constant in the target sentence;
[0139] Based on the placeholder, the second constant, and the target sentence, a second grammatical digest corresponding to the target sentence is determined.
[0140] In other embodiments of the present application, the processor 41 is used to execute the syntax conversion method of the syntax conversion program in the memory 42 to implement the following steps:
[0141] Based on the first grammatical summary, the feature code and the second grammatical summary, establishing a target correspondence relationship between the first grammatical summary and the second grammatical summary;
[0142] Store the target correspondence in the initial summary list, obtain the target summary list, and return the target statement.
[0143] In other embodiments of the present application, the processor 41 is used to execute the syntax conversion method of the syntax conversion program in the memory 42 to implement the following steps:
[0144] If the initial summary list contains a feature code, obtaining a second grammatical summary from the initial summary list based on the feature code and a preset correspondence relationship in the initial summary list; wherein the preset correspondence relationship represents a relationship between the grammatical summary of the first database and the grammatical summary of the second database;
[0145] A target sentence is generated based on the sentence to be converted and the second grammar summary, and the target sentence is returned.
[0146] In other embodiments of the present application, the processor 41 is used to execute the grammar conversion program in the memory 42 to generate a target sentence based on the sentence to be converted and the second grammar summary, so as to implement the following steps:
[0147] The first constant in the statement to be converted is used to replace the placeholder in the second grammar summary to generate a target statement.
[0148] It should be noted that the specific description of the steps executed by the processor can be referred to Figure 3 and Figure 5 The syntax conversion method provided in the corresponding embodiment will not be described again here.
[0149] The grammar conversion device provided in the embodiment of the present application uses a target large language model for conversion when performing grammar conversion on the conversion statement, that is, a trained artificial intelligence model is used for conversion. When new conversion rules need to be added, it is sufficient to continuously upgrade and train the artificial intelligence model, thereby avoiding the problem of modifying the code of the conversion tool as in the related art, thereby reducing the cost of adding new grammar conversion rules, and improving the efficiency of grammar conversion by introducing a grammar summary list, thereby overcoming the problem of increasing the cost of grammar conversion and reducing the efficiency of grammar conversion in the prior art.
[0150] Based on the foregoing embodiments, the embodiments of the present application provide a computer-readable storage medium, which stores one or more programs, and the one or more programs can be executed by one or more processors to implement Figure 3 and Figure 5 The corresponding embodiments provide steps of the grammar conversion method.
[0151] Those skilled in the art will appreciate that the embodiments of the present application may be provided as methods, systems, or computer program products. Therefore, the present application may take the form of hardware embodiments, software embodiments, or embodiments combining software and hardware. Moreover, the present application may take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage and optical storage, etc.) containing computer-usable program codes.
[0152] The present application is described with reference to the flowcharts and / or block diagrams of the methods, devices (systems), and computer program products according to the embodiments of the present application. It should be understood that each process and / or box in the flowchart and / or block diagram, as well as the combination of the processes and / or boxes in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to generate a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.
[0153] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.
[0154] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.
[0155] The above description is only a preferred embodiment of the present application and is not intended to limit the protection scope of the present application.
Claims
1. A grammar conversion method, characterized in that: The method comprises: Obtaining a statement to be converted having a first database grammar; Based on the sentence to be converted, generating a feature code corresponding to the sentence to be converted; wherein the feature code is unique; If the feature code is not included in the initial summary list, the target large language model is used to perform grammatical conversion on the sentence to be converted to generate a target sentence with the grammar of the second database; wherein the target large language model is obtained by training the initial large language model using sample data; the initial summary list has a plurality of preset corresponding relationships, and each of the preset corresponding relationships represents the relationship between the grammatical summaries of different databases; Wherein, generating a feature code corresponding to the sentence to be converted based on the sentence to be converted includes: Based on the sentence to be converted and the placeholder, generate a first grammatical summary corresponding to the sentence to be converted; Using a hash algorithm to convert the first syntax summary to obtain the feature code; The step of generating a first grammatical summary corresponding to the statement to be converted based on the statement to be converted and the placeholder includes: Performing grammatical analysis on the statement to be converted by a first grammatical analyzer to determine a first constant in the statement to be converted; The first syntax summary is generated based on the placeholder, the first constant, and the statement to be converted.
2. The method according to claim 1, characterized in that After the target large language model is used to perform grammar conversion on the sentence to be converted to generate a target sentence with the grammar of the second database, the method further includes: Performing grammatical parsing on the target sentence by a second grammatical parser to determine a second constant in the target sentence; Based on the placeholder, the second constant, and the target sentence, a second grammatical digest corresponding to the target sentence is determined.
3. The method according to claim 1 or 2, characterized in that: The method further comprises: Based on the first grammatical digest, the feature code and the second grammatical digest, establishing a target correspondence relationship between the first grammatical digest and the second grammatical digest; The target correspondence is stored in the initial summary list, a target summary list is obtained, and the target sentence is returned.
4. The method according to claim 1, characterized in that: The method further comprises: If the feature code is in the initial summary list, obtaining a second grammatical summary from the initial summary list based on the feature code and a preset correspondence in the initial summary list; wherein the preset correspondence represents a relationship between the grammatical summary of the first database and the grammatical summary of the second database; The target sentence is generated based on the sentence to be converted and the second grammar summary, and the target sentence is returned.
5. The method according to claim 4, characterized in that The step of generating the target sentence based on the sentence to be converted and the second grammar summary includes: The first constant in the statement to be converted is used to replace the placeholder in the second grammar summary to generate the target statement.
6. A grammar conversion device, characterized in that: The device comprises: An acquisition unit, used for acquiring a statement to be converted having a first database grammar; A processing unit, configured to generate a feature code corresponding to the sentence to be converted based on the sentence to be converted; wherein the feature code is unique; A generating unit is used for, if the initial summary list does not contain the feature code, using a target large language model to perform grammar conversion on the sentence to be converted, and generating a target sentence with the grammar of the second database; wherein the target large language model is obtained by training the initial large language model using sample data; the initial summary list contains a plurality of preset corresponding relationships, and each of the preset corresponding relationships represents the relationship between the grammatical summaries of different databases; Wherein, generating a feature code corresponding to the sentence to be converted based on the sentence to be converted includes: Based on the sentence to be converted and the placeholder, generate a first grammatical summary corresponding to the sentence to be converted; Using a hash algorithm to convert the first syntax summary to obtain the feature code; The step of generating a first grammatical summary corresponding to the statement to be converted based on the statement to be converted and the placeholder includes: Performing grammatical analysis on the statement to be converted by a first grammatical analyzer to determine a first constant in the statement to be converted; The first syntax summary is generated based on the placeholder, the first constant, and the statement to be converted.
7. A grammar conversion device, characterized in that: The device comprises: a processor, a memory and a communication bus; The communication bus is used to realize the communication connection between the processor and the memory; The processor is used to execute the grammar conversion program in the memory to implement the steps of the grammar conversion method according to any one of claims 1 to 5.
8. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores one or more programs, and the one or more programs can be executed by one or more processors to implement the steps of the grammar conversion method according to any one of claims 1 to 5.
Citation Information
Patent Citations
Method and device for generating structured query language statement
CN114528312A
Database access code conversion method and device and electronic equipment
CN117555925A