A method for converting text into SQL, storage medium and electronic device

By using semantic comparison components and noun extraction network in text recognition technology, the problem of high complexity of SQL statement element extraction is solved, the processing accuracy is improved, and efficient conversion from text to SQL is achieved.

CN118709684BActive Publication Date: 2025-02-18SHENZHEN YUANDAO COMM TECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202410937812.2
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-07-12
Publication Date
2025-02-18
Estimated Expiration
2044-07-12

AI Technical Summary

Technical Problem

In the prior art, due to the complex semantic recognition process, SQL statement element extraction is complex, resulting in low processing accuracy.

Method used

By receiving the text sentences to be identified, using semantic comparison components and operation description vocabulary to traverse, obtain keyword identification results, and use noun extraction network to perform segmentation and feature matching, generate operation areas and operation objects, and finally combine with SQL statement templates. Build SQL statements.

Benefits of technology

Reduces the complexity of feature matching, improves processing accuracy, and achieves efficient conversion from text to SQL.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118709684B_ABST
    Figure CN118709684B_ABST
Patent Text Reader

Abstract

The present invention relates to a method, storage medium and electronic device for converting text into SQL, and relates to the field of text recognition, including: receiving a text sentence to be recognized, traversing the text sentence to be recognized from the beginning to the end according to a semantic comparison component and an operation description vocabulary set, obtaining a front segment text sentence to be recognized and a back segment text sentence to be recognized; obtaining a front segment noun identification result and a back segment noun identification result through a noun extraction network, and obtaining a front segment secondary segmentation result; obtaining a back segment secondary segmentation result according to the back segment noun identification result; performing element matching on the front segment noun identification result and the back segment noun identification result according to the front segment secondary segmentation result and the back segment secondary segmentation result, generating an operation area and an operation object, and constructing an SQL statement. The method solves the technical problem that the SQL statement element extraction complexity of the complex semantic recognition process in the prior art is high, resulting in a low processing accuracy.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of text recognition, and in particular to a method for converting text into SQL, a storage medium and an electronic device. Background Art

[0002] During the operation process, SQL databases need to combine text to perform a large number of operations such as query, update, delete or add. These operations require the input of SQL statements. Currently, the generation of SQL statements is mainly manually written according to needs. However, due to the increasing demand for SQL statements, manual writing is difficult to meet the needs. Although the text recognition model can realize automatic recognition of instructions, the high complexity of SQL statement element extraction in the complex semantic recognition process leads to the problem of low processing accuracy. Summary of the invention

[0003] The present invention aims at the technical problem in the prior art that the extraction of SQL statement elements in a complex semantic recognition process is highly complex, resulting in low processing accuracy. Aiming at the SQL text conversion scenario in which the most common operation vocabulary is located in the middle of the sentence, the present invention provides a method for converting text into SQL, a storage medium and an electronic device to solve the problem.

[0004] The technical solution of the present invention to solve the above technical problems is as follows:

[0005] In a first aspect, the present invention provides a method for converting text into SQL, comprising:

[0006] Receiving a text sentence to be identified, and traversing the text sentence to be identified from the beginning to the end according to the semantic comparison component and the operation description vocabulary set to obtain a keyword identification result;

[0007] When the keyword identification result is not located at both ends of the text sentence to be identified, the text sentence to be identified is divided into two segments using the keyword identification result as a segmentation point to obtain a front segment of the text sentence to be identified and a back segment of the text sentence to be identified;

[0008] Through a noun extraction network, nouns are extracted from the first segment of the text sentence to be recognized and the second segment of the text sentence to be recognized, to obtain a first segment noun identification result and a second segment noun identification result;

[0009] Segment the preceding paragraph of the text sentence to be recognized according to the preceding paragraph noun identification result to obtain the preceding paragraph secondary segmentation result;

[0010] Segmenting the text sentence to be recognized in the latter segment according to the noun identification result in the latter segment to obtain a secondary segmentation result in the latter segment;

[0011] According to the first-stage secondary segmentation result and the second-stage secondary segmentation result, element matching is performed on the first-stage noun identification result and the second-stage noun identification result to generate an operation area and an operation object;

[0012] According to the keyword identification result, the operation area and the operation object, in combination with the SQL statement template, an SQL statement is constructed and returned to the user end.

[0013] In a second aspect, the present application provides an electronic device, including:

[0014] Memory for storing computer software programs;

[0015] The processor is used to read and execute the computer software program, thereby implementing the method of converting text into SQL as described in any one of the first aspects.

[0016] In a third aspect, the present application provides a non-transitory computer-readable storage medium, wherein the storage medium stores a computer software program, and when the computer software program is executed by a processor, the method for converting text into SQL as described in any one of the first aspects is implemented.

