A processing method and device for converting natural language into structured query language

Through structured query language conversion and entity name mapping, it solves the problem of difficulty in filling in values ​​when converting natural language into SQL, improves conversion accuracy, and meets business query needs such as payment systems.

CN114090624BActive Publication Date: 2024-10-18THE PEOPLES BANK OF CHINA NAT CLEARING CENT
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202111376120.8
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-11-19
Publication Date
2024-10-18
Estimated Expiration
2041-11-19

AI Technical Summary

Technical Problem

In the existing technology, the value of query conditions cannot be effectively filled in when natural language is converted into structured query language (SQL), which is especially difficult in business queries applied to payment systems.

Method used

By obtaining the Chinese statement to be processed, performing structured query language conversion, extracting table fields, constructing entity key-value pairs, and using the pre-trained key-value pair extraction model to perform entity name mapping to realize value filling of SQL statements.

Benefits of technology

It improves the accuracy of converting natural language into SQL statements to meet the needs of business queries such as payment systems.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114090624B_ABST
    Figure CN114090624B_ABST
Patent Text Reader

Abstract

The present invention provides a processing method and device for converting natural language into structured query language, the method comprising: converting the acquired Chinese sentence to be processed into structured query language, obtaining a first structured query statement and extracting table fields, obtaining the table fields included in the first structured query statement; constructing a first entity key-value pair; obtaining a second entity key-value pair according to the Chinese sentence to be processed and the key-value pair extraction model; performing entity name mapping according to the first entity key-value pair and the second entity key-value pair, obtaining matching table fields and entity object names; obtaining a second structured query statement according to the first structured query statement and the matching table fields and entity object names. The device is used to execute the above method. The processing method and device for converting natural language into structured query language provided by the embodiment of the present invention improves the accuracy of converting natural language into SQL statements.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of natural language processing, and in particular to a processing method and device for converting natural language into structured query language. Background Art

[0002] Natural Language Processing (NLP) is an important direction in the fields of computer science and artificial intelligence. Natural Language Processing has been widely used in machine translation, opinion extraction, text classification, question answering, speech recognition, etc.

[0003] In the prior art, natural language has been converted into Structured Query Language (SQL) statements. Current research on algorithms for converting natural language into SQL statements mainly focuses on methods for filling in values ​​without values. Filling in values ​​for NL2SQL is a relatively difficult problem. Industrializing NL2SQL requires filling in values. How to implement value filling for NL2SQL is an important issue that needs to be solved in this field. Summary of the invention

[0004] In view of the problems in the prior art, an embodiment of the present invention provides a method and device for converting a natural language into a structured query language, which can at least partially solve the problems in the prior art.

[0005] On the one hand, the present invention provides a processing method for converting natural language into structured query language, comprising:

[0006] Acquire a Chinese sentence to be processed, and convert the Chinese sentence to be processed into a structured query language to obtain a first structured query sentence corresponding to the Chinese sentence to be processed;

[0007] Extracting table fields from the first structured query statement to obtain table fields included in the first structured query statement;

[0008] According to the entity and library table field name correspondence table and the table fields included in the first structured query statement, construct a first entity key-value pair corresponding to the first structured query statement, wherein the first entity key-value pair includes a table field and an entity name;

[0009] According to the Chinese sentence to be processed and the key-value pair extraction model, a second entity key-value pair corresponding to the Chinese sentence to be processed is obtained, wherein the second entity key-value pair includes an entity object name and an entity name; wherein the key-value pair extraction model is obtained by pre-training;

[0010] Performing entity name mapping according to the first entity key-value pair corresponding to the first structured query statement and the second entity key-value pair corresponding to the Chinese statement to be processed, to obtain matching table fields and entity object names;

[0011] According to the first structured query statement and the matching table fields and entity object names, a second structured query statement corresponding to the Chinese statement to be processed is obtained.

[0012] In another aspect, the present invention provides a processing device for converting a natural language into a structured query language, comprising:

[0013] An acquisition unit, configured to acquire a Chinese sentence to be processed, and perform structured query language conversion on the Chinese sentence to be processed to obtain a first structured query sentence corresponding to the Chinese sentence to be processed;

[0014] An extraction unit, configured to extract table fields from the first structured query statement to obtain table fields included in the first structured query statement;

[0015] A construction unit, configured to construct a first entity key-value pair corresponding to the first structured query statement according to a table of correspondence between entity and library table field names and table fields included in the first structured query statement, wherein the first entity key-value pair includes a table field and an entity name;

[0016] A first obtaining unit is used to obtain a second entity key-value pair corresponding to the Chinese sentence to be processed according to the Chinese sentence to be processed and the key-value pair extraction model, wherein the second entity key-value pair includes an entity object name and an entity name; wherein the key-value pair extraction model is obtained by pre-training;

[0017] A second obtaining unit is used to perform entity name mapping according to the first entity key-value pair corresponding to the first structured query statement and the second entity key-value pair corresponding to the Chinese statement to be processed, so as to obtain matching table fields and entity object names;

[0018] The third obtaining unit is used to obtain a second structured query statement corresponding to the Chinese statement to be processed according to the first structured query statement and the matching table fields and entity object names.

[0019] On the other hand, the present invention provides an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the program, the steps of the processing method for converting natural language into structured query language described in any of the above embodiments are implemented.

[0020] In yet another aspect, the present invention provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the steps of the method for converting a natural language into a structured query language as described in any of the above embodiments.

