A sql language conversion method, electronic equipment and storage medium
By using mapping tables and simplification processes in the SQL language conversion model, the problems of long generation time and high computational cost when converting natural language to SQL are solved, resulting in more efficient SQL statement generation.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- MOBILE TECH COMPANY CHINA TRAVELSKY HLDG
- Filing Date
- 2024-10-08
- Publication Date
- 2026-05-01
AI Technical Summary
In existing technologies, when converting natural language to SQL, the large number of characters in SQL word segmentation leads to long generation time and consumes a lot of computing power, affecting user experience and resource consumption.
The SQL language conversion model is adopted, which utilizes the first SQL language conversion mapping table and the second SQL language conversion mapping table to generate the target SQL statement by splitting, simplifying and concatenating SQL words, thereby reducing unnecessary word segmentation processing.
It shortens the SQL statement generation time, improves conversion efficiency, reduces computing power consumption, and enhances the user experience.
Smart Images

Figure CN119201985B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of computer language conversion, and in particular to an SQL language conversion method, electronic device, and storage medium. Background Technology
[0002] Current methods for converting natural language (NLP) to SQL involve parsing the NLP statement and then converting it according to its semantics and a specific language conversion template to obtain the SQL statement. The generation rate of the SQL statement is related to the number of characters in the SQL tokens used for language conversion. The larger the number of characters in the SQL tokens, the longer the generation time and the greater the computational cost. Therefore, the more conversion keywords in the NLP statement, the more SQL tokens are needed, which lengthens the time to generate the corresponding SQL statement, impacting user experience and consuming significant computational resources. Summary of the Invention
[0003] To address the aforementioned technical problems, the technical solution adopted by this invention is as follows:
[0004] According to one aspect of this application, a SQL language conversion method is provided, which is applied to an SQL language conversion model, wherein the SQL language conversion model stores a first SQL language conversion mapping table and a second SQL language conversion mapping table.
[0005] The first SQL language conversion mapping table stores several target SQL language conversion words, which include preset key fields and whose information entropy is less than the preset information entropy threshold.
[0006] The second SQL language conversion mapping table stores the mapping relationship between key SQL language conversion words that conform to the preset information entropy difference rule and their corresponding rewritten SQL language conversion words; the character length of the rewritten SQL language conversion word is less than the character length of the key SQL language conversion word corresponding to the rewritten SQL language conversion word;
[0007] The SQL language conversion method includes the following steps:
[0008] Step S100: In response to receiving the natural language statement to be converted, the natural language statement to be converted is split to obtain several natural language segments to be converted included in the natural language statement to be converted.
[0009] Step S200: Perform SQL language conversion on each natural word to be converted to obtain the initial SQL language word corresponding to each natural word to be converted;
[0010] Step S300: Traverse each initial SQL language segmentation. If the initial SQL language segmentation is any target SQL language conversion segmentation stored in the first SQL language conversion mapping table, then determine the initial SQL language segmentation as the target SQL language segmentation.
[0011] Step S400: Delete each target SQL language segment from the initial SQL language segments, and then concatenate the remaining initial SQL language segments after deletion to obtain the target SQL statement.
[0012] In one exemplary embodiment of this application, the first SQL language conversion mapping table is obtained through the following steps:
[0013] Step S011: Obtain several historical natural language statements;
[0014] Step S012: Segment each historical natural sentence to obtain several historical natural words included in each historical natural sentence.
[0015] Step S013: Perform SQL language conversion on each historical natural word segment to obtain the historical initial SQL language segment corresponding to each historical natural word segment;
[0016] Step S014: Traverse each historical initial SQL language segmentation. If any historical initial SQL language segmentation includes a preset key field, then determine the historical initial SQL language segmentation as a historical key SQL language segmentation to obtain several historical key SQL language segments.
[0017] Step S015: Traverse each historical key SQL language segment. If the information entropy of any historical key SQL language segment is less than the preset information entropy threshold, then determine the historical key SQL language segment as the target SQL language conversion segment.
[0018] Step S016: Integrate several target SQL language conversion word segments to obtain the first SQL language conversion mapping table.
[0019] In one exemplary embodiment of this application, step S100 includes:
[0020] Step S110: Perform multiple rounds of rewriting on the natural language statement to be converted to obtain the corresponding rewritten statement to be converted;
[0021] Step S120: Perform semantic analysis on the statement to be converted and rewritten to obtain the semantic identifier corresponding to each word to be converted and rewritten in the statement to be converted and rewritten.
[0022] Step S130: Traverse each word segment to be converted and rewritten. If the semantic identifier corresponding to the word segment to be converted and rewritten is a preset key semantic identifier, then the word segment to be converted and rewritten is determined as the natural word segment to be converted.
[0023] In one exemplary embodiment of this application, step S300 includes:
[0024] Step S310: If the initial SQL language segmentation is not any target SQL language conversion segmentation stored in the first SQL language conversion mapping table, then the initial SQL language segmentation is determined as the SQL language segmentation to be verified.
[0025] Step S320: If the SQL language segment to be verified includes a preset key field and the information entropy of the SQL language segment to be verified is less than the preset information entropy threshold, then the SQL language segment to be verified is stored in the first SQL language conversion mapping table, and the SQL language segment to be verified is determined as the target SQL language segment, and step S400 is executed.
[0026] In one exemplary embodiment of this application, step S300 further includes:
[0027] Step S301: If the initial SQL language segmentation is not any target SQL language transformation segmentation stored in the first SQL language transformation mapping table, but the initial SQL language segmentation is any key SQL language transformation segmentation stored in the second SQL language transformation mapping table, then the initial SQL language segmentation is rewritten as a rewritten SQL language transformation segmentation that has a mapping relationship with it.
[0028] In one exemplary embodiment of this application, the second SQL language conversion mapping table is obtained through the following steps:
[0029] Step S021: Traverse each historical initial SQL language segmentation. If the historical initial SQL language segmentation does not include the preset key field, or the information entropy of the historical initial SQL language segmentation is greater than or equal to the preset information entropy threshold, then the historical initial SQL language segmentation is determined as the first historical SQL language segmentation.
[0030] Step S022: Based on the character length of each first historical SQL language segment, determine several second historical SQL language segments from several first historical SQL language segments; the second historical SQL language segments are first historical SQL language segments that conform to the preset character length rules;
[0031] Step S023: According to the preset character abbreviation rules, rewrite each second historical SQL language segment to obtain the rewritten SQL language converted segment corresponding to each second historical SQL language segment;
[0032] Step S024: Determine the second SQL language conversion mapping table based on the information entropy of each second historical SQL language segment and the information entropy of the rewritten SQL language conversion segment corresponding to the second historical SQL language segment.
[0033] In one exemplary embodiment of this application, step S022 includes:
[0034] Step S0221: Obtain the character length of each first historical SQL language token, and obtain the character length list B = (B1, B2, ..., B...). g ,...,B h ); where g = 1, 2, ..., h; h is the number of words in the first historical SQL language segmentation; B g The length of the g-th first historical SQL language word segment;
[0035] Step S0222: Traverse the character length list B. If B g If B0 is greater than or equal to B0, then the g-th first historical SQL language segment is determined as the second historical SQL language segment, so as to obtain several second historical SQL language segments; where B0 is the preset character length threshold.
[0036] In one exemplary embodiment of this application, step S024 includes:
[0037] Step S0241: Obtain the information entropy of each second historical SQL language segmentation, and obtain the first information entropy list C = (C1, C2, ..., C a ,...,C b ); where a = 1, 2, ..., b; b is the number of words in the second historical SQL language segmentation; C a The information entropy of the a-th second historical SQL language word segmentation;
[0038] Step S0242: Obtain the information entropy of each rewritten SQL language conversion word segmentation to obtain the second information entropy list.
[0039] D = (D1, D2, ..., D a ,...,D b ); where D a The rewritten result is obtained after rewriting the a-th second historical SQL language word segment.
[0040] Information entropy of SQL language word segmentation conversion;
[0041] Step S0243: Traverse the first information entropy list C and the second information entropy list D. If |D a -C aIf |≤d, then the a-th second historical SQL language segment is determined as the key SQL language conversion segment; where d is the preset information entropy difference threshold.
[0042] Step S0244: Store the mapping relationship between each key SQL language conversion word segment and its corresponding rewritten SQL language conversion word segment in a preset initial mapping relationship table to obtain the second SQL language conversion mapping table.
[0043] According to one aspect of this application, a non-transitory computer-readable storage medium is provided, wherein at least one instruction or at least one program is stored therein, the at least one instruction or the at least one program being loaded and executed by a processor to implement the aforementioned SQL language conversion method.
[0044] According to one aspect of this application, an electronic device is provided, including a processor and the aforementioned non-transitory computer-readable storage medium.
[0045] The present invention has at least the following beneficial effects:
[0046] The SQL language conversion method of this invention splits the natural language statement to be converted into several natural language segments to be converted. Each natural language segment is then converted into an initial SQL language segment. Each initial SQL language segment is then iterated over; if it conforms to the information entropy rule, it is deleted. The remaining initial SQL language segments are then concatenated sequentially to obtain the target SQL statement. By simplifying the converted initial SQL language segments, the generation time of the target SQL statement is shortened, thereby improving the conversion efficiency. Attached Figure Description
[0047] To more clearly illustrate the technical solutions in the embodiments of the present invention, the accompanying drawings used in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0048] Figure 1 A flowchart of the SQL language conversion method provided in an embodiment of the present invention. Detailed Implementation
[0049] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0050] A SQL language conversion method is applied to an SQL language conversion model, which stores a first SQL language conversion mapping table and a second SQL language conversion mapping table.
[0051] Currently, in the conversion between natural language and SQL, this is typically used in intelligent question-and-answer systems. Users input questions in natural language into the system, which then converts the questions into SQL index conditions. The system then uses these index conditions to retrieve corresponding data from the database, converts the SQL data back into natural language answers, and outputs them to the user.
[0052] Therefore, the SQL language conversion model in this application is the model for converting user question statements into SQL in a user intelligent question answering system.
[0053] The first SQL language conversion mapping table stores several target SQL language conversion words, which include preset key fields and whose information entropy is less than the preset information entropy threshold.
[0054] The second SQL language conversion mapping table stores the mapping relationship between key SQL language conversion words that conform to the preset information entropy difference rule and their corresponding rewritten SQL language conversion words; the character length of the rewritten SQL language conversion word is less than the character length of the key SQL language conversion word corresponding to the rewritten SQL language conversion word.
[0055] The first SQL language conversion mapping table is obtained through steps S011-S016:
[0056] Step S011: Obtain several historical natural language statements;
[0057] Historical natural language statements are user-generated queries written in natural language within a historical period.
[0058] Step S012: Segment each historical natural sentence to obtain several historical natural words included in each historical natural sentence.
[0059] Semantic analysis is performed on each historical natural sentence to identify several historical natural words that can represent semantics in each historical natural sentence. Existing semantic analysis methods are used for the semantic analysis of natural sentences.
[0060] Step S013: Perform SQL language conversion on each historical natural word segment to obtain the historical initial SQL language segment corresponding to each historical natural word segment;
[0061] The method of performing semantic analysis on each historical natural sentence to obtain several historical natural word segments, and then performing SQL conversion on each historical natural word segment, is different from directly converting the historical natural sentence into SQL. This method eliminates the need to convert words with less semantic meaning into SQL, thus reducing the amount of data processing required for language conversion.
[0062] Step S014: Traverse each historical initial SQL language segmentation. If any historical initial SQL language segmentation includes a preset key field, then determine the historical initial SQL language segmentation as a historical key SQL language segmentation to obtain several historical key SQL language segments.
[0063] The preset key fields are fields set by the developers to represent the amount of information in the historical natural language statements. If the preset key fields are included in the historical initial SQL language segmentation, it means that the historical initial SQL language segmentation is a word that can reflect a specific semantic meaning, and it is identified as the historical key SQL language segmentation.
[0064] Step S015: Traverse each historical key SQL language segment. If the information entropy of any historical key SQL language segment is less than the preset information entropy threshold, then determine the historical key SQL language segment as the target SQL language conversion segment.
[0065] The information entropy of historical key SQL terms indicates the amount of information contained in those terms. The higher the information entropy, the more information the historical key SQL terms contain, meaning they are more important when indexing information. Conversely, the lower the information entropy, the less information the historical key SQL terms contain, and therefore they have little impact on subsequent indexing results.
[0066] Step S016: Integrate several target SQL language conversion word segments to obtain the first SQL language conversion mapping table.
[0067] The second SQL language conversion mapping table is obtained through steps S021-S024:
[0068] Step S021: Traverse each historical initial SQL language segmentation. If the historical initial SQL language segmentation does not include the preset key field, or the information entropy of the historical initial SQL language segmentation is greater than or equal to the preset information entropy threshold, then the historical initial SQL language segmentation is determined as the first historical SQL language segmentation.
[0069] Step S022: Based on the character length of each first historical SQL language segment, determine several second historical SQL language segments from several first historical SQL language segments; the second historical SQL language segments are first historical SQL language segments that conform to the preset character length rules;
[0070] When indexing data based on index conditions, the character length of the index conditions is directly proportional to the indexing time and the computing power required for the index. Therefore, when indexing information, the longer the character length of the index conditions, the greater the computing power required for the index and the longer the indexing time. Thus, the character length of the index conditions becomes a key factor in reducing indexing time. After obtaining the first historical SQL language segmentation, several second historical SQL language segments are determined based on the character length.
[0071] Furthermore, step S022 includes steps S0221-S0222:
[0072] Step S0221: Obtain the character length of each first historical SQL language token, and obtain the character length list B = (B1, B2, ..., B...). g ,...,B h ); where g = 1, 2, ..., h; h is the number of words in the first historical SQL language segmentation; B g The length of the g-th first historical SQL language word segment;
[0073] Step S0222: Traverse the character length list B. If B g If B0 is greater than or equal to B0, then the g-th first historical SQL language segment is determined as the second historical SQL language segment, so as to obtain several second historical SQL language segments; where B0 is the preset character length threshold.
[0074] If the character length of the first historical SQL language segment is too long, the generated index conditions will affect the subsequent indexing speed. Therefore, the first historical SQL language segment is determined as the second historical SQL language segment.
[0075] Step S023: According to the preset character abbreviation rules, rewrite each second historical SQL language segment to obtain the rewritten SQL language converted segment corresponding to each second historical SQL language segment;
[0076] Character abbreviation rules are user-defined or system-preset character shortening and rewriting rules. By statistically analyzing a number of historical characters, characters are shortened without losing information, thereby improving data processing efficiency.
[0077] Step S024: Determine the second SQL language conversion mapping table based on the information entropy of each second historical SQL language segment and the information entropy of the rewritten SQL language conversion segment corresponding to the second historical SQL language segment;
[0078] Since shortening the characters of the second historical SQL language segmentation must not result in excessive loss of information in the original words and sentences, so as not to reduce the accuracy of the indexing results, it is necessary to verify whether the information entropy difference between the second historical SQL language segmentation and its corresponding rewritten SQL language transformed segmentation is too large. If the difference is within the specified range, it means that the obtained rewritten SQL language transformed segmentation conforms to the information entropy difference rule, and the characters of the words and sentences are shortened without significant loss of information, thus improving the indexing speed.
[0079] Furthermore, step S024 includes steps S0241-S0244:
[0080] Step S0241: Obtain the information entropy of each second historical SQL language segmentation, and obtain the first information entropy list C = (C1, C2, ..., C a ,...,C b ); where a = 1, 2, ..., b; b is the number of words in the second historical SQL language segmentation; C a The information entropy of the a-th second historical SQL language word segmentation;
[0081] Step S0242: Obtain the information entropy of each rewritten SQL language conversion word segmentation to obtain the second information entropy list.
[0082] D = (D1, D2, ..., D a ,...,D b ); where D a The rewritten result is obtained after rewriting the a-th second historical SQL language word segment.
[0083] Information entropy of SQL language word segmentation conversion;
[0084] Step S0243: Traverse the first information entropy list C and the second information entropy list D. If |D a -C a If |≤d, then the a-th second historical SQL language segment is determined as the key SQL language conversion segment; where d is the preset information entropy difference threshold.
[0085] Step S0244: Store the mapping relationship between each key SQL language conversion word segment and its corresponding rewritten SQL language conversion word segment in a preset initial mapping relationship table to obtain the second SQL language conversion mapping table.
[0086] like Figure 1 As shown, the SQL language conversion method described in this application includes the following steps:
[0087] Step S100: In response to receiving the natural language statement to be converted, the natural language statement to be converted is split to obtain several natural language segments to be converted included in the natural language statement to be converted.
[0088] Semantic analysis is performed on the natural language sentences to be converted, resulting in several natural language segments to be converted.
[0089] Furthermore, step S100 includes steps S110-S130:
[0090] Step S110: Perform multiple rounds of rewriting on the natural language statement to be converted to obtain the corresponding rewritten statement to be converted;
[0091] Multi-round rewriting can be performed using existing processing methods. Multi-round rewriting is used to semantically supplement the natural language statement to be converted. If the natural language statement to be converted is too simple, such as lacking a subject, and the natural language statement to be converted is directly converted into SQL, the converted SQL statement will also lack the corresponding keywords, which will lead to subsequent indexing anomalies. Therefore, multi-round rewriting of the natural language statement to be converted can be performed first. By connecting the surrounding statements of the natural language statement to be converted, the semantics of the natural language statement to be converted can be expanded, and then the SQL statement can be converted into SQL, which can improve the accuracy of the response to the user.
[0092] Step S120: Perform semantic analysis on the statement to be converted and rewritten to obtain the semantic identifier corresponding to each word to be converted and rewritten in the statement to be converted and rewritten.
[0093] After obtaining the statement to be converted and rewritten, semantic analysis is performed on it, that is, keyword splitting is performed on the statement to be converted and rewritten to obtain the words to be converted and rewritten included in the statement. Semantic analysis and keyword splitting can be performed using existing analysis methods. Each word to be converted and rewritten has a corresponding semantic identifier, which indicates the semantic type of the corresponding word to be converted and rewritten, such as whether the word to be converted and rewritten is the subject, predicate, or object of the statement. Through the semantic identifier, it can be determined whether the word to be converted and rewritten plays a key role in information indexing.
[0094] Step S130: Traverse each word segment to be converted and rewritten. If the semantic identifier corresponding to the word segment to be converted and rewritten is a preset key semantic identifier, then the word segment to be converted and rewritten is determined as the natural word segment to be converted.
[0095] The pre-defined key semantic identifiers are semantic identifiers of essential semantic types that are indispensable during information indexing. Key semantic identifiers can be obtained by performing keyword segmentation and statistical analysis on several historical natural language samples.
[0096] Step S200: Perform SQL language conversion on each natural word to be converted to obtain the initial SQL language word corresponding to each natural word to be converted;
[0097] SQL language conversion uses existing language conversion methods.
[0098] Step S300: Traverse each initial SQL language segmentation. If the initial SQL language segmentation is any target SQL language conversion segmentation stored in the first SQL language conversion mapping table, then determine the initial SQL language segmentation as the target SQL language segmentation.
[0099] Furthermore, step S300 includes steps S310-S320:
[0100] Step S310: If the initial SQL language segmentation is not any target SQL language conversion segmentation stored in the first SQL language conversion mapping table, then the initial SQL language segmentation is determined as the SQL language segmentation to be verified.
[0101] Step S320: If the SQL language segment to be verified includes a preset key field and the information entropy of the SQL language segment to be verified is less than the preset information entropy threshold, then the SQL language segment to be verified is stored in the first SQL language conversion mapping table, and the SQL language segment to be verified is determined as the target SQL language segment, and step S400 is executed.
[0102] Furthermore, step S300 also includes step S301:
[0103] Step S301: If the initial SQL language segmentation is not any target SQL language transformation segmentation stored in the first SQL language transformation mapping table, but the initial SQL language segmentation is any key SQL language transformation segmentation stored in the second SQL language transformation mapping table, then the initial SQL language segmentation is rewritten as a rewritten SQL language transformation segmentation that has a mapping relationship with it.
[0104] Step S400: Delete each target SQL language segment from the initial SQL language segments, and then concatenate the remaining initial SQL language segments after deletion to obtain the target SQL statement.
[0105] Since the target SQL language conversion words stored in the first SQL language conversion mapping table are words and phrases with low information entropy, they have little impact on the indexing results of subsequent information indexing. Therefore, if the initial SQL language word is any target SQL language conversion word stored in the first SQL language conversion mapping table, it will be deleted to improve the subsequent indexing speed.
[0106] The SQL language conversion method of this invention splits the natural language statement to be converted into several natural language segments to be converted. Each natural language segment is then converted into an initial SQL language segment. Each initial SQL language segment is then iterated over; if it conforms to the information entropy rule, it is deleted. The remaining initial SQL language segments are then concatenated sequentially to obtain the target SQL statement. By simplifying the converted initial SQL language segments, the generation time of the target SQL statement is shortened, thereby improving the conversion efficiency.
[0107] Embodiments of the present invention also provide a computer program product including program code, which, when the program product is run on an electronic device, causes the electronic device to perform the steps of the methods described above in various exemplary embodiments of the present invention.
[0108] Furthermore, although the steps of the method in this disclosure are described in a specific order in the accompanying drawings, this does not require or imply that the steps must be performed in that specific order, or that all the steps shown must be performed to achieve the desired result. Additional or alternative steps may be omitted, multiple steps may be combined into one step, and / or a step may be broken down into multiple steps.
[0109] From the above description of the embodiments, those skilled in the art will readily understand that the exemplary embodiments described herein can be implemented by software or by combining software with necessary hardware. Therefore, the technical solutions according to the embodiments of this disclosure can be embodied in the form of a software product, which can be stored in a non-volatile storage medium (such as a CD-ROM, USB flash drive, external hard drive, etc.) or on a network, including several instructions to cause a computing device (such as a personal computer, server, mobile terminal, or network device, etc.) to execute the methods according to the embodiments of this disclosure.
[0110] In an exemplary embodiment of this disclosure, an electronic device capable of implementing the above-described method is also provided.
[0111] Those skilled in the art will understand that various aspects of the present invention can be implemented as systems, methods, or program products. Therefore, various aspects of the present invention can be specifically implemented in the following forms: entirely hardware implementations, entirely software implementations (including firmware, microcode, etc.), or implementations combining hardware and software aspects, collectively referred to herein as “circuits,” “modules,” or “systems.”
[0112] An electronic device according to this embodiment of the invention. The electronic device is merely an example and should not be construed as limiting the functionality or scope of the embodiments of the invention.
[0113] Electronic devices are manifested in the form of general-purpose computing devices. Components of an electronic device may include, but are not limited to: at least one processor, at least one memory, and buses connecting different system components (including memory and processor).
[0114] The storage device stores program code that can be executed by the processor to perform the steps described in the "Exemplary Methods" section above, according to various exemplary embodiments of the present invention.
[0115] The storage may include readable media in the form of volatile storage, such as random access memory (RAM) and / or cache memory, and may further include read-only memory (ROM).
[0116] The storage may also include programs / utilities having a set (at least one) of program modules, including but not limited to: an operating system, one or more applications, other program modules, and program data, each or some combination of these examples may include an implementation of a network environment.
[0117] A bus can represent one or more of several bus architectures, including a memory bus or memory controller, a peripheral bus, a graphics acceleration port, a processor, or a local bus that uses any of the various bus architectures.
[0118] Electronic devices can also communicate with one or more external devices (such as keyboards, pointing devices, Bluetooth devices, etc.), one or more devices that enable users to interact with the electronic device, and / or any device that enables the electronic device to communicate with one or more other computing devices (such as routers, modems, etc.). This communication can be performed through input / output (I / O) interfaces. Furthermore, electronic devices can also communicate with one or more networks (such as local area networks (LANs), wide area networks (WANs), and / or public networks, such as the Internet) via network adapters.
[0119] From the above description of the embodiments, those skilled in the art will readily understand that the exemplary embodiments described herein can be implemented by software or by combining software with necessary hardware. Therefore, the technical solutions according to the embodiments of this disclosure can be embodied in the form of a software product, which can be stored in a non-volatile storage medium (such as a CD-ROM, USB flash drive, external hard drive, etc.) or on a network, including several instructions to cause a computing device (such as a personal computer, server, terminal device, or network device, etc.) to execute the methods according to the embodiments of this disclosure.
[0120] In exemplary embodiments of this disclosure, a computer-readable storage medium is also provided, on which a program product capable of implementing the methods described above is stored. In some possible embodiments, various aspects of the invention may also be implemented as a program product comprising program code that, when the program product is run on a terminal device, causes the terminal device to perform the steps of the various exemplary embodiments of the invention described in the "Exemplary Methods" section of this specification.
[0121] The program product may employ any combination of one or more readable media. A readable medium may be a readable signal medium or a readable storage medium. A readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination thereof. More specific examples of readable storage media (a non-exhaustive list) include: an electrical connection having one or more wires, a portable disk, a hard disk, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fiber, portable compact disk read-only memory (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination thereof.
[0122] Computer-readable signal media may include data signals propagated in baseband or as part of a carrier wave, carrying readable program code. Such propagated data signals may take various forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination thereof. A readable signal medium may also be any readable medium other than a readable storage medium, capable of sending, propagating, or transmitting programs for use by or in conjunction with an instruction execution system, apparatus, or device.
[0123] The program code contained on the readable medium may be transmitted using any suitable medium, including but not limited to wireless, wired, optical fiber, RF, etc., or any suitable combination thereof.
[0124] Program code for performing the operations of this invention can be written in any combination of one or more programming languages, including object-oriented programming languages such as Java and C++, and conventional procedural programming languages such as C or similar languages. The program code can execute entirely on the user's computing device, partially on the user's device, as a standalone software package, partially on the user's computing device and partially on a remote computing device, or entirely on a remote computing device or server. In cases involving remote computing devices, the remote computing device can be connected to the user's computing device via any type of network, including a local area network (LAN) or a wide area network (WAN), or it can be connected to an external computing device (e.g., via the Internet using an Internet service provider).
[0125] Furthermore, the above figures are merely illustrative of the processes included in the method according to exemplary embodiments of the present invention, and are not intended to be limiting. It is readily understood that the processes shown in the above figures do not indicate or limit the temporal order of these processes. Additionally, it is readily understood that these processes may be executed synchronously or asynchronously, for example, in multiple modules.
[0126] It should be noted that although several modules or units for the device used to perform actions have been mentioned in the detailed description above, this division is not mandatory. In fact, according to embodiments of this disclosure, the features and functions of two or more modules or units described above can be embodied in one module or unit. Conversely, the features and functions of one module or unit described above can be further divided and embodied by multiple modules or units.
[0127] The above description is merely a specific embodiment of the present invention, but the scope of protection of the present invention is not limited thereto. Any variations or substitutions that can be easily conceived by those skilled in the art within the technical scope disclosed in the present invention should be included within the scope of protection of the present invention. Therefore, the scope of protection of the present invention should be determined by the scope of the claims.
Claims
1. A method for converting SQL language, characterized in that, It is applied to an SQL language conversion model, in which a first SQL language conversion mapping table is stored, and the first SQL language conversion mapping table stores several target SQL language conversion words, wherein the target SQL language conversion words include preset key fields and the information entropy is less than a preset information entropy threshold; The method includes the following steps: Step S100: In response to receiving the natural language statement to be converted, the natural language statement to be converted is split to obtain several natural language segments to be converted included in the natural language statement to be converted. Step S200: Perform SQL language conversion on each of the natural word segments to be converted to obtain the initial SQL language segment corresponding to each of the natural word segments to be converted; Step S300: Traverse each of the initial SQL language segments. If the initial SQL language segment is any target SQL language conversion segment stored in the first SQL language conversion mapping table, then determine the initial SQL language segment as the target SQL language segment. Step S400: Delete each target SQL language segment from the initial SQL language segments, and concatenate the remaining initial SQL language segments after deletion to obtain the target SQL statement. The first SQL language conversion mapping table is obtained through steps S011-S016: Step S011: Obtain several historical natural language statements; Step S012: Segment each of the historical natural sentences to obtain several historical natural words included in each of the historical natural sentences. Step S013: Perform SQL language conversion on each of the historical natural word segments to obtain the historical initial SQL language segment corresponding to each of the historical natural word segments; Step S014: Traverse each of the historical initial SQL language segments. If any of the historical initial SQL language segments includes a preset key field, then the historical initial SQL language segment is determined as a historical key SQL language segment to obtain several historical key SQL language segments. Step S015: Traverse each of the historical key SQL language segments. If the information entropy of any historical key SQL language segment is less than the preset information entropy threshold, then the historical key SQL language segment is determined as the target SQL language conversion segment. Step S016: Integrate the target SQL language conversion word segments to obtain the first SQL language conversion mapping table.
2. The method according to claim 1, characterized in that, Step S100 includes: Step S110: Perform multiple rounds of rewriting on the natural language statement to be converted to obtain the corresponding rewritten statement to be converted; Step S120: Perform semantic analysis on the statement to be converted and rewritten to obtain the semantic identifier corresponding to each word to be converted and rewritten in the statement to be converted and rewritten. Step S130: Traverse each of the words to be converted and rewritten. If the semantic identifier corresponding to the word to be converted and rewritten is a preset key semantic identifier, then the word to be converted and rewritten is determined as a natural word to be converted.
3. The method according to claim 2, characterized in that, Step S300 includes: Step S310: If the initial SQL language segmentation is not any target SQL language conversion segmentation stored in the first SQL language conversion mapping table, then the initial SQL language segmentation is determined as the SQL language segmentation to be verified. Step S320: If the SQL language segment to be verified includes a preset key field, and the information entropy of the SQL language segment to be verified is less than the preset information entropy threshold, then the SQL language segment to be verified is stored in the first SQL language conversion mapping table, and the SQL language segment to be verified is determined as the target SQL language segment, and step S400 is executed.
4. The method according to claim 2, characterized in that, The SQL language conversion model also stores a second SQL language conversion mapping table, which stores the mapping relationship between key SQL language conversion words that conform to the preset information entropy difference rule and their corresponding rewritten SQL language conversion words; the character length of the rewritten SQL language conversion word is less than the character length of the key SQL language conversion word corresponding to the rewritten SQL language conversion word; Step S300 further includes: Step S301: If the initial SQL language segmentation is not any target SQL language conversion segmentation stored in the first SQL language conversion mapping table, but the initial SQL language segmentation is any key SQL language conversion segmentation stored in the second SQL language conversion mapping table, then the initial SQL language segmentation is rewritten as a rewritten SQL language conversion segmentation with a mapping relationship with it.
5. The method according to claim 4, characterized in that, The second SQL language conversion mapping table is obtained through the following steps: Step S021: Traverse each of the historical initial SQL language segments. If the historical initial SQL language segment does not include a preset key field, or the information entropy of the historical initial SQL language segment is greater than or equal to a preset information entropy threshold, then the historical initial SQL language segment is determined as the first historical SQL language segment. Step S022: Based on the character length of each first historical SQL language segment, determine a number of second historical SQL language segments from the number of first historical SQL language segments; the second historical SQL language segments are first historical SQL language segments that conform to preset character length rules; Step S023: According to the preset character abbreviation rules, each second historical SQL language segment is rewritten to obtain the rewritten SQL language converted segment corresponding to each second historical SQL language segment; Step S024: Determine the second SQL language conversion mapping table based on the information entropy of each second historical SQL language segment and the information entropy of the rewritten SQL language conversion segment corresponding to the second historical SQL language segment.
6. The method according to claim 5, characterized in that, Step S022 includes: Step S0221: Obtain the character length of each of the first historical SQL language tokens, and obtain a character length list B=(B1,B2,...,B...). g ,...,B h ); where g=1,2,...,h; h is the number of words in the first historical SQL language segmentation; B g The length of the first historical SQL language word segment for the g-th segment; Step S0222: Traverse the character length list B. If B g If B0 is greater than or equal to B0, then the g-th first historical SQL language segment is determined as the second historical SQL language segment, so as to obtain several second historical SQL language segments; where B0 is a preset character length threshold.
7. The method according to claim 6, characterized in that, Step S024 includes: Step S0241: Obtain the information entropy of each of the second historical SQL language segments to obtain the first information entropy list C=(C1,C2,...,C...). a ,...,C b ); where a=1,2,...,b; b is the number of words in the second historical SQL language segmentation; C a The information entropy of the second historical SQL language word segmentation for the a-th term; Step S0242: Obtain the information entropy of each of the rewritten SQL language conversion word segments to obtain the second information entropy list D=(D1,D2,...,D...). a ,...,D b ); where D a The information entropy of the rewritten SQL language transformed word segment is obtained after rewriting the a-th second historical SQL language word segment. Step S0243: Traverse the first information entropy list C and the second information entropy list D. If |D a -C a If |≤d, then the a-th second historical SQL language segment is determined as the key SQL language conversion segment; where d is the preset information entropy difference threshold. Step S0244: Store the mapping relationship between each key SQL language conversion word segment and its corresponding rewritten SQL language conversion word segment in a preset initial mapping relationship table to obtain a second SQL language conversion mapping table.
8. A non-transitory computer-readable storage medium storing at least one instruction or at least one program segment, characterized in that, The at least one instruction or the at least one program segment is loaded and executed by the processor to implement the SQL language conversion method as described in any one of claims 1-7.
9. An electronic device, characterized in that, Includes a processor and the non-transitory computer-readable storage medium as described in claim 8.
Citation Information
Patent Citations
Dictionary dimension reducing method and device and information classifying method and device
CN105512104A
Structured query language conversion method based on natural language, and related equipment thereof
CN111177184A