[0017] The beneficial effects of the present invention are as follows: by providing a receiving text sentence to be recognized, according to a semantic comparison component, combined with an operation description vocabulary set, the text sentence to be recognized is traversed from the beginning to the end to obtain a keyword identification result; when the keyword identification result is not at both ends of the text sentence to be recognized, the text sentence to be recognized is divided into two segments with the keyword identification result as a segmentation point to obtain a front segment text sentence to be recognized and a back segment text sentence to be recognized; through a noun extraction network, nouns are extracted from the front segment text sentence to be recognized and the back segment text sentence to be recognized to obtain a front segment noun identification result and a back segment noun identification result; the front segment text sentence to be recognized is segmented according to the front segment noun identification result to obtain a front segment secondary segmentation result; according to the back segment noun identification result, the front segment text sentence to be recognized is segmented The back-end text sentence to be recognized is segmented to obtain the back-end secondary segmentation result; the front-end noun identification result and the back-end noun identification result are element-matched according to the front-end secondary segmentation result and the back-end secondary segmentation result to generate an operation area and an operation object; according to the keyword identification result, the operation area and the operation object, in combination with an SQL statement template, a technical solution is constructed to return an SQL statement to the user end, firstly, the text sentence to be recognized is segmented into five parts: keywords, front-end secondary segmentation results, back-end secondary segmentation results, front-end noun identification results, and back-end noun identification results. The five parts all have special labels and are not simply divided into subdivision units, which reduces the complexity of element matching and achieves the technical effect of improving processing accuracy. BRIEF DESCRIPTION OF THE DRAWINGS

[0018] Figure 1A flowchart of a method for converting text into SQL provided by the present invention;

[0019] Figure 2 A schematic diagram of a flow chart of obtaining a primary keyword identification result of a method for converting text into SQL provided by the present invention;

[0020] Figure 3 A schematic diagram of the structure of an electronic device provided by the present invention;

[0021] Figure 4 A schematic diagram of the structure of a computer-readable storage medium provided by the present invention.

[0022] In the accompanying drawings, the components represented by the reference numerals are listed as follows:

[0023] Electronic device 500 , memory 510 , processor 520 , computer program 511 , computer readable storage medium 600 , computer program 611 . DETAILED DESCRIPTION

[0024] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative work are within the scope of protection of the present invention.

[0025] In the description of the present invention, the terms "first" and "second" are used for descriptive purposes only and should not be understood as indicating or implying relative importance or implicitly indicating the number of the indicated technical features. Thus, the features defined as "first" and "second" may explicitly or implicitly include one or more of the features. In the description of the present invention, the meaning of "plurality" is two or more, unless otherwise clearly and specifically defined.

[0026] In the description of the present invention, the term "for example" is used to mean "used as an example, illustration or explanation". Any embodiment described as "for example" in the present invention is not necessarily to be construed as being more preferred or advantageous than other embodiments. The following description is given to enable any technician in the field to implement and use the present invention. In the following description, details are listed for the purpose of explanation. It should be understood that a person of ordinary skill in the art can recognize that the present invention can be implemented without using these specific details. In other examples, well-known structures and processes will not be elaborated in detail to avoid obscuring the description of the present invention with unnecessary details. Therefore, the present invention is not intended to be limited to the embodiments shown, but is consistent with the widest scope consistent with the principles and features disclosed in the present invention.

[0027] Embodiment 1:

[0028] like Figure 1 As shown, the embodiment of the present invention provides a method for converting text into SQL, comprising the steps of:

[0029] S10: receiving a text sentence to be identified, and traversing the text sentence to be identified from the beginning to the end according to the semantic comparison component and the operation description vocabulary set to obtain a keyword identification result;

[0030] Further, receiving the text sentence to be recognized, step S10 includes the steps of:

[0031] S11: Obtaining a file to be identified, wherein the file to be identified includes an editable file and a picture file;

[0032] S12: Segment the editable file to obtain a first set of text sentences to be recognized;

[0033] S13: After performing OCR extraction on the image file, perform sentence segmentation to obtain a second set of text sentences to be recognized; wherein the text sentence to be recognized is any text sentence in the first set of text sentences to be recognized and the second set of text sentences to be recognized; wherein sentence segmentation refers to segmentation based on preset segmentation symbols.

[0034] In the embodiment of the present application, the text sentence to be identified is the basic text from which the SQL statement needs to be extracted. Preferably, the acquisition method is as follows:

[0035] The user uploads the file to be recognized that contains the text to be recognized. The file includes editable files and non-editable image files. The editable files include but are not limited to tables, word documents, etc. Such files can directly perform sentence segmentation on the text to obtain a first set of text sentences to be recognized. For non-editable image files, it is necessary to use OCR technology to scan the image to obtain editable text content, and perform sentence segmentation on the editable text content to obtain a second set of text sentences to be recognized. Sentence segmentation refers to segmentation based on preset punctuation symbols, that is, segmentation is performed when a preset punctuation symbol is encountered. Preferably, the punctuation symbols include but are not limited to: period, semicolon, line break, etc.