[0021] The processing method and device for converting natural language into structured query language provided by the embodiment of the present invention can obtain a Chinese statement to be processed, and convert the Chinese statement to be processed into structured query language, obtain a first structured query statement corresponding to the Chinese statement to be processed, extract table fields from the first structured query statement, obtain table fields included in the first structured query statement, construct a first entity key-value pair corresponding to the first structured query statement according to a corresponding relationship table between entity and library table field names and the table fields included in the first structured query statement, the first entity key-value pair including table fields and entity names, obtain a second entity key-value pair corresponding to the Chinese statement to be processed according to the Chinese statement to be processed and a key-value pair extraction model, perform entity name mapping according to the first entity key-value pair corresponding to the first structured query statement and the second entity key-value pair corresponding to the Chinese statement to be processed, obtain matching table fields and entity object names, obtain a second structured query statement corresponding to the Chinese statement to be processed according to the first structured query statement and the matching table fields and entity object names, implement value filling of SQL statements, and improve the accuracy of converting natural language into SQL statements. BRIEF DESCRIPTION OF THE DRAWINGS

[0022] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the following briefly introduces the drawings required for use in the embodiments or the prior art descriptions. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work. In the drawings:

[0023] Figure 1 It is a flowchart of a processing method for converting natural language into structured query language provided by the first embodiment of the present invention.

[0024] Figure 2 It is a flowchart of a processing method for converting natural language into structured query language provided by the second embodiment of the present invention.

[0025] Figure 3 It is a flowchart of a processing method for converting natural language into structured query language provided by the third embodiment of the present invention.

[0026] Figure 4 It is a schematic diagram of the structure of a processing device for converting natural language into structured query language provided by the fourth embodiment of the present invention.

[0027] Figure 5 It is a schematic diagram of the structure of a processing device for converting natural language into structured query language provided by the fifth embodiment of the present invention.

[0028] Figure 6 It is a schematic diagram of the structure of a processing device for converting natural language into structured query language provided by the sixth embodiment of the present invention.

[0029] Figure 7 It is a schematic diagram of the structure of a processing device for converting natural language into structured query language provided by the seventh embodiment of the present invention.

[0030] Figure 8 It is a schematic diagram of the structure of a processing device for converting natural language into structured query language provided by an eighth embodiment of the present invention.

[0031] Fig. 9 It is a schematic diagram of the physical structure of an electronic device provided by the ninth embodiment of the present invention. DETAILED DESCRIPTION

[0032] In order to make the purpose, technical scheme and advantages of the embodiments of the present invention more clear, the embodiments of the present invention are further described in detail below in conjunction with the accompanying drawings. Here, the illustrative embodiments of the present invention and their descriptions are used to explain the present invention, but are not intended to limit the present invention. It should be noted that, in the absence of conflict, the embodiments in this application and the features in the embodiments can be combined with each other arbitrarily.

[0033] In order to facilitate understanding of the technical solution provided by the present application, the relevant contents of the technical solution of the present application are first described below. When using Chinese statements to query payment services, it is impossible to fill in values ​​for query conditions when converting Chinese statements into SQL statements in the prior art. In order to apply NL2SQL to the payment system for business queries, an embodiment of the present invention proposes a processing method for converting natural language into structured query language, which can fill in values ​​for SQL converted from Chinese statements to meet the business query requirements of the payment system.

[0034] The following uses a server as an example to illustrate the implementation process of the method for converting natural language into structured query language provided by the embodiment of the present invention. It is understandable that the execution subject of the method for converting natural language into structured query language provided by the embodiment of the present invention is not limited to the server.

[0035] Figure 1 FIG. 1 is a flow chart of a method for converting a natural language into a structured query language according to a first embodiment of the present invention. Figure 1 As shown, the processing method for converting natural language into structured query language provided by the embodiment of the present invention includes:

[0036] S101, obtaining a Chinese sentence to be processed, and converting the Chinese sentence to be processed into a structured query language to obtain a first structured query sentence corresponding to the Chinese sentence to be processed;

[0037] Specifically, the server may obtain a Chinese statement to be processed, and then convert the Chinese statement to be processed into an SQL statement, so as to obtain a first structured query statement corresponding to the Chinese statement to be processed.

[0038] For example, a staff member can send a query request to a server through a client, and the server receives the query request and obtains the Chinese statement to be processed from the query request. The server can convert the Chinese statement to be processed into a first structured query statement corresponding to the Chinese statement to be processed through a conversion model, and the first structured query statement needs to be filled with values. The conversion model can be obtained by training the RAT-SQL (Relation-Aware Schema Encoding and Linking for Text-to-SQL Parsers) model without Value filling. The RAT-SQL model has high prediction accuracy for SQL structure and is suitable for complex SQL statements. For different technical fields, the conversion models obtained through training will be different. The specific training process of the conversion model is a prior art and will not be repeated here.

[0039] For example, the Chinese statement to be processed is: Query the number of transactions of small-amount payment services in the A city processing center on May 12, 2020. The above Chinese statement to be processed is converted into the corresponding first structured query statement through the conversion model supporting the payment system: SELECT*FROM PSASBEOT0101 WHERE RECVDATE NULL AND SENDSETTBKCCPC=NULL ORDER BY RECVTIME ASC.

[0040] S102: extracting table fields from the first structured query statement to obtain table fields included in the first structured query statement;

[0041] Specifically, after obtaining the first structured query statement corresponding to the Chinese sentence to be processed, the server may extract the table fields included in the first structured query statement from the first structured query statement to obtain the table fields included in the first structured query statement.

[0042] For example, for the first structured query statement: SELECT*FROM PSASBEOT0101 WHERE RECVDATENULL AND SENDSETTBKCCPC=NULL ORDER BY RECVTIME ASC, the table fields that can be extracted are RECVDATE and SENDSETTBKCCPC. When the structured query language is converted to the Chinese statement to be processed, a database table is used, and the table fields included in each database table can be used to match the table fields with each field in the first structured query statement to achieve the extraction of the table fields in the first structured query statement. Among them, the database table is preset.

[0043] S103: construct a first entity key-value pair corresponding to the first structured query statement according to the entity-library table field name correspondence table and the table fields included in the first structured query statement, wherein the first entity key-value pair includes a table field and an entity name;