[0036] The semantic comparison component selects the keyword position and keyword type of the SQL operation from the text sentence to be identified and stores them as the keyword identification result. The preferred process is as follows: through the user-preset operation description vocabulary set, including but not limited to: delete, store, update, add, query and other description vocabulary. The semantic comparison component can perform semantic recognition on the text sentence to be identified based on the operation description vocabulary set and extract the corresponding keyword data.

[0037] S20: When the keyword identification result is not located at both ends of the text sentence to be identified, the text sentence to be identified is divided into two segments using the keyword identification result as a segmentation point to obtain a front segment of the text sentence to be identified and a back segment of the text sentence to be identified;

[0038] The text sentences to be identified in the embodiment of the present application are limited to the sentence structure with the keyword in the middle, exemplarily: adding C's D to A's B. It cannot be applied to other sentence structures with keywords at both ends, for example: adding C's D to A's B. Since most of the sentence keywords are in the middle and fewer are at the two ends, this application does not consider them and can be processed in the traditional way. Therefore, if they are at the two ends, they are processed in the traditional way. If they are not at the two ends of the text sentence to be identified, continue to execute the steps of this application.

[0039] In the embodiment of the present application, the first segment of the text sentence to be identified is the text sequence before the keyword identification result; the second segment of the text sentence to be identified is the text sequence after the keyword identification result. For example, add D of C in B of A. The keyword is addition, position number 6 to number 7, so the first segment of the text sentence to be identified is numbered 1 to 5: in B of A, and the second segment of the text sentence to be identified is numbered 8 to 10: D of C.

[0040] S30: extracting nouns from the first segment of the text sentence to be recognized and the second segment of the text sentence to be recognized through a noun extraction network to obtain a first segment noun identification result and a second segment noun identification result;

[0041] Further, noun extraction is performed on the first segment of the text sentence to be recognized and the second segment of the text sentence to be recognized through a noun extraction network to obtain a first segment noun identification result and a second segment noun identification result. The previous step S30 includes the steps of:

[0042] S31: collecting a training sentence data set, wherein the training sentence data set has a noun identification array;

[0043] S32: Using the hit rate of noun identification data as a loss function, using the noun identification array as supervision, and using the training sentence data set as input, a neural network is configured to generate the noun extraction network.

[0044] In the embodiment of the present application, the noun identification result of the first segment refers to the field whose part of speech is a noun in the first segment of the text sentence to be identified; the noun identification result of the second segment refers to the field whose part of speech is a noun in the second segment of the text sentence to be identified. Exemplarily: the first segment of the text sentence to be identified in the above example: in B of A, the noun identification result of the first segment is the characters of sequence number 2 and sequence number 4: A, B; the second segment of the text sentence to be identified in the above example: D of C, the noun identification result of the second segment is the characters of sequence number 8 and sequence number 10: C, D. Since part of speech recognition is performed here, a noun extraction network based on hidden Markov model or recurrent neural network training can be used to realize the extraction of text nouns. Preferably, in order to make the noun extraction network more suitable for noun recognition in the embodiment of the present application, a data set of text sentences to be identified is obtained through expert compilation or historical data collection, which is set as a training sentence data set; then the nouns in the training sentence data set are marked as an array and stored as a noun identification array. The hit rate of noun identification data is used as a loss function, the noun identification array is used as supervision, and the training sentence data set is used as input to configure a hidden Markov model or a recurrent neural network. When the loss function is greater than or equal to the hit rate threshold for a preset number of consecutive times, the noun extraction network is generated. The traditional model is trained by local data to ensure the hit rate of noun extraction, thereby improving the extraction accuracy of the front-end noun identification results and the back-end noun identification results.

[0045] S40: Segmenting the preceding paragraph of the text sentence to be recognized according to the preceding paragraph noun identification result to obtain the preceding paragraph secondary segmentation result;

[0046] S50: Segmenting the text sentence to be recognized in the latter segment according to the noun identification result in the latter segment to obtain a secondary segmentation result in the latter segment;

[0047] In the embodiment of the present application, the second-level segmentation result of the first segment refers to the result of segmenting the first segment text sentence to be recognized with the result of the first segment noun identification as the splitting node, and the above example is continued to illustrate: the first segment text sentence to be recognized is in A's B, and the first segment noun identification result is A, B, then the second-level segmentation result of the first segment is character number 1: in, character number 3: of, and character number 5: in. The second-level segmentation result of the second segment refers to the result of segmenting the second segment text sentence to be recognized with the result of the second segment noun identification as the splitting node, and the above example is continued to illustrate: the second segment text sentence to be recognized is: C's D, and the second segment noun identification result is characters number 8 and number 10: C, D, then the second-level segmentation result of the second segment is character number 9: of. The second-level segmentation result of the first segment and the second-level segmentation result of the second segment are stored, waiting for the next step to call.

[0048] S60: performing element matching on the front segment noun identification result and the back segment noun identification result according to the front segment secondary segmentation result and the back segment secondary segmentation result, and generating an operation area and an operation object;

[0049] Further, according to the first-stage secondary segmentation result and the second-stage secondary segmentation result, the first-stage noun identification result and the second-stage noun identification result are element-matched to generate an operation area and an operation object. Step S60 includes the following steps:

[0050] S61: When the preceding noun identification result is one:

[0051] S62: Obtain a semantic identification component, wherein the semantic identification component is used to identify positive semantics or negative semantics, wherein the positive semantics represents the entire manipulated object, and the negative semantics represents a part of the manipulated object; wherein the semantic identification component has a positive feature word set and a negative feature word set;

[0052] S63: Based on the positive feature word set and the negative feature word set, the front-end secondary segmentation result is marked to obtain a semantic type mark;

[0053] S64: When the semantic type identification belongs to the positive semantics, the first segment noun identification result is identified as the operation object, and it is determined whether the second segment noun identification result is multiple;

[0054] S65: when the identification result of the latter noun is one, setting the identification result of the latter noun as the operation area;

[0055] S66: When the number of the identification results of the latter noun is multiple:

[0056] S661: based on the starting noun of the latter noun identification result to the ending noun of the latter noun identification result, extracting a first characteristic word segment from the text sentence to be identified;

[0057] S662: Process the first feature word segment through a description object recognition network, extract a first description object, and use the first description object to replace the latter noun identification result.

[0058] In the embodiment of the present application, the operation area refers to the subject to be queried, deleted, updated, or added, such as a database to which data needs to be added. The operation object refers to the specific content to be queried, deleted, updated, or added, such as the data to be added. The optimal process for element matching is as follows:

[0059] When the preceding noun identification result is one:

[0060] Step 1: Activate the semantic identification component that stores the positive feature word set and the negative feature word set. The positive semantic representation manipulates the object as a whole. For example, the sentence structure is: will + A, put + A. The service objects of will and put are A as a whole, then from and to are positive semantic feature words. The negative semantic representation manipulates the object partially. For example, the sentence structure is: from + A, to + A. The service objects of from and to are some content inside A, then from and to are negative semantic feature words.

[0061] Step 2: Based on the positive feature word set and the negative feature word set, perform semantic similarity analysis on each word in the previous secondary segmentation result to obtain the feature word with the maximum semantic similarity, and set the positive semantic label or negative semantic label of the feature word as the semantic type identifier. The semantic similarity preferably adopts cosine similarity.

[0062] Step 3: The semantic type identification belongs to the positive semantics, and the identification result of the preceding noun is identified as the operation object. This is because the simplest example is: insert A into ..., and it can be seen that A is the operation object.

[0063] Step 4: When the result of the subsequent noun identification is one, it must be the service area, and the subsequent noun identification result is set as the operation area.

[0064] Step 5: When there are multiple noun identification results for the latter segment, there may be two nouns at this time, such as C and D in the above example. At this time, based on the starting noun of the latter segment noun identification result to the end noun of the latter segment noun identification result, the first feature segment is intercepted from the text sentence to be identified, that is, C~D, that is, the segments with sequence numbers 8~10, that is, D of C. At this time, the first feature segment can be processed through the description object recognition network, the first description object can be extracted, and the latter segment noun identification result can be replaced with the first description object. After replacement, there is only one latter segment noun identification result, and the latter segment noun identification result can be directly set as the operation area. The description object recognition network is a text model for identifying the core of multiple compound sentences. Preferably, a compound noun text is constructed, a description object data set is identified, and a loss function is used to train the recurrent neural network with the output deviation frequency ratio trained for a preset number of times to obtain a description object recognition network. This application is only an exemplary description, and such a model has existing technology for use, which will not be elaborated here.

[0065] Furthermore, the method further comprises step S67, wherein step S67 further comprises the steps of:

[0066] S671: When the preceding noun identification result is multiple:

[0067] S672: based on the starting noun of the preceding noun identification result to the ending noun of the preceding noun identification result, extracting a second characteristic word segment from the text sentence to be identified;

[0068] S673: Process the second feature word segment through a description object recognition network, extract a second description object, and use the second description object to replace the previous noun identification result.