[0044] Specifically, after obtaining the table fields included in the first structured query statement, the server matches the corresponding entity name in the entity and library table field name correspondence table according to each obtained table field, and constructs the first entity key-value pair corresponding to the first structured query statement through the matched table fields and entity names. The first entity key-value pair includes table fields and entity names, and only includes one table field and one entity pair, and the table fields and entity pairs in the first entity key-value pair match. The entity and library table field name correspondence table is preset, including each entity name and the matching rules corresponding to each entity name.

[0045] For example, for a payment system, based on the payment system metadata and data standard definitions, the table field classifications are summarized and defined, and the following entity and library table field name correspondence table can be obtained:

[0046] Table 1 Correspondence between entity and database table field names

[0047] Entity Name Entity name matching rules BNK The table field ends with BANK and ends with DRBK DAT The table fields end with DATE NOD The table fields end with CCPC PID The table fields are PKGNO, DTLTXSNO, PAYTXSNO, APLYSNO, MSGID AMT The table fields end with AMT FLG Table field is RPLYFLAG PST The table fields are QRYPROCFLAG,SETTSTAT MSG Table fields are MSGTYPE BIZ Table fields are BIZTYPE

[0048] For the table fields RECVDATE and SENDSETTBKCCPC, through the above Table 1, we can get that RECVDATE matches DAT, and SENDSETTBKCCPC matches NOD, so we can get two first entity key-value pairs.<RECVDATE,DAT> and<SENDSETTBKCCPC,NOD> .

[0049] S104. Obtain the second entity key-value pair corresponding to the Chinese sentence to be processed according to the Chinese sentence to be processed and the key-value pair extraction model. The second entity key-value pair includes an entity object name and an entity name. Among them, the key-value pair extraction model is pre-trained.

[0050] Specifically, after obtaining the Chinese sentence to be processed, the server inputs the Chinese sentence to be processed into the key-value pair extraction model, and can output the second entity key-value pair corresponding to the Chinese sentence to be processed. The second entity key-value pair corresponding to the Chinese sentence to be processed can be one second entity key-value pair, or two or more second entity key-value pairs. The second entity key-value pair includes an entity object name and an entity name, and the second entity key-value pair only includes one entity object name and one entity name, and the entity object name included in the second entity key-value pair matches the entity name. The entity object name is derived from the Chinese sentence to be processed, and the entity name is the classification label corresponding to the entity object name obtained through the key-value pair extraction model. Among them, the key-value pair extraction model is pre-trained.

[0051] For example, for the Chinese sentence to be processed: Query the number of transaction records of the small payment service at the processing center of City A on May 12, 2020. After inputting it into the key-value pair extraction model, the second entity key-value pair corresponding to the above Chinese sentence to be processed can be output as: <Processing center of City A, NOD> and <May 12, 2020, DAT>. The processing center of City A and May 12, 2020 are entity object names, and NOD and DAT are entity names.

[0052] S105. Perform entity name mapping according to the first entity key-value pair corresponding to the first structured query statement and the second entity key-value pair corresponding to the Chinese sentence to be processed, and obtain the matching table field and entity object name.

[0053] Specifically, for the first entity key-value pair corresponding to the first structured query statement, the server can query the same entity name in the second entity key-value pair corresponding to the Chinese sentence to be processed according to the entity name included in the first entity key-value pair. If the same entity name is found, the table field corresponding to the same entity name in the first entity key-value pair and the entity object name corresponding to the same entity name in the second entity key-value pair match. The server can obtain the matching table field and entity object name.

[0054] For example, the server obtains the first entity key-value pairs <RECVDATE, DAT> and <SENDSETTBKCCPC, NOD>, and the second entity key-value pairs <A City Processing Center, NOD> and <May 12, 2020, DAT>. According to the entity name DAT included in the first entity key-value pairs, the server queries for the same entity name DAT in the second entity key-value pairs. If the second entity key-value pair <May 12, 2020, DAT> with the same entity name DAT is found, then the table field RECVDATE matches the entity object name May 12, 2020. Similarly, it can be determined that the table field SENDSETTBKCCPC matches the entity object name A City Processing Center.

[0055] S106. Obtain a second structured query statement corresponding to the Chinese statement to be processed according to the matching table fields, entity object names, and the first structured query statement.

[0056] Specifically, the server queries for the same table fields in the first structured query statement according to each table field in the matching table fields and entity object names. If the same table fields are found, then the entity object names matching the same table fields are filled as the values corresponding to the same table fields in the first structured query statement. After completing the above value filling, the second structured query statement corresponding to the Chinese statement to be processed can be obtained.

[0057] For example, the first structured query statement is: SELECT*FROM PSASBEOT0101 WHERE RECVDATENULL AND SENDSETTBKCCPC=NULL ORDER BY RECVTIME ASC. The server obtains the table field RECVDATE that matches the entity object name May 12, 2020, and the table field SENDSETTBKCCPC matches the entity object name A City Processing Center. The server queries RECVDATE in the first structured query statement based on RECVDATE, and then replaces the NULL corresponding to RECVDATE in the first structured query statement with May 12, 2020, and queries SENDSETTBKCCPC in the first structured query statement based on SENDSETTBKCCPC, and then replaces the NULL corresponding to SENDSETTBKCCPC in the first structured query statement with A City Processing Center to implement the value filling of the first structured query statement. After completing the value filling, the corresponding second structured query statement is obtained: SELECT*FROMPSASBEOT0101 WHERE RECVDATE'May 12, 2020'AND SENDSETTBKCCPC='A City Processing Center' ORDER BY RECVTIME ASC.