[0069] On the other hand, when there are multiple preceding noun identification results, a second characteristic word segment is intercepted from the text sentence to be identified based on the starting noun of the preceding noun identification result to the ending noun of the preceding noun identification result. The second characteristic word segment is processed through the description object recognition network to extract the second description object, and the preceding noun identification result is replaced with the second description object, and then steps 1 to 5 are continued.

[0070] S70: Constructing an SQL statement based on the keyword identification result, the operation area and the operation object in combination with an SQL statement template and returning it to the user end.

[0071] In the embodiment of the present application, the SQL statement template mainly includes a deletion template, a query template, an update template, and an addition template. The user can customize the settings according to the needs, and then insert the keyword identification result, the operation area and the operation object to obtain the SQL statement, which will be returned to the user end, eliminating the need for user editing and improving efficiency.

[0072] Further, according to the semantic comparison component, combined with the operation description vocabulary set, the text sentence to be identified is traversed from the beginning to the end to obtain the keyword identification result, and step S10 includes the steps of:

[0073] S141: The semantic comparison component includes a primary comparison channel and a secondary comparison channel;

[0074] S142: traversing the operation description vocabulary set, combining the text sentence to be identified, inputting the first-level comparison channel, and obtaining a first-level keyword identification result;

[0075] S143: deleting the primary keyword identification result from the text sentence to be recognized, and generating a reconstructed text sentence to be recognized;

[0076] S144: traversing the operation description vocabulary set, combining the to-be-reconstructed text sentence, inputting the secondary comparison channel, and obtaining a secondary keyword identification result;

[0077] S145: Add the primary keyword identification result and the secondary keyword identification result into the keyword identification result.

[0078] In the embodiment of the present application, the semantic comparison component is mainly used to determine whether the text sentence to be identified has an operation description vocabulary according to the operation description vocabulary set, and output a model of the operation description vocabulary type and the operation description word position.

[0079] Preferably, the semantic comparison component includes a primary comparison channel and a secondary comparison channel.

[0080] The first-level comparison channel is a calculation module for calculating the Hamming distance between the operation description vocabulary and each vocabulary of the text sentence to be recognized, preferably as follows:

[0081] Further, such as Figure 2 As shown, the operation description vocabulary set is traversed, combined with the text sentence to be identified, input into the primary comparison channel, and the primary keyword identification result is obtained. Step S142 includes the following steps:

[0082] S1421: extracting a first operation description vocabulary according to the operation description vocabulary set;

[0083] S1422: According to the first operation description vocabulary, perform Hamming distance calculation on the to-be-recognized text sentence from the beginning to the end through the first-level comparison channel to obtain a plurality of Hamming distance calculation results;

[0084] S1423: Extract the comparison words that are equal to 0 from the plurality of Hamming distance calculation results, and set them as the first-level keyword identification results.

[0085] Specifically, extract the first operation description vocabulary from the operation description vocabulary set, for example, delete, query, update, add, etc. According to the first operation description vocabulary, traverse the text sentence to be identified from the beginning to the end through the first-level comparison channel, perform Hamming distance calculation with each vocabulary of the text sentence to be identified, and obtain a number of Hamming distance calculation results; extract the comparison vocabulary equal to 0 from the several Hamming distance calculation results, and set it as the first-level keyword identification result. When it is equal to 0, it means that the vocabulary is exactly the same. At this time, there is no need to perform the semantic analysis in the next step, and it is directly set as the first-level keyword identification result, and continue to traverse other operation description vocabulary until the traversal is completed, and output the first-level keyword identification result.

[0086] The secondary comparison channel is mainly used to analyze the semantic similarity between the operation description vocabulary and the text vocabulary. The preferred process is as follows:

[0087] Further, the operation description vocabulary set is traversed, combined with the reconstructed text sentence to be identified, input into the secondary comparison channel, and the secondary keyword identification result is obtained. Step S144 includes the following steps:

[0088] S1441: Construct secondary alignment function:

[0089] ,

[0090] in, Represents any operation description vocabulary, Represents any word extracted from the text sentence to be identified and reconstructed, Represents semantic similarity, Represents cosine similarity, represents the Hamming distance, k represents the weight change rate adjustment coefficient, and c represents the center value of the Hamming distance;

[0091] S1442: extracting a first operation description vocabulary according to the operation description vocabulary set;

[0092] S1443: According to the secondary comparison function and the first operation description vocabulary, the reconstructed text sentence to be identified is traversed to compare from the beginning to the end to obtain a plurality of semantic similarity evaluation values;

[0093] S1444: extracting the plurality of comparison words whose semantic similarity evaluation values ​​are greater than or equal to the semantic similarity threshold, and adding them into the secondary keyword identification result.