[0058] The processing method for converting natural language into structured query language provided by the embodiment of the present invention can obtain a Chinese statement to be processed, and convert the Chinese statement to be processed into structured query language, obtain a first structured query statement corresponding to the Chinese statement to be processed, extract table fields from the first structured query statement, obtain table fields included in the first structured query statement, construct a first entity key-value pair corresponding to the first structured query statement according to a corresponding relationship table between entity and library table field names and the table fields included in the first structured query statement, the first entity key-value pair including table fields and entity names, obtain a second entity key-value pair corresponding to the Chinese statement to be processed according to the Chinese statement to be processed and a key-value pair extraction model, perform entity name mapping according to the first entity key-value pair corresponding to the first structured query statement and the second entity key-value pair corresponding to the Chinese statement to be processed, obtain matching table fields and entity object names, obtain a second structured query statement corresponding to the Chinese statement to be processed according to the first structured query statement and the matching table fields and entity object names, implement value filling of SQL statements, and improve the accuracy of converting natural language into SQL statements.

[0059] Figure 2 FIG. 1 is a flow chart of a method for converting a natural language into a structured query language according to a second embodiment of the present invention. Figure 2As shown, based on the above embodiments, further, obtaining the Chinese sentence to be processed includes:

[0060] S201, extracting entity names from the original Chinese sentence to obtain entity names in the original Chinese sentence;

[0061] Specifically, the server may perform named entity extraction on the original Chinese sentence through a named entity recognition (NER) method to obtain each entity name in the original Chinese sentence. One entity name may be extracted from the original Chinese sentence, or two or more implementation names may be extracted.

[0062] For example, a named entity extraction model can be obtained through training, and the trained named entity extraction model can be used to extract entity names from the original Chinese sentence. Entity name training data is constructed, and the entity name training data can include a set number of Chinese sentences and the entity name corresponding to each Chinese sentence. Model training is performed based on the above entity name training data and the initial model, and a named entity extraction model can be trained. The original Chinese sentence is used as the input of the named entity extraction model, and after being processed by the named entity extraction model, the entity names in the original Chinese sentence can be output. Among them, the set number is set according to actual needs, and the embodiment of the present invention is not limited. The initial model can adopt a neural network model, which is selected according to actual needs, and the embodiment of the present invention is not limited.

[0063] S202, obtaining a standardized name corresponding to each entity name according to each entity name in the original Chinese sentence and a standardized name library;

[0064] Specifically, after obtaining the entity name in the original Chinese sentence, the server queries the standardized name corresponding to each entity name from the standardized name library according to each entity name, and can obtain the standardized name corresponding to each entity name. The standardized name library is preset, including multiple standardized names, and is set according to actual experience, and is not limited in the embodiment of the present invention.

[0065] For example, the entity name can be converted into a word embedding by word2vec, and the standardized name in the standardized name library can be converted into a word embedding, and then the word embedding corresponding to the entity name and the word embedding of each standardized name in the standardized name library can be compared to obtain the standardized name corresponding to the most similar word embedding as the standardized name corresponding to the entity name. For the obtained entity name "ICBC", the standardized name corresponding to "ICBC" can be obtained in the standardized name library as "Industrial and Commercial Bank of China".

[0066] S203: Replace the entity names of the original Chinese sentence according to the standardized names corresponding to each entity name to obtain the Chinese sentence to be processed.

[0067] Specifically, the server replaces the entity names in the original Chinese sentence with the standardized names corresponding to each entity name, and the Chinese sentence to be processed can be obtained. Since the original Chinese sentence may contain abbreviations, abbreviations or aliases, by converting the entity names in the original Chinese sentence into standardized names, the subsequent processing of the Chinese sentence to be processed is facilitated.

[0068] Figure 3 FIG. 1 is a flow chart of a method for converting a natural language into a structured query language according to a third embodiment of the present invention. Figure 3 As shown, the steps of pre-training the key-value pair extraction model include:

[0069] S301, obtaining key-value pair training data, wherein the key-value pair training data includes various entity object names and entity names corresponding to each entity object name;

[0070] Specifically, various entity object names required for training the key-value pair extraction model can be collected, and entity names corresponding to each type of entity object name can be set. The server can obtain various entity object names and entity names corresponding to each type of entity object name as key-value pair training data. Among them, the entity name is set according to actual needs, and the embodiment of the present invention does not limit it.

[0071] For example, for the entity object names of the payment system, you can collect various entity object names according to the following table.

[0072] Table 2 Various entity objects and corresponding entity names

[0073]

[0074]

[0075] S302: According to the names of various entity objects, the entity names corresponding to each type of entity object name, and the initial model of the key-value pair, the key-value pair extraction model is trained to obtain the key-value pair extraction model.

[0076] Specifically, after obtaining various entity object names and entity names corresponding to each entity object name, the server performs model training according to the various entity object names, entity names corresponding to each entity object name and the key-value pair initial model, and the key-value pair extraction model can be trained. The key-value pair initial model is set according to actual needs, such as using a BERT (Bidirectional Encoder Representation from Transformers) model based on random spans, which is not limited in the embodiment of the present invention. The specific training process of the model is prior art and will not be described here.

[0077] For example, for a Chinese sentence to be processed: query the transaction amount today for the initiator Bank of China and the recipient China Merchants Bank. The second entity key-value pair corresponding to the Chinese sentence to be processed can be obtained through the key-value pair extraction model as: <Bank of China, SENDBNK> and <China Merchants Bank, RECEIVEBNK>.

[0078] On the basis of the above embodiments, further, entity name mapping is performed according to the first entity key-value pair corresponding to the first structured query statement and the second entity key-value pair corresponding to the Chinese statement to be processed, and the matching table fields and entity object names are obtained, including:

[0079] If it is determined that the entity name included in the second entity key-value pair is the same as the entity name included in the first entity key-value pair, it is determined that the entity object name included in the second entity key-value pair matches the table field included in the first entity key-value pair.

[0080] Specifically, the server compares the entity name included in the second entity key-value pair with the entity name included in the first entity key-value pair, and if the entity name included in the second entity key-value pair is the same as the entity name included in the first entity key-value pair, then it is determined that the entity object name included in the second entity key-value pair matches the table field included in the first entity key-value pair. If the entity name included in the second entity key-value pair is not the same as the entity name included in the first entity key-value pair, then the entity object name included in the second entity key-value pair does not match the table field included in the first entity key-value pair.

[0081] On the basis of the above embodiments, further, the processing method for converting natural language into structured query language provided by the embodiment of the present invention also includes:

[0082] If it is determined that two first entity key-value pairs in the first entity key-value pairs corresponding to the first structured query statement include the same entity name, role classification is added to the two first entity key-value pairs including the same entity name respectively.

[0083] Specifically, when the first entity key-value pair corresponding to the first structured query statement includes more than two second entity key-value pairs, the server will compare the entity names included in any two first entity key-value pairs. If two first entity key-value pairs include the same entity name, the server will add role classifications to the two first entity key-value pairs including the same entity name. Among them, the role classification of the first entity key-value pair can be determined by whether the table field includes the first classification keyword. The role classification and the first classification keyword are set according to actual needs, and the embodiment of the present invention does not limit it.

[0084] For example, the first entity key value corresponding to the first structured query statement obtained by the server includes two first entity key value pairs:<SENDBANK,BNK> and<RECEIVEBANK,BNK> .<SENDBANK,BNK> and<RECEIVEBANK,BNK> Including the same entity name BNK, the classification role needs to be set. The classification roles of BNK are the initiating role and the receiving role. The first classification keyword corresponding to the initiating role is send, and the first classification keyword corresponding to the receiving role is receive. The server matches send in the table field SENDBANK according to send, then it can be determined that the classification role corresponding to SENDBANK is the initiating role, and the first entity key-value pair to which SENDBANK belongs is changed to<SENDBANK,SENDBNK> , indicating that the corresponding classification role is the initiating role. Similarly, the first entity key-value pair of RECEIVEBANK can be changed to<RECEIVEBANK,RECEIVEBNK> , indicating that the corresponding classification role is the receiving role.

[0085] On the basis of the above embodiments, further, the processing method for converting natural language into structured query language provided by the embodiment of the present invention also includes:

[0086] The entity object name included in the second structured query statement is converted to obtain a third structured query statement.

[0087] Specifically, in order to facilitate business analysis and information exchange, some entity object names can be represented in the database by unique corresponding codes or identifiers, and some entity names can be represented in the database in a unified format. The server can perform name conversion on the entity object names included in the second structured query statement, and replace the corresponding entity object names in the second structured query statement with the converted data to obtain a third structured query statement, which is an executable SQL statement. After executing the SQL statement, the query result corresponding to the Chinese statement to be processed can be obtained.

[0088] For example, in a payment system, a mapping relationship table between Chinese names and identifiers is set up. In the mapping relationship table between Chinese names and identifiers, a Chinese name identical to the entity object name is queried. If a Chinese name identical to the entity object name is found, then the identifier corresponding to this Chinese name can be used as the identifier corresponding to the entity object name. For example, a unique corresponding line number is set for the bank name in the mapping relationship table between Chinese names and identifiers, and the line number is represented by a string of N digits. If the entity object name in the second structured query statement is the bank name, the bank name in the second structured query statement can be replaced with the line number corresponding to the bank name; a field value range query mapping relationship table is set up. The field value range query mapping relationship table includes the corresponding relationship between each processing status field and the corresponding code. For example, the code corresponding to the processing status field "completed" is "PR04". When the entity object name in the second structured query statement is "completed", "PR04" can be used to replace "completed" in the second structured query statement; the standard format of time is set as "yyyymmdd". For the entity object name "May 12, 2020" in the second structured query statement, it can be replaced with "2020-05-12".

[0089] For example, for the second structured query statement: SELECT*FROM PSASBEOT0101 WHERE RECVDATE‘May 12, 2020’AND SENDSETTBKCCPC=‘A City Processing Center’ORDER BY RECVTIME ASC. Through the mapping relationship table between Chinese names and identifiers, it can be queried that the identifier corresponding to the A City Processing Center is 3910. May 12, 2020 is converted to the standard time format 20200512. Replace the A City Processing Center included in the second structured query statement with 3910, and replace May 12, 2020 with 20200512 to obtain the third structured query statement: SELECT*FROMPSASBEOT0101WHERE RECVDATE‘20200512’AND SENDSETTBKCCPC=‘3910’ORDER BYRECVTIME ASC.

[0090] Figure 4 It is a schematic structural diagram of a processing device for converting natural language into a structured query language provided by the fourth embodiment of the present invention. As Figure 4 shown, the processing device for converting natural language into a structured query language provided by the embodiment of the present invention includes an acquisition unit 401, an extraction unit 402, a construction unit 403, a first acquisition unit 404, a second acquisition unit 405, and a third acquisition unit 406, where:

[0091] The first acquisition unit 401 is used to acquire a Chinese sentence to be processed, and perform structured query language conversion on the Chinese sentence to be processed to obtain a first structured query statement corresponding to the Chinese sentence to be processed; the extraction unit 402 is used to extract table fields from the first structured query statement to obtain table fields included in the first structured query statement; the construction unit 403 is used to construct a first entity key-value pair corresponding to the first structured query statement according to the entity and library table field name correspondence table and the table fields included in the first structured query statement, the first entity key-value pair including table fields and entity names; the first acquisition unit 404 is used to extract the table fields included in the first structured query statement according to the entity and library table field name correspondence table and the table fields included in the first structured query statement. The method comprises the following steps: a first structured query statement and a key-value pair extraction model are used to obtain a second entity key-value pair corresponding to the Chinese statement to be processed, wherein the second entity key-value pair includes an entity object name and an entity name; wherein the key-value pair extraction model is pre-trained; a second obtaining unit 405 is used to perform entity name mapping according to the first entity key-value pair corresponding to the first structured query statement and the second entity key-value pair corresponding to the Chinese statement to be processed, and obtain matching table fields and entity object names; a third obtaining unit 406 is used to obtain a second structured query statement corresponding to the Chinese statement to be processed according to the first structured query statement and the matching table fields and entity object names.