[0094] Specifically, in order to prevent the identified keywords from affecting the processing of the secondary comparison channel, the primary keyword identification result is deleted from the text sentence to be identified to generate a reconstructed text sentence to be identified. Construct the secondary comparison function: ,in, Represents any operation description vocabulary, Represents any word extracted from the text sentence to be identified and reconstructed, Represents semantic similarity, Represents cosine similarity, represents the Hamming distance, k represents the weight change rate adjustment coefficient, and c represents the center value of the Hamming distance. This formula represents that when the Hamming distance is larger, the weight of the Hamming distance is smaller, and the weight of the cosine similarity is larger. According to the operation description vocabulary set, the first operation description vocabulary is extracted, and according to the secondary comparison function and the first operation description vocabulary, the reconstructed text sentence to be identified is traversed from the beginning to the end to extract multiple vocabulary for comparison, and several semantic similarity evaluation values ​​are obtained. Several comparison words with semantic similarity evaluation values ​​greater than or equal to the semantic similarity threshold are extracted, added to the secondary keyword identification result, and then other operation description words are continued to be traversed. When the operation description vocabulary set is traversed, the secondary keyword identification result is output. Finally, the primary keyword identification result and the secondary keyword identification result are added to the keyword identification result for output. Extracting keywords through two-level channels reduces the amount of data transmitted to the secondary comparison channel with higher computational complexity, reduces the computational pressure, and ensures processing efficiency.

[0095] In summary, the method for converting text into SQL provided in the embodiment of the present application has at least the following technical effects:

[0096] By providing and receiving a text sentence to be recognized, traversing the text sentence to be recognized from the beginning to the end according to a semantic comparison component and an operation description vocabulary set, a keyword identification result is obtained; when the keyword identification result is not at both ends of the text sentence to be recognized, the text sentence to be recognized is divided into two segments with the keyword identification result as a segmentation point, so as to obtain a front segment text sentence to be recognized and a back segment text sentence to be recognized; performing noun extraction on the front segment text sentence to be recognized and the back segment text sentence to be recognized through a noun extraction network, so as to obtain a front segment noun identification result and a back segment noun identification result; segmenting the front segment text sentence to be recognized according to the front segment noun identification result, so as to obtain a front segment secondary segmentation result; segmenting the back segment text sentence to be recognized according to the back segment noun identification result. Identify text sentences and segment them to obtain the second-level segmentation results of the latter segment; perform element matching on the first-segment noun identification results and the second-segment noun identification results according to the first-segment second-level segmentation results and the second-segment second-level segmentation results to generate an operation area and an operation object; and construct a technical solution to return an SQL statement to the user end based on the keyword identification results, the operation area and the operation object in combination with an SQL statement template. First, the text sentence to be identified is segmented into five parts: keywords, first-segment second-level segmentation results, second-segment second-level segmentation results, first-segment noun identification results, and second-segment noun identification results. All five parts have special labels and are not simply divided into subdivided units, which reduces the complexity of element matching and achieves the technical effect of improving processing accuracy.

[0097] Embodiment 2:

[0098] See also Figure 3 , Figure 3 Schematic diagram of an electronic device provided by an embodiment of the present invention. Figure 3 As shown, an embodiment of the present invention provides an electronic device 500, including a memory 510, a processor 520, and a computer program 511 stored in the memory 510 and executable on the processor 520. When the processor 520 executes the computer program 511, the following steps are implemented:

[0099] Receiving a text sentence to be identified, and traversing the text sentence to be identified from the beginning to the end according to the semantic comparison component and the operation description vocabulary set to obtain a keyword identification result;

[0100] When the keyword identification result is not located at both ends of the text sentence to be identified, the text sentence to be identified is divided into two segments using the keyword identification result as a segmentation point to obtain a front segment of the text sentence to be identified and a back segment of the text sentence to be identified;

[0101] Through a noun extraction network, nouns are extracted from the first segment of the text sentence to be recognized and the second segment of the text sentence to be recognized, to obtain a first segment noun identification result and a second segment noun identification result;

[0102] Segment the preceding paragraph of the text sentence to be recognized according to the preceding paragraph noun identification result to obtain the preceding paragraph secondary segmentation result;

[0103] Segmenting the text sentence to be recognized in the latter segment according to the noun identification result in the latter segment to obtain a secondary segmentation result in the latter segment;

[0104] According to the first-stage secondary segmentation result and the second-stage secondary segmentation result, element matching is performed on the first-stage noun identification result and the second-stage noun identification result to generate an operation area and an operation object;

[0105] According to the keyword identification result, the operation area and the operation object, in combination with the SQL statement template, an SQL statement is constructed and returned to the user end.

[0106] Embodiment three:

[0107] See also Figure 4 , Figure 4 Schematic diagram of an embodiment of a computer-readable storage medium provided by an embodiment of the present invention. Figure 4 As shown, this embodiment provides a computer-readable storage medium 600, on which a computer program 611 is stored. When the computer program 611 is executed by a processor, the following steps are implemented:

[0108] Receiving a text sentence to be identified, and traversing the text sentence to be identified from the beginning to the end according to the semantic comparison component and the operation description vocabulary set to obtain a keyword identification result;

[0109] When the keyword identification result is not located at both ends of the text sentence to be identified, the text sentence to be identified is divided into two segments using the keyword identification result as a segmentation point to obtain a front segment of the text sentence to be identified and a back segment of the text sentence to be identified;

[0110] Through a noun extraction network, nouns are extracted from the first segment of the text sentence to be recognized and the second segment of the text sentence to be recognized, to obtain a first segment noun identification result and a second segment noun identification result;

[0111] Segment the preceding paragraph of the text sentence to be recognized according to the preceding paragraph noun identification result to obtain the preceding paragraph secondary segmentation result;

[0112] Segmenting the text sentence to be recognized in the latter segment according to the noun identification result in the latter segment to obtain a secondary segmentation result in the latter segment;

[0113] According to the first-stage secondary segmentation result and the second-stage secondary segmentation result, element matching is performed on the first-stage noun identification result and the second-stage noun identification result to generate an operation area and an operation object;

[0114] According to the keyword identification result, the operation area and the operation object, in combination with the SQL statement template, an SQL statement is constructed and returned to the user end.

[0115] It should be noted that in the above embodiments, the description of each embodiment has its own emphasis, and for parts that are not described in detail in a certain embodiment, reference can be made to the relevant descriptions of other embodiments.

[0116] It will be appreciated by those skilled in the art that embodiments of the present invention may be provided as methods, systems, or computer program products. Therefore, the present invention may take the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware. Furthermore, the present invention 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, CD-ROM, optical storage, etc.) containing computer-usable program code.

[0117] The present invention is described with reference to flowcharts and / or block diagrams of methods, devices (systems), and computer program products according to embodiments of the present invention. It should be understood that each process and / or block in the flowchart and / or block diagram, as well as the combination of processes and / or blocks 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 computer, or other programmable data processing device to produce 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.

[0118] 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.

[0119] 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 in the computer or other programmable device. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.

[0120] Although preferred embodiments of the present invention have been described, additional changes and modifications may occur to these embodiments once those skilled in the art understand the basic inventive concepts.

[0121] Obviously, those skilled in the art can make various changes and modifications to the present invention without departing from the spirit and scope of the present invention. Thus, if these modifications and variations of the present invention belong to the scope of the present invention and its equivalent technologies, the present invention is also intended to include these changes and variations.

Claims

1. A method for converting text into SQL, characterized in that: include: Receiving a text sentence to be identified, and traversing the text sentence to be identified from the beginning to the end according to the semantic comparison component and the operation description vocabulary set to obtain a keyword identification result; When the keyword identification result is not located at both ends of the text sentence to be identified, the text sentence to be identified is divided into two segments with the keyword identification result as a segmentation point to obtain a front segment of the text sentence to be identified and a back segment of the text sentence to be identified, and the keyword identification result does not belong to the front segment of the text sentence to be identified and the back segment of the text sentence to be identified; Through a noun extraction network, nouns are extracted from the first segment of the text sentence to be recognized and the second segment of the text sentence to be recognized, to obtain a first segment noun identification result and a second segment noun identification result; Segment the preceding paragraph of the text sentence to be recognized according to the preceding paragraph noun identification result to obtain the preceding paragraph secondary segmentation result; Segmenting the text sentence to be recognized in the latter segment according to the noun identification result in the latter segment to obtain a secondary segmentation result in the latter segment; According to the first-stage secondary segmentation result and the second-stage secondary segmentation result, the first-stage noun identification result and the second-stage noun identification result are matched with each other to generate an operation area and an operation object, wherein the operation area refers to a subject to be queried, deleted, updated, or added, and the operation object refers to the specific content to be queried, deleted, updated, or added; According to the keyword identification result, the operation area and the operation object, in combination with an SQL statement template, an SQL statement is constructed and returned to the user end, wherein the keyword identification result represents the operation description vocabulary.

2. The method according to claim 1, characterized in that Receive the text sentence to be recognized, including: Obtaining a file to be identified, wherein the file to be identified includes an editable file and a picture file; Segmenting the editable file to obtain a first set of text sentences to be recognized; After performing OCR extraction on the image file, perform sentence segmentation to obtain a second set of text sentences to be recognized; The text sentence to be recognized is any text sentence in the first set of text sentences to be recognized and the second set of text sentences to be recognized; Among them, sentence segmentation refers to segmentation based on preset sentence segmentation symbols.