[0092] Specifically, the first acquisition unit 401 can acquire a Chinese statement to be processed, and then convert the Chinese statement to be processed into an SQL statement, so as to obtain a first structured query statement corresponding to the Chinese statement to be processed.

[0093] After obtaining the first structured query statement corresponding to the Chinese sentence to be processed, the extraction unit 402 may extract the table fields included in the first structured query statement from the first structured query statement to obtain the table fields included in the first structured query statement.

[0094] After obtaining the table fields included in the first structured query statement, the construction unit 403 matches the corresponding entity name in the entity and library table field name correspondence table according to each obtained table field, and constructs the first entity key-value pair corresponding to the first structured query statement through the matched table fields and entity names. The first entity key-value pair includes table fields and entity names, and only includes one table field and one entity pair, and the table fields and entity pairs in the first entity key-value pair match. The entity and library table field name correspondence table is preset, including each entity name and the matching rule corresponding to each entity name.

[0095] After obtaining the Chinese sentence to be processed, the first obtaining unit 404 inputs the Chinese sentence to be processed into the key-value pair extraction model, and can output the second entity key-value pair corresponding to the Chinese sentence to be processed. The second entity key-value pair corresponding to the Chinese sentence to be processed can be one second entity key-value pair, or two or more second entity key-value pairs. The second entity key-value pair includes an entity object name and an entity name, and the second entity key-value pair only includes one entity object name and one entity name, and the entity object name included in the second entity key-value pair matches the entity name. The entity object name originates from the Chinese sentence to be processed, and the entity name is the classification label corresponding to the entity object name obtained by the key-value pair extraction model. Among them, the key-value pair extraction model is obtained by pre-training.

[0096] For the first entity key-value pair corresponding to the first structured query statement, the second obtaining unit 405 can search for the same entity name in the second entity key-value pair corresponding to the Chinese statement to be processed according to the entity name included in the first entity key-value pair. If the same entity name is found, the table field corresponding to the same entity name in the first entity key-value pair and the entity object name corresponding to the same entity name in the second entity key-value pair are matched. The server can obtain the matched table field and entity object name.

[0097] The third obtaining unit 406 queries the same table field in the first structured query statement according to the matched table field and each table field in the entity object name. If the same table field is found, the entity object name that matches the same table field is filled with the value corresponding to the same table field in the first structured query statement. After completing the above value filling, the second structured query statement corresponding to the Chinese sentence to be processed can be obtained.

[0098] The processing device for converting natural language into structured query language provided by the embodiment of the present invention can obtain a Chinese statement to be processed, and convert the Chinese statement to be processed into structured query language, obtain a first structured query statement corresponding to the Chinese statement to be processed, extract table fields from the first structured query statement, obtain table fields included in the first structured query statement, construct a first entity key-value pair corresponding to the first structured query statement according to a corresponding relationship table between entity and library table field names and the table fields included in the first structured query statement, the first entity key-value pair including table fields and entity names, obtain a second entity key-value pair corresponding to the Chinese statement to be processed according to the Chinese statement to be processed and a key-value pair extraction model, perform entity name mapping according to the first entity key-value pair corresponding to the first structured query statement and the second entity key-value pair corresponding to the Chinese statement to be processed, obtain matching table fields and entity object names, obtain a second structured query statement corresponding to the Chinese statement to be processed according to the first structured query statement and the matching table fields and entity object names, implement value filling of SQL statements, and improve the accuracy of converting natural language into SQL statements.

[0099] Figure 5 FIG. 5 is a schematic diagram of a structure of a processing device for converting a natural language into a structured query language provided by a fifth embodiment of the present invention. Figure 5 As shown, based on the above embodiments, further, the first acquisition unit 401 includes an extraction subunit 4011, an acquisition subunit 4012 and a replacement subunit 4013, wherein:

[0100] The extraction subunit 4011 is used to extract entity names from the original Chinese sentence to obtain the entity names in the original Chinese sentence; the acquisition subunit 4012 is used to obtain the standardized name corresponding to each entity name based on each entity name in the original Chinese sentence and the standardized name library; the replacement subunit 4013 is used to replace the entity names of the original Chinese sentence according to the standardized name corresponding to each entity name to obtain the Chinese sentence to be processed.

[0101] Figure 6 is a schematic diagram of the structure of a processing device for converting a natural language into a structured query language provided by a sixth embodiment of the present invention, such as Figure 6 As shown, based on the above embodiments, further, the processing device for converting natural language into structured query language provided by the embodiment of the present invention further includes a second acquisition unit 407 and a training unit 408, wherein:

[0102] The second acquisition unit 407 is used to acquire named entity training data, and the named entity training data includes various entity object names and entity names corresponding to each type of entity object name; the training unit 408 is used to train and obtain the key-value pair extraction model based on the various entity object names, the entity names corresponding to each type of entity object name, and the key-value pair initial model.

[0103] On the basis of the above embodiments, further, the second obtaining unit 405 is specifically used for:

[0104] After determining that the entity name included in the second entity key-value pair is the same as the entity name included in the first entity key-value pair, it is determined that the entity object name included in the second entity key-value pair matches the table field included in the first entity key-value pair.

[0105] Figure 7 FIG. 7 is a schematic diagram of a structure of a processing device for converting a natural language into a structured query language provided by a seventh embodiment of the present invention. Figure 7 As shown, based on the above embodiments, further, the processing device for converting natural language into structured query language provided by the embodiment of the present invention further includes an adding unit 409, wherein:

[0106] The adding unit 409 is used to add role classifications to the two first entity key-value pairs including the same entity name after determining that two first entity key-value pairs in the first entity key-value pairs corresponding to the first structured query statement include the same entity name.

[0107] Figure 8 FIG. 8 is a schematic diagram of a processing device for converting a natural language into a structured query language according to an eighth embodiment of the present invention. Figure 8 As shown, the processing device for converting natural language into structured query language provided by the embodiment of the present invention also includes:

[0108] The name conversion unit 410 is used to perform name conversion on the entity object name included in the second structured query statement to obtain a third structured query statement.

[0109] The embodiments of the apparatus provided in the embodiments of the present invention can be specifically used to execute the processing flow of the above-mentioned method embodiments, and its functions are not described in detail here, and reference can be made to the detailed description of the above-mentioned method embodiments.

[0110] Fig. 9 is a schematic diagram of the physical structure of an electronic device provided by a ninth embodiment of the present invention, such as Fig. 9As shown, the electronic device may include: a processor (processor) 901, a communication interface (Communications Interface) 902, a memory (memory) 903 and a communication bus 904, wherein the processor 901, the communication interface 902, and the memory 903 communicate with each other through the communication bus 904. The processor 901 can call the logic instructions in the memory 903 to execute the following method: obtain a Chinese statement to be processed, and perform structured query language conversion on the Chinese statement to be processed to obtain a first structured query statement corresponding to the Chinese statement to be processed; perform table field extraction on the first structured query statement to obtain the table field included in the first structured query statement; construct a first entity key-value pair corresponding to the first structured query statement according to the entity and library table field name correspondence table and the table field included in the first structured query statement, the first entity key-value pair including the table field and the entity name; obtain a second entity key-value pair corresponding to the Chinese statement to be processed according to the Chinese statement to be processed and the key-value pair extraction model, the second entity key-value pair including the entity object name and the entity name; wherein the key-value pair extraction model is obtained by pre-training; perform entity name mapping according to the first entity key-value pair corresponding to the first structured query statement and the second entity key-value pair corresponding to the Chinese statement to be processed to obtain matching table fields and entity object names; obtain a second structured query statement corresponding to the Chinese statement to be processed according to the first structured query statement and the matching table fields and entity object names.

[0111] In addition, the logic instructions in the above-mentioned memory 903 can be implemented in the form of software functional units and can be stored in a computer-readable storage medium when sold or used as an independent product. Based on such an understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art or the part of the technical solution, can be embodied in the form of a software product, which is stored in a storage medium and includes several instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present invention. The aforementioned storage medium includes: various media that can store program codes, such as a USB flash drive, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk.

[0112] The present embodiment discloses a computer program product, which includes a computer program stored on a non-transitory computer-readable storage medium, and the computer program includes program instructions. When the program instructions are executed by a computer, the computer can execute the methods provided by the above-mentioned method embodiments, for example, including: obtaining a Chinese sentence to be processed, and converting the Chinese sentence to be processed into a structured query language to obtain a first structured query statement corresponding to the Chinese sentence to be processed; extracting table fields from the first structured query statement to obtain table fields included in the first structured query statement; constructing the first structured query statement according to a corresponding relationship table between entity and library table field names and the table fields included in the first structured query statement. A first entity key-value pair corresponding to a structured query statement, the first entity key-value pair includes a table field and an entity name; according to the Chinese statement to be processed and a key-value pair extraction model, a second entity key-value pair corresponding to the Chinese statement to be processed is obtained, the second entity key-value pair includes an entity object name and an entity name; wherein the key-value pair extraction model is pre-trained; according to the first entity key-value pair corresponding to the first structured query statement and the second entity key-value pair corresponding to the Chinese statement to be processed, entity name mapping is performed to obtain matching table fields and entity object names; according to the first structured query statement and the matching table fields and entity object names, a second structured query statement corresponding to the Chinese statement to be processed is obtained.

[0113] The present embodiment provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, wherein the computer program enables the computer to execute the methods provided by the above-mentioned method embodiments, for example, including: obtaining a Chinese statement to be processed, and performing structured query language conversion on the Chinese statement to be processed to obtain a first structured query statement corresponding to the Chinese statement to be processed; performing table field extraction on the first structured query statement to obtain table fields included in the first structured query statement; constructing a first entity key value corresponding to the first structured query statement according to a corresponding relationship table between entity and library table field names and the table fields included in the first structured query statement Yes, the first entity key-value pair includes table fields and entity names; according to the Chinese sentence to be processed and the key-value pair extraction model, the second entity key-value pair corresponding to the Chinese sentence to be processed is obtained, and the second entity key-value pair includes an entity object name and an entity name; wherein the key-value pair extraction model is pre-trained; entity name mapping is performed according to the first entity key-value pair corresponding to the first structured query statement and the second entity key-value pair corresponding to the Chinese sentence to be processed, to obtain matching table fields and entity object names; according to the first structured query statement and the matching table fields and entity object names, the second structured query statement corresponding to the Chinese sentence to be processed is obtained.

[0114] Those skilled in the art will appreciate 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. Moreover, 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.

[0115] 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 processor, 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.

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

[0117] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.

[0118] In the description of this specification, the description with reference to the terms "one embodiment", "a specific embodiment", "some embodiments", "for example", "example", "specific example", or "some examples" means that the specific features, structures, materials or characteristics described in conjunction with the embodiment or example are included in at least one embodiment or example of the present invention. In this specification, the schematic representation of the above terms does not necessarily refer to the same embodiment or example. Moreover, the specific features, structures, materials or characteristics described may be combined in any one or more embodiments or examples in a suitable manner.