3. The method according to claim 1, characterized in that According to the semantic comparison component, combined with the operation description vocabulary set, the text sentence to be identified is traversed from the beginning to the end to obtain the keyword identification result, including: The semantic comparison component includes a primary comparison channel and a secondary comparison channel; Traversing the operation description vocabulary set, combining the text sentence to be identified, inputting the first-level comparison channel, and obtaining a first-level keyword identification result; Deleting the primary keyword identification result from the text sentence to be identified to generate a reconstructed text sentence to be identified; Traversing the operation description vocabulary set, combining the to-be-reconstructed text sentence, inputting the secondary comparison channel, and obtaining a secondary keyword identification result; The first-level keyword identification result and the second-level keyword identification result are added to the keyword identification result.

4. The method according to claim 3, characterized in that Traversing the operation description vocabulary set, combining the text sentence to be identified, inputting the primary comparison channel, and obtaining the primary keyword identification result, including: Extracting a first operation description vocabulary according to the operation description vocabulary set; According to the first operation description vocabulary, the text sentence to be identified is traversed from the beginning to the end through the first-level comparison channel to perform Hamming distance calculation to obtain a plurality of Hamming distance calculation results; The comparison words equal to 0 in the plurality of Hamming distance calculation results are extracted and set as the first-level keyword identification results.

5. The method according to claim 3, characterized in that Traversing the operation description vocabulary set, combining the to-be-identified reconstructed text sentence, inputting the secondary comparison channel, and obtaining the secondary keyword identification result, including: Construct the secondary alignment function: , in, Represents any operation description vocabulary, Represents any word extracted from the text sentence to be identified and reconstructed, Represents semantic similarity, Represents cosine similarity, represents the Hamming distance, k represents the weight change rate adjustment coefficient, and c represents the center value of the Hamming distance; Extracting a first operation description vocabulary according to the operation description vocabulary set; According to the secondary comparison function and the first operation description vocabulary, the to-be-identified reconstructed text sentences are traversed to compare from the beginning to the end to obtain a plurality of semantic similarity evaluation values; The plurality of comparison words whose semantic similarity evaluation values ​​are greater than or equal to the semantic similarity threshold are extracted and added into the secondary keyword identification result.

6. The method according to claim 1, characterized in that Through the noun extraction network, nouns are extracted from the first segment of the text sentence to be recognized and the second segment of the text sentence to be recognized, and the first segment noun identification result and the second segment noun identification result are obtained, which includes: Collecting a training sentence data set, wherein the training sentence data set has a noun identification array; The hit rate of noun identification data is used as a loss function, the noun identification array is used as supervision, and the training sentence data set is used as input to configure a neural network to generate the noun extraction network.

7. The method according to claim 1, characterized in that According to the first-stage secondary segmentation result and the second-stage secondary segmentation result, the first-stage noun identification result and the second-stage noun identification result are matched with each other to generate an operation area and an operation object, including: When the preceding noun identification result is one: Obtaining a semantic identification component, wherein the semantic identification component is used to identify positive semantics or negative semantics, the positive semantics represents the entire manipulated object, and the negative semantics represents a part of the manipulated object; Wherein, the semantic identification component has a positive feature word set and a negative feature word set; Based on the positive feature word set and the negative feature word set, the front-end secondary segmentation result is marked to obtain a semantic type mark; When the semantic type identification belongs to the positive semantics, the first segment noun identification result is identified as the operation object, and it is determined whether the second segment noun identification result is multiple; When the identification result of the latter noun is one, setting the identification result of the latter noun as the operation area; When the number of noun identifiers in the latter part is multiple: Based on the starting noun of the latter noun identification result to the ending noun of the latter noun identification result, extracting a first characteristic word segment from the text sentence to be identified; The first feature word segment is processed through a description object recognition network to extract a first description object, and the first description object is used to replace the latter noun identification result.

8. The method according to claim 7, characterized in that Also includes: When the preceding noun identification results are multiple: Based on the starting noun of the preceding noun identification result to the ending noun of the preceding noun identification result, extracting a second characteristic word segment from the text sentence to be identified; The second feature word segment is processed through a description object recognition network to extract a second description object, and the second description object is used to replace the noun identification result of the previous segment.

9. An electronic device, characterized in that: include: Memory for storing computer software programs; A processor is used to read and execute the computer software program, thereby implementing a method for converting text into SQL as described in any one of claims 1 to 8.

10. A non-transitory computer-readable storage medium, characterized in that: The storage medium stores a computer software program, and when the computer software program is executed by the processor, the method for converting text into SQL as described in any one of claims 1 to 8 is implemented.

Citation Information

Patent Citations

  • Configurable method and system for converting natural language into sql

    CN112347121A

  • Intelligent question and answer processing method and device, electronic equipment and storage medium

    CN115827819A