[0119] The specific embodiments described above further illustrate the objectives, technical solutions and beneficial effects of the present invention in detail. It should be understood that the above description is only a specific embodiment of the present invention and is not intended to limit the scope of protection of the present invention. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of the present invention should be included in the scope of protection of the present invention.

Claims

1. A method for converting natural language into structured query language, characterized in that: include: Acquire a Chinese sentence to be processed, and convert the Chinese sentence to be processed into a structured query language to obtain a first structured query sentence corresponding to the Chinese sentence to be processed; Extracting table fields from the first structured query statement to obtain table fields included in the first structured query statement; According to the entity and library table field name correspondence table and the table fields included in the first structured query statement, construct a first entity key-value pair corresponding to the first structured query statement, wherein the first entity key-value pair includes a table field and an entity name; According to the Chinese sentence to be processed and the key-value pair extraction model, a second entity key-value pair corresponding to the Chinese sentence to be processed is obtained, wherein the second entity key-value pair includes an entity object name and an entity name; wherein the key-value pair extraction model is obtained by pre-training; Performing entity name mapping according to the first entity key-value pair corresponding to the first structured query statement and the second entity key-value pair corresponding to the Chinese statement to be processed, to obtain matching table fields and entity object names; According to the first structured query statement and the matching table fields and entity object names, a second structured query statement corresponding to the Chinese statement to be processed is obtained.

2. The method according to claim 1, characterized in that The obtaining of the Chinese sentences to be processed comprises: Extracting entity names from the original Chinese sentence to obtain entity names in the original Chinese sentence; According to each entity name in the original Chinese sentence and the standardized name library, obtaining a standardized name corresponding to each entity name; The entity names of the original Chinese sentences are replaced according to the standardized names corresponding to each entity name to obtain the Chinese sentences to be processed.

3. The method according to claim 1, characterized in that The steps of pre-training the key-value pair extraction model include: Acquire named entity training data, wherein the named entity training data includes names of various entity objects and entity names corresponding to each type of entity object name; The key-value pair extraction model is obtained by training according to the names of various entity objects, the entity names corresponding to each type of entity object name, and the key-value pair initial model.

4. The method according to claim 1, characterized in that: The performing entity name mapping according to the first entity key-value pair corresponding to the first structured query statement and the second entity key-value pair corresponding to the Chinese statement to be processed to obtain matching table fields and entity object names includes: If it is determined that the entity name included in the second entity key-value pair is the same as the entity name included in the first entity key-value pair, it is determined that the entity object name included in the second entity key-value pair matches the table field included in the first entity key-value pair.

5. The method according to claim 1, characterized in that Also includes: If it is determined that two first entity key-value pairs in the first entity key-value pairs corresponding to the first structured query statement include the same entity name, role classification is added to the two first entity key-value pairs including the same entity name respectively.

6. The method according to any one of claims 1 to 5, characterized in that: Also includes: The entity object name included in the second structured query statement is converted to obtain a third structured query statement.

7. A processing device for converting natural language into structured query language, characterized in that: include: An acquisition unit, configured to acquire a Chinese sentence to be processed, and perform structured query language conversion on the Chinese sentence to be processed to obtain a first structured query sentence corresponding to the Chinese sentence to be processed; An extraction unit, configured to extract table fields from the first structured query statement to obtain table fields included in the first structured query statement; A construction unit, configured to construct a first entity key-value pair corresponding to the first structured query statement according to a table of correspondence between entity and library table field names and table fields included in the first structured query statement, wherein the first entity key-value pair includes a table field and an entity name; A first obtaining unit is used to obtain a second entity key-value pair corresponding to the Chinese sentence to be processed according to the Chinese sentence to be processed and the key-value pair extraction model, wherein the second entity key-value pair includes an entity object name and an entity name; wherein the key-value pair extraction model is obtained by pre-training; A second obtaining unit is used to perform entity name mapping according to the first entity key-value pair corresponding to the first structured query statement and the second entity key-value pair corresponding to the Chinese statement to be processed, so as to obtain matching table fields and entity object names; The third obtaining unit is used to obtain a second structured query statement corresponding to the Chinese statement to be processed according to the first structured query statement and the matching table fields and entity object names.

8. The device according to claim 7, characterized in that The acquisition unit comprises: An extraction subunit, used to extract entity names from the original Chinese sentence to obtain entity names in the original Chinese sentence; An obtaining subunit, used for obtaining a standardized name corresponding to each entity name according to each entity name in the original Chinese sentence and a standardized name library; The replacement subunit is used to replace the entity name of the original Chinese sentence according to the standardized name corresponding to each entity name to obtain the Chinese sentence to be processed.

9. The device according to claim 7, characterized in that Also includes: A second acquisition unit is used to acquire named entity training data, wherein the named entity training data includes various entity object names and entity names corresponding to each entity object name; The training unit is used to train and obtain the key-value pair extraction model according to various entity object names, entity names corresponding to each type of entity object name, and the key-value pair initial model.

10. The device according to claim 7, characterized in that The second obtaining unit is specifically used for: After determining that the entity name included in the second entity key-value pair is the same as the entity name included in the first entity key-value pair, it is determined that the entity object name included in the second entity key-value pair matches the table field included in the first entity key-value pair.

11. The device according to claim 7, characterized in that Also includes: The adding unit is used to add role classification to the two first entity key-value pairs including the same entity name after determining that two first entity key-value pairs in the first entity key-value pairs corresponding to the first structured query statement include the same entity name.

12. The device according to any one of claims 7 to 11, characterized in that Also includes: The name conversion unit is used to perform name conversion on the entity object name included in the second structured query statement to obtain a third structured query statement.

13. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the computer program, the steps of the method according to any one of claims 1 to 6 are implemented.

14. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 6 are implemented.

Citation Information

Patent Citations

  • Chinese language processing method and device based on neural network model

    CN114185